Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

pausing scripts?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 kaysik   Members   -  Reputation: 382

Like
0Likes
Like

Posted 12 August 2004 - 04:00 PM

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

Sponsor:

#2 Igmon   Members   -  Reputation: 122

Like
0Likes
Like

Posted 12 August 2004 - 07:42 PM

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

#3 Desdemona   Members   -  Reputation: 158

Like
0Likes
Like

Posted 12 August 2004 - 10:48 PM

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.

#4 Andreas Jonsson   Moderators   -  Reputation: 3290

Like
0Likes
Like

Posted 13 August 2004 - 01:57 AM

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

#5 kaysik   Members   -  Reputation: 382

Like
0Likes
Like

Posted 13 August 2004 - 04:24 AM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS