Jump to content
  • Advertisement
Sign in to follow this  
Servant of the Lord

Would this be misuse of aslScriptContext::Suspend()?

This topic is 1142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

//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.

//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.


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.

Edited by Servant of the Lord

Share this post

Link to post
Share on other sites

A) This is a perfectly valid use case. Using this script engine like this can be thought of a form of coroutine. Just remember that it is currently not possible to serialize a context's state, so if you plan on allowing the user to save the game in the middle of a playthrough with coroutines still running you'll face trouble.


B) You'll probably be fine with 50 something contexts. Expect each context to take up a few KB of memory. If you're targeting platforms with limited amount of memory you can tweak the amount of memory that is allocated for the callstack in the contexts by setting the engine property asEP_MAX_STACK_SIZE.


C) Take a look at the code for the ExecuteString helper function. It is a good place to start, but you'll likely want to make some adaptions to suite your own specific needs. For example, resuming the context after it has been suspended. By default the function doesn't support resuming, since it discards the script code before returning.


D) Yes, PushState/PopState can be used to call the different script. Though, obviously you cannot resume the original script before the called script finishes if you do.




Share this post

Link to post
Share on other sites

Thanks a bunch. The library and documentation seems really straightforward and easy to understand.


I appreciate being able to pick up and use a language like this without having to code (a exceptionally poorer) one myself.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!