Array of timers
Andreas, thank you so much for providing AngelScript to the public. I have just started experimenting with it and I'm trying to tie my arms around how to integrate it properly with arrays of classes.
I am trying to figure out the best way to allow the script the ability to access an array of timers that would be pre-created in the application.
for example
Script code
{
timers[1].preset = 400;
timers[1].start;
if (timers[1].value >100) timers[2].start;
if (timers[1].expired) timers[2].stop;
}
I understand that you can create a class and register it. I think I missed something with arrays though. I'm am open to any ideas.
Cheers,
Tony
You can do this 2 ways:
Alternative 1:
Use the built-in array object.
Use RegisterGlobalProperty to register the array variable with the script so that the script can access it.
Alternative 2:
Register your own array type with the index operator that returns references to the timers. You do this the same way you register other classes. Just the object type will be "Timer[]" for example. It will then override the built-in array type. Or you could just register it as a non-array type, i.e. "TimerCollection".
Regards,
Andreas
Alternative 1:
Use the built-in array object.
int arrayType = engine->GetTypeIdByDecl(0, "Timer[]");asIScriptArray *array = (asIScriptArray*)engine->CreateScriptObject(arrayType);array->Resize(2);for( int n = 0; n < array->GetElementCount(); n++ ){ Timer *timer = *(Timer**)array->GetElementPointer(n); // Initialize each timer}
Use RegisterGlobalProperty to register the array variable with the script so that the script can access it.
Alternative 2:
Register your own array type with the index operator that returns references to the timers. You do this the same way you register other classes. Just the object type will be "Timer[]" for example. It will then override the built-in array type. Or you could just register it as a non-array type, i.e. "TimerCollection".
Regards,
Andreas
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
Popular Topics
Advertisement