🎉 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!

Q about how AngelScript works

Started by
1 comment, last by WitchLord 19 years ago
To start angel script you create an engine, then load scripts into modules (or a single module) Then when you wish to execute a script function you create a context to execute the function in. Here is my question. Does this context have it's own set of global variables and functions, or is this context just used to contain the calling of the function. Globals are still common to all. From what i've read it seems the latter. What i'm after is a way to have per entity data contained in the script. I'm new to scripting so excuse my ignorance. --Zims
Advertisement
If you have exactly one entity per script, you can just use globals in the script. If multiple entities use the same script, you'll need to devise some way to store the data in the entity.
The global variables are common to all contexts running the same scripts.

I'm currently looking in to some way of allowing the script writer to declare global variables as thread local, i.e. private for each context.

In the upcoming version of AngelScript you will also be able to let the scripts store structures within the application, in this way you can have the script allocate a structure, and store it for later use.

For now, you can implement application functions for storing data specific for a context, e.g:

void StoreFloat(string &name, float val){  asIScriptContext *ctx = asGetActiveContext();  // map the ctx pointer to an application object that can store attributes  CAttributes *attr = GetAttributesForContext(ctx);  attr->StoreFloat(name, val);}


I also intend to change the library to allow the application to store a pointer with each context. This can be used for faster mapping between context pointer and the extra data, used by the application.

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

This topic is closed to new replies.

Advertisement