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

executing arbitrary section

Started by
3 comments, last by mono2k 17 years, 3 months ago
Hello! I'm completely new to AngelScript and I'm doing my first steps to implement my own GUI subsystem based on AS. Currently I use xml definition to lay-out GUI elements and I'd like to use AS for event handling. Is it possible to execute an arbitrary script section, not just an arbitrary function (like in events sample from sdk)? Consider the following example:


// a bit ugly example, imagine a little xml file containing AS statements

<button id='button01' x='10' y='10' disabled='yes' on_click='enable_button("button01")' />

<button id='button02' x='10' y='20' on_click='if(buttons["button01"].disabled() == true) do_something()' />

...

<script>
 void enable_button(string& id)
 {
    // 
 };

 void do_something()
 {
    // GUI magic goes here
 };
</script>

There are 3 script sections in the example above: button01's on_click, button02's on_click and <script>..</script>. Due to design of my GUI subsystem it is very easy to handle all of these sections inside xml definition and pass them to the AS compiler to compile as a single module. But how do I execute on_click sections? Is there any way?
Advertisement
You can use ExecuteString() for that. The call would be something like:

int r = engine->ExecuteString("modulename", "enable_button(\"button01\")");if( r != asEXECUTION_FINISHED ){  // Something went wrong with the execution, examine what...}


The first parameter is the name of the module in which context you wish to execute the string, i.e. the same module name where you compiled the script functions. The second parameter is the event handler as it was defined in the xml.

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

Andreas, thank you very much for the answer!
Could you please explain asEXECSTRING_ONLY_PREPARE flag? What does this preparation mean?
By using the asEXECSTRING_ONLY_PREPARE you can tell ExecuteString() to setup and prepare a script context with the byte code that should be executed. The function will return without executing the byte code. This can be useful if you wish to have better control over when and how the byte code is executed.

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

thanks, nice feature... will try to use!

This topic is closed to new replies.

Advertisement