Jump to content
  • Advertisement
Sign in to follow this  
cbken

calling multiple functions

This topic is 3985 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

Hi, I'm new to AngelScript and will be using it in a game engine. Is it possible to call a script function, have the function return with a sleep and then call another function in the same script and context, and this second function will also return before finished and then again continue execution of the first function? In other words, there will be two or more functions in the same script and context in some state of execution. Is this possible or will calling a new function mess up the state of the first function that returned in the middle of execution? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Yes this is possible, and quite simple to do. The 'concurrent' sample in the sdk shows how this can be done.

Share this post


Link to post
Share on other sites
I looked at the concurrent sample but there two separate contexts are created, one for each script and function. Does it work to use only one context and then have several functions executing in that context?
I guess I'm not entirely clear about what the context does and how functions relate to it.

What I have in mind is to load a script file, create a context for the script and then get the function IDs for functions in this script so I can later quickly call the functions. The script will also have it's own module name.

The main point is that one function may not have finished executing, just sleeping, when another is called. I can of course try it out and see what happens but it would be good to know if it can work at all before I spend time on it.

Share this post


Link to post
Share on other sites
The asIScriptContext is the script thread with the stack memory, and so on.

You cannot execute two separate threads in the same script context. If you try the currently suspended execution will be aborted and cannot be resumed later on, as when you prepare the second function it will over write the previous state with the new one.

Two contexts can execute functions from the same script module though, in which case they'll share byte code and global variables. From what you describe this is what you want to do.


Share this post


Link to post
Share on other sites
Ah ok, thanks for clarifying this. I had a feeling that was the case so I will create separate contexts.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!