[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

GameMonkey Script Forums
It is currently Tue Nov 24, 2020 12:51 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Tue Apr 20, 2010 4:27 am 
Offline

Joined: Mon Apr 19, 2010 3:09 pm
Posts: 5


Top
 Profile  
Reply with quote  
PostPosted: Tue Apr 20, 2010 11:52 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 708


Top
 Profile  
Reply with quote  
PostPosted: Tue Apr 20, 2010 1:41 pm 
Offline

Joined: Fri Jan 14, 2005 2:28 am
Posts: 439


Top
 Profile  
Reply with quote  
PostPosted: Tue Apr 20, 2010 3:15 pm 
Offline

Joined: Mon Apr 19, 2010 3:09 pm
Posts: 5
:lol:

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

Thanks!


Top
 Profile  
Reply with quote  
PostPosted: Wed Apr 21, 2010 4:06 pm 
Offline

Joined: Mon Apr 19, 2010 3:09 pm
Posts: 5
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?


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 22, 2010 3:33 am 
Offline

Joined: Fri Jan 14, 2005 2:28 am
Posts: 439
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.


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 22, 2010 6:45 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 708
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.


Top
 Profile  
Reply with quote  
PostPosted: Thu Apr 22, 2010 3:52 pm 
Offline

Joined: Mon Apr 19, 2010 3:09 pm
Posts: 5
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. :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group