I'm currently thinking through how I want scripts to interact with my game logic.
Most of my logic is going to be implemented strait in C++, but some of it will be exposed to scripts.
Some of the exposed logic gets processed over time, with scripts firing off an action that may take several seconds before it completes.
Alot of this logic is higher-level, so I was thinking my scripts might look something like this:
//Sets this entity's movement goal, and the entity moves towards that location.
//This function just returns an ID for a 'trigger' that gets triggered when the entity reaches that location.
Trigger reachedNode = thisEntity.MoveTo("node placed on map");
//Other events can be operating simultaneously.
Camera.ShakeScreen(amount, duration);
//Some functions just operate immediately.
thisEntity.SetSomeValue(value);
//Here, the script gets suspended (likely using aslScriptContext::Suspend()).
//The entity continues doing whatever logic C++-side that was already triggered (i.e. shaking the screen for the desired length of time, and walking toward the node), until the entity reaches the node, at which time C++ will resume the script's execution. Other scripts for other entities would've still been running.
WaitForTrigger(reachedNode);
//Now that the entity reached the node, we show a dialog box.
Trigger doneReadingDialog = GUI.ShowDialog("human-readable name for dialog details (including facial portraits and rich text and etc...)");
//Wait for the player to read the dialog, before resuming.
WaitForTrigger(doneReadingDialog);
//...etc...
I'd probably have up to 50-ish of these scripts in execution and suspended, though usually it wouldn't be that high, and
My questions are:
A) Does this seem like reasonable use of aslScriptContext::Suspend(), or would this be abuse of that feature?
B) Am I using too many contexts?
C) What function should I use to execute small blocks of "throwaway" scripts (i.e. scripts I want to run once and then discard)? Would the ExecuteString() add-on be able to run multi-line chunks of code like the above example? Would it be able to suspend and resume?
D) If one script calls another script, do I have to use a new context, or can I use aslScriptContext::PushState()/PopState() to execute that new script before resuming the original script?
Thank you for your help - I'm new to AngelCode.