c# - Blocking functions in XNA -


i'm coding rpg engine in xna. engine executes series of scripting commands has block until next scripting command. how can this?

for example:

// interact npc named in string 'name' string interactfunc = string.format("{0}_interact", name); system.reflection.methodinfo info = factory.script.gettype().getmethod(interactfunc); if (info != null) info.invoke(factory.script, new object[]{this});  //this may run following script command npc 'bob'      public void bob_interact(npc bob)     {         bob.say("well worked.");         bob.say("didnt it?");     }  //the command looks      public void say(string text)     {         talkgui gui = new talkgui(this, text);           factory.game.guis.add(gui);         factory.focusedgui = gui;      } 

now need script wait until first talkgui has been dismissed before running next script command.

what's best way this? maybe run script functions in own thread or something?

you don't want use threads kind of thing. they're far heavy weight.

what want co-routines. can emulate these in c# using yield , iterators.

there examples here , here. , perhaps answer here worth reading too.

c# 5.0 introducing nicer way of doing asynchronous programming this. here's video , here ctp.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -