🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

pausing scripts?

Started by
3 comments, last by kaysik 19 years, 10 months ago
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
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...
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.
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.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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!

This topic is closed to new replies.

Advertisement