First of all, thank you for your time. 
I am not that experienced when it comes to all the terms used in this area of software, so please be patient with me.   <br><div><br></div><div>To give you a more clear idea of what I am doing I have posted a video of the current progress here <a href="http://www.youtube.com/watch?v=HER6WSIwSBQ&amp;feature=youtu.be">http://www.youtube.com/watch?v=HER6WSIwSBQ&amp;feature=youtu.be</a> . This is a simple gameengine, with a physics based robot. It has simple senes (A vector to the nearest bot and the length of a raycast in front of the robot) and three actions (left_wheel_speed, right_wheel_speed and fire). IronPython is embeeded inside the Unity3D game engine which runs on .NET 2.0. I am using the dll version of ironpython in the project. (I could not figure out how to integrate the source into my game project.) </div>

<div><br></div><div>The whole prototype was made at  48 hour game jam called &quot;No More Sweden&quot; in Malmö the past weekend. </div><div> </div><div>I did not know that the python code is compiled in IronPython before it is executed, and therefore will catch syntax errors before execution. That will be very usefull. :)</div>

<div><br></div><div>I will need to look into the settrace advice, but my gut feeling is that it is not the direction I want to be going in. It might be later during work on the GUI / programming interface. </div><div><br>

</div><div>I agree that I should have a simple singlethreaded, turn based solution, as that can be made deterministic and its far easier to implement. That is definitely the way I want to go. The threading was only used in the prototype because I could not execute my script gradually. I saw the execute command as the only way to have Ironpython run my script, and saw a thread as the only way out. (at 3 am in the morning) </div>

<div><br></div><div>The reason I keep mentioning gradually execution requires some backstory: The reference project I have been inspired by is an old game called GunTactyx (<a href="http://www.youtube.com/watch?v=vT8PYETav7A&amp;feature=relmfu">http://www.youtube.com/watch?v=vT8PYETav7A&amp;feature=relmfu</a>), where you program robots to hunt down other robots. It uses an old version of the PAWN Language/abstract machine (<a href="http://www.compuphase.com/pawn/pawn.htm">http://www.compuphase.com/pawn/pawn.htm</a>). As far as I understand each robot there has an isolated abstract machine with limited memory and it is ticked gradually, like you control the clock on its CPU. If a robot crashes, has an infinite loop or a memory leak it does not affect the cpu in the other robots. The reason I am not using PAWN is that it is C++ based and my target platform runs .NET 2.0. Besides that I prefer Python over the PAWN language.</div>

<div><br></div><div>Kevin: When you say statemachine, I imagined Ironpython had something of that sort inside its belly? That might be where I am wrong. Is a statemachine and an abstract machine the same thing in this context?</div>

<div><br></div><div>With regard to the dostuff() functions, I dont mind the robots firing many instructions at a time. I just need to be able to let the robots run the same number of &quot;ticks&quot; between each game cycle. I imagine assigning a tick cost to the dostuff() functions, as they probably will do stuff inside the game world. </div>

<div><br></div><div>I have been looking at other solutions to allow me to make a programming game. During the 48 hours I briefly used the AluminumLua project which I was able to tick, but it lacked debelopment on the language side. (for loops was not implemented) I would prefer to stick to Pythoon as I love the language and I feel it contains the elements needed to write an interristing AI. </div>

<div><br></div><div>I need to read up on the IronPython  system and have therefore just ordered &quot;Ironpython in action&quot; book, I hope it will give me a better understanding. Other recommendations are welcome.</div>

<div><br></div><div>Kind regards and thank you again for your feedback.</div><div><br></div><div>Tax</div><div><br></div><div>  </div><div><br><div class="gmail_quote">2012/7/23 Kevin Hazzard <span dir="ltr">&lt;<a href="mailto:wkhazzard@gmail.com" target="_blank">wkhazzard@gmail.com</a>&gt;</span><br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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>

<span class="HOEnZb"><font color="#888888">
<div> </div><div>Kevin<br><br></div></font></span><div class="HOEnZb"><div class="h5"><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><div><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" value="+17706174016" target="_blank">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"><a href="tel:%28804%29%20928-3444" value="+18049283444" target="_blank">(804) 928-3444</a></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>
</div></div></blockquote></div><br></div>