<div>What you&#39;re describing is a state machine. There are many ways to build such a thing and honestly, I&#39;ve never thought of single-stepping through code as a way to do that. It&#39;s actually quite an intriguing idea, if not inefficient. But efficiency isn&#39;t always measured with elegance (and vice versa). Keith&#39;s settrace idea is good, too. You should check that out.</div>
<div> </div><div>What it really comes down to is this: do you want the controller to also define the code or merely to drive it? For the example you posted, do you want the while loops implemented in Python to execute your dostuff() and dootherstuff() methods? Or do you want the controller that authorizes a &quot;step&quot; to do that? In that context, you could write the controller in Python, too, but the design of your code would look very different than what you proposed.</div>
<div> </div><div>Kevin<br><br></div><div class="gmail_quote">On Mon, Jul 23, 2012 at 1:48 PM, Jesper Taxbøl <span dir="ltr">&lt;<a href="mailto:jesper@taxboel.dk" target="_blank">jesper@taxboel.dk</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">The reason I want to do it gradually is that I cant be sure that the script ever terminates or has syntax errors. Would that not be a problem in a turn based setup? <br>
<div class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote">2012/7/23 Keith Rome <span dir="ltr">&lt;<a href="mailto:rome@wintellect.com" target="_blank">rome@wintellect.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">





<div lang="EN-US" vlink="purple" link="blue">
<div>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:11pt">You may want to look into leveraging the sys.settrace() feature of Python for controlling line-by-line execution. This API allows you to install a profiling
 function that gets invoked for every frame of script code that is executed. In your profiling function, you could compute the amount of memory being used by variables within the ScriptScope, and halt execution if you need to. Just be careful about what you
 do in your profiling function, as it will be called extremely often by the runtime.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><a href="http://docs.python.org/library/sys.html#sys.settrace" target="_blank">http://docs.python.org/library/sys.html#sys.settrace</a><u></u><u></u></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:11pt">The reason you are seeing variant results is probably due to how you have implemented multithreading. The IronPython runtime is mostly thread-safe (as long
 as you don’t use libraries that make use of mutable objects, and as long as you import all libraries used at least once prior to forking threads). But your code must also be thread-safe as well. From your descriptions of your game engine, it sounds like your
 game engine is not designed to be thread-safe so I would strongly recommend avoiding multithreading as a means of providing resource sharing. It is very difficult to write 100% thread-safe code, and nothing will stop people from writing unsafe scripts in your
 game.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:11pt">Instead, I would suggest implementing your game engine as a turn-based system. For each turn, the script for each character is executed completely. This will
 allow you to cycle through all characters one turn at a time, equally, and will also eliminate the problem of having variant outcomes since the program will become deterministic.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:14pt">Keith Rome<u></u><u></u></span></b></p>
<p class="MsoNormal"><b><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:10pt">Senior Consultant and Architect<u></u><u></u></span></b></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:10pt">MCPD-EAD, MCSD, MCDBA, MCTS-WPF, MCTS-TFS, MCTS-WSS<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:10pt">Wintellect | <a href="tel:770.617.4016" target="_blank" value="+17706174016">770.617.4016</a> |
<a href="mailto:rome@wintellect.com" target="_blank">krome@wintellect.com</a><u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:10pt"><a href="http://www.wintellect.com/" target="_blank">www.wintellect.com</a><u></u><u></u></span></p>



<p class="MsoNormal"><span style="color:rgb(31,73,125);font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;font-size:11pt"><u></u> <u></u></span></p>
<p class="MsoNormal"><b><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;font-size:10pt">From:</span></b><span style="font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;;font-size:10pt"> ironpython-users-bounces+rome=<a href="mailto:wintellect.com@python.org" target="_blank">wintellect.com@python.org</a> [mailto:<a href="mailto:ironpython-users-bounces%2Brome" target="_blank">ironpython-users-bounces+rome</a>=<a href="mailto:wintellect.com@python.org" target="_blank">wintellect.com@python.org</a>]
<b>On Behalf Of </b>Jesper Taxbøl<br>
<b>Sent:</b> Monday, July 23, 2012 11:05 AM<br>
<b>To:</b> Kevin Hazzard<br>
<b>Cc:</b> <a href="mailto:ironpython-users@python.org" target="_blank">ironpython-users@python.org</a><br>
<b>Subject:</b> Re: [Ironpython-users] Gradually executing a python script<u></u><u></u></span></p><div><div>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Would that allow me to step gradually through a loop?<u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">like:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">x = 0<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">while x &lt; 10:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">   dostuff()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">   x=x+1<u></u><u></u></p>
</div>
<div>
<div>
<p class="MsoNormal">while x &gt; 0:<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">   dootherstuff()<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal">   x=x-1<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12pt"><u></u> <u></u></p>
<div>
<p class="MsoNormal">2012/7/23 Kevin Hazzard &lt;<a href="mailto:wkhazzard@gmail.com" target="_blank">wkhazzard@gmail.com</a>&gt;<u></u><u></u></p>
<div>
<p class="MsoNormal">Why don&#39;t you use a scripting host and inject commands into a ScriptEngine reusing a ScriptScope as you need to execute them?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"> <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12pt">Kevin<u></u><u></u></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal">On Mon, Jul 23, 2012 at 5:31 AM, Jesper Taxbøl &lt;<a href="mailto:jesper@taxboel.dk" target="_blank">jesper@taxboel.dk</a>&gt; wrote:<u></u><u></u></p>
</div>
</div>
<blockquote style="border-width:medium medium medium 1pt;border-style:none none none solid;border-color:currentColor currentColor currentColor rgb(204,204,204);padding:0in 0in 0in 6pt;margin-right:0in;margin-left:4.8pt">

<div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">Hi,</span><u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">I am not that familiar with Ironpython yet, but I have a question that I hope you can help me answer.</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">I am working on a programming-game where I will allow users to do some simple python scripting against a simple API that I will control a game character. Instructions like move and shoot etc, alongside some simple
 sense functions that return info on the game world. </span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">My current prototype creates an ironpython engine for each game character and executes the script in a thread by itself, which sort of works. But I have the problem that the outcome of executing the game gives
 different results every time. Therefore I would like to ask the question:</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">Is it possible to execute a script inside the Ironpython engine gradually?</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">I imagine that I could update a list of engines with a tick(int cycles) and get a fair sharing of resources between engines and ensure the same result every time.</span><u></u><u></u></p>



</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">Kind regards </span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">Tax</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">P.S:</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">As this is a programming game I would also like to be able to limit the available memory each script is using. Is there a way to limit this, so a script like this would be killed.</span><u></u><u></u></p>



</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">x = 0</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">v = {}</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">while True:</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">   v[x]=x</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:rgb(34,34,34)">   x= x + 1</span><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
<p class="MsoNormal" style="margin-bottom:12pt">_______________________________________________<br>
Ironpython-users mailing list<br>
<a href="mailto:Ironpython-users@python.org" target="_blank">Ironpython-users@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/ironpython-users" target="_blank">http://mail.python.org/mailman/listinfo/ironpython-users</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal"><span style="color:rgb(136,136,136)"><br>
<br clear="all">
<br>
-- <br>
</span><b><span style="color:rgb(136,136,136);font-family:&quot;Garamond&quot;,&quot;serif&quot;">W. Kevin Hazzard</span></b><span style="color:rgb(136,136,136)"><u></u><u></u></span></p>
<div>
<p class="MsoNormal"><span style="color:rgb(136,136,136);font-family:&quot;Garamond&quot;,&quot;serif&quot;;font-size:8pt">Consultant, Author, Teacher, Microsoft MVP</span><span style="color:rgb(136,136,136)"><u></u><u></u></span></p>

</div>
<div>
<p class="MsoNormal"><span style="color:rgb(136,136,136);font-family:&quot;Garamond&quot;,&quot;serif&quot;;font-size:8pt"><a href="tel:%28804%29%20928-3444" target="_blank">(804) 928-3444</a></span><span style="color:rgb(136,136,136)"><u></u><u></u></span></p>



</div>
<div>
<p class="MsoNormal"><span style="color:rgb(136,136,136);font-family:&quot;Garamond&quot;,&quot;serif&quot;;font-size:8pt"><a href="http://manning.com/hazzard" target="_blank">book</a> |
<a href="https://mvp.support.microsoft.com/profile/Kevin.Hazzard" target="_blank">
mvp</a> | <a href="http://twitter.com/#%21/KevinHazzard" target="_blank">twitter</a> |
<a href="http://www.facebook.com/wkhazzard" target="_blank">facebook</a> | <a href="http://www.linkedin.com/in/kevinhazzard" target="_blank">
linkedin</a> | <a href="http://captechconsulting.com" target="_blank">captech</a></span><span style="color:rgb(136,136,136)"><u></u><u></u></span></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div>
</div>

</blockquote></div><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><span style="font-size:12pt"><strong><font face="Garamond">W. Kevin Hazzard</font></strong></span><div><font face="Garamond"><span><span style="font-size:8pt">Consultant, Author, Teacher, Microsoft MVP</span></span></font></div>
<div><font><span style="font-size:8pt"><span></span></span></font><font face="Garamond"><span style="font-size:8pt">(804) 928-3444</span></font></div><div><font face="Garamond"><span style="font-size:8pt"><a href="http://manning.com/hazzard" target="_blank">book</a> | <a href="https://mvp.support.microsoft.com/profile/Kevin.Hazzard" target="_blank">mvp</a> | <a href="http://twitter.com/#!/KevinHazzard" target="_blank">twitter</a> | <a href="http://www.facebook.com/wkhazzard" target="_blank">facebook</a> | <a href="http://www.linkedin.com/in/kevinhazzard" target="_blank">linkedin</a> | <a href="http://captechconsulting.com" target="_blank">captech</a></span></font></div>
<br>