[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
GameMonkey Script :: View topic - Calling a script function from an ExecuteString
GameMonkey Script
http://www.gmscript.com/gamemonkey/forum/

Calling a script function from an ExecuteString
http://www.gmscript.com/gamemonkey/forum/viewtopic.php?f=6&t=541
Page 1 of 1

Author:  onimatrix [ Tue Apr 20, 2010 4:27 am ]
Post subject:  Calling a script function from an ExecuteString


Author:  Greg [ Tue Apr 20, 2010 11:52 am ]
Post subject:  Re: Calling a script function from an ExecuteString


Author:  DrEvil-OB [ Tue Apr 20, 2010 1:41 pm ]
Post subject:  Re: Calling a script function from an ExecuteString


Author:  onimatrix [ Tue Apr 20, 2010 3:15 pm ]
Post subject:  Re: Calling a script function from an ExecuteString

:lol:

The trick worked =)
Now I can write, store and use functions from inside the game.

Thanks!

Author:  onimatrix [ Wed Apr 21, 2010 4:06 pm ]
Post subject:  Re: Calling a script function from an ExecuteString

Hey, maybe you'll hang me for good, but I found a way to recover and use references to individual C++ objects from scripting by IDing them with their address.

For example, I have an object of base class cDynamicObject, which has a "type" parameter that gets filled with enum values (PLANET, SHIP, NEBULAE, etc).
The manager of such objects, cMngrDynamicObject, has searching methods and can recover an object by name through hashing.

That way, I only need to bind a C function that makes the manager search for X object, return it as a DWORD (The address) and then bind accessor functions that C-cast the DWORD to a cDynamicObject, read "type" and then dynamic_cast the object to the derived class.

So... what do you think?

Author:  DrEvil-OB [ Thu Apr 22, 2010 3:33 am ]
Post subject:  Re: Calling a script function from an ExecuteString

It's pretty unsafe to do that with the actual address. If the object is deleted on the c++ side, the script may still hold references to it, and as soon as it tries to call something on the object the app will crash.

Better would be to use a handle, and look up your object by handle. This allows it to fail gracefully if the object no longer exists.

My favorite implementation of a handle is to mash an index in an array, with a serial number. Then to look up your object you just mask out the index in your manager class to find the index the object exists in, but you also must verify that the serial number matches the object at that index. That way when an object is deleted from the array, the serial number for that element is incremented, invalidating any remaining handles that may still exist in script.

Author:  Greg [ Thu Apr 22, 2010 6:45 am ]
Post subject:  Re: Calling a script function from an ExecuteString

DrEvils described favorite method is probably the best and safest.

One thing to remember is that as long as you share a single gmObject you can nullify that object and test its validity. That is, you want all variables to point to the same object, not different objects. You achieve this by providing a accessor method which returns the one and only gmObject for your class instance. You may need to use the 'CPP owned' or gmGCRoot interfaces to retain the gmObject while it is not referenced in script, to prevent it from being garbage collected.

Author:  onimatrix [ Thu Apr 22, 2010 3:52 pm ]
Post subject:  Re: Calling a script function from an ExecuteString

Please remember that the script doesn't do anything with the objects other than passing them to a C function.
As I validate the address there, the script just isn't able to screw things up :P

Nonetheless, I'll surely be implementing something close to DrEvil's idea in a few versions. :)

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/