• Advertisement
Sign in to follow this  

pausing scripts?

This topic is 4907 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've just finished planning my next game and I'm looking round for a scripting engine to use. Right now i'm tossing up between lua, python and angelScript. One thing I need is to be able to pause a script from inside itself. I've had a quick looks at the docs, and the suspend() function from the asIScriptContext class looks exactly like what i want - but I'm just wondering if you can call that from inside the script? Lets say I have a scrip, and I let it call my function checkContinue(), am i allowed suspend the script inside the checkContinue() function when the script i'm suspending is calling the function? hope that makes sense :P

Share this post


Link to post
Share on other sites
Advertisement
Hi,

I'm thinking of the same problem. The only way I can think of so far is to create a script function called 'Pause()' and have it call the function 'Suspend()'. The only problem is that we don't know which context the function is being called...

Share this post


Link to post
Share on other sites
The answer to this depends on how you use AS in your project. For my last project, I maintained a list of currently active script contexts. During each pass through the game loop, I would call ExecuteStep on each context. For pausing my scripts, I made a simple Sleep() command:
void Sleep(float fSeconds)
{
float wakeTime = Ghoul.fTickTime + fSeconds;

while (Ghoul.fTickTime < wakeTime);
}
// Ghoul.fTickTime is the current engine time




This solution has the obvious drawback that sleeping scripts still use processor time (although they are still correctly timeshared with the other contexts).

If you want to get a little fancier than that, then yeah, you will need the scripts context. I cannot say how to do that off the top of my head though...

Anyways... Just a thought.

Share this post


Link to post
Share on other sites
Yes, you may call Suspend() from a system function called by the script. In fact, that is one of the reasons I made it.

You'll use the global function GetActiveContext() to get the script context that is currently running so that you can suspend it. Example:


void Suspend()
{
asIScriptContext *ctx = GetActiveContext();
if( ctx )
ctx->Suspend();
}


GetActiveContext() is guaranteed to always return the context that is actually running, or null if no context is currently active. There will never be more than one context active at one time.

AngelScript has not yet been made to work with multiple threads so I can't guarantee functionality if you have scripts running in more than one thread.

Share this post


Link to post
Share on other sites
Quote:
Original post by WitchLord
Yes, you may call Suspend() from a system function called by the script. In fact, that is one of the reasons I made it.

You'll use the global function GetActiveContext() to get the script context that is currently running so that you can suspend it.


SWEEEEET :D

thats exactly what i'm after! I'll definatly be trying out AS in my next game engine then. It'll take me a little while to get to implimenting the scripting section (as I gota write the rest first) but i'll let you know how it goes when i get round to it!

ta for the quick replies all!

Share this post


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

  • Advertisement