Advertisement

calling multiple functions

Started by July 27, 2007 08:23 AM
3 comments, last by cbken 17 years, 4 months ago
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
Yes this is possible, and quite simple to do. The 'concurrent' sample in the sdk shows how this can be done.

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

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

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.


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

Ah ok, thanks for clarifying this. I had a feeling that was the case so I will create separate contexts.

This topic is closed to new replies.

Advertisement