GameMonkey Script

GameMonkey Script Forums
It is currently Mon Nov 20, 2017 3:26 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue Jan 31, 2012 7:57 am 
Offline

Joined: Tue Jan 31, 2012 7:53 am
Posts: 12
Hi, I would like to know how to use reflection in gamemonkey script, I searched in the documentation and this forum but found nothing (unless I missed something),
Can anyone please give me some hints?

My intention is to make a game object script and expose all the (public) member variables in the gui editor, for the designer to tweak the game object's parameters.
Thanks.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 31, 2012 1:51 pm 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 698
Welcome to the forum Wihu :)

I think you are asking how to list global variables from a script file so the values can be edited and injected later while the application is running.

You'll need to do something like this...

1) Create an instance of gmMachine and execute the script.
2) Call gmMachine::GetGlobals to access the global gmTableObject.
3) Use gmTableObject::GetFirst, GetNext to iterate the table and retrieve key & value gmVariables.

When the application is running you can access the global table again and call gmTableObject::Set to apply the replacement values.

Hope that gets you started.

(There are other ways to achieve this, such as writing a script that does a foreach loop and calls a bound function to accumulate the global table contents. You could apply global variables by executing strings with assignment operations. I don't recommend these methods, just suggesting how it is possible to use native, script or both to achieve these kinds of goals.)


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 01, 2012 7:02 am 
Offline

Joined: Tue Jan 31, 2012 7:53 am
Posts: 12
Hi Greg,

Thanks for the prompt reply.
Its close to what I need, but can I attach one script per game object such that each game object has its own member variables when executing the script?

What I want to achieve is actually something similar to Unity3d's Game Object editor, is it possible to use GameMonkey for that purpose? or should I write my own c++ reflection library on top of that?


Top
 Profile  
Reply with quote  
PostPosted: Wed Feb 01, 2012 7:35 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 698
Yes, you should be able to achieve what you are describing. I have seen game level/scene editors use GM in a very similar way to what you see in Unity and that is how it is intended to be used.

Instead of using global variables, you may just want to use member variables so they can be set per game object. To get the 'one script per game object' behavior, you will want to set member functions to be executed at specific times or as events.

If you haven't already, please read the excellent GM articles by downgraded. The 3rd one in particular talks about practical game object implementation.

You may end up writing some helper functions or a GM utility class, but access to the types and values in GM should be provided by the existing API. Mostly you will be working with gmTables, gmVariables and making sure you set 'this' when calling script functions from native code.


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 02, 2012 1:29 am 
Offline

Joined: Tue Jan 31, 2012 7:53 am
Posts: 12
Thanks a lot, Greg! Thats really helpful, I have read the first two articles by downgraded, but did not know there is the third one (google missed that when I typed keywords 'GameMonkey GameDev').

I'll take a look on it and see how it goes. I think I already got some rough idea from what you have explained to me.

Just one quick question (pardon me if this is a little bit off the topic), do you happen to know any open source games/projects that use GameMonkey?

Meanwhile, I'll play around with GameMonkey script and see how far I can go with it.


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 02, 2012 4:13 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 698
wihu wrote:
...Just one quick question (pardon me if this is a little bit off the topic), do you happen to know any open source games/projects that use GameMonkey?..
I can't name any open source games off hand. It's worth googling to see what appears. I've mostly seen glimpses of commercial games using GM. Have a look in the Resources section of the forum in case there are useful projects or helpers worth using. I know DrEvil's Game Monkey Script Ex project has a bunch of cool features and extensions that aren't in my build.


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 02, 2012 2:49 pm 
Offline

Joined: Tue Jan 31, 2012 7:53 am
Posts: 12
Looks like this forum has some interesting stuff.. Richy2k's particularly..

I'll try Game Monkey Script Ex when I feel Game Monkey Script is not enough.. Thanks for the hints!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 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