GameMonkey Script

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

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Feb 09, 2011 10:53 am 
Offline

Joined: Sat Apr 25, 2009 1:40 am
Posts: 66
I have an object called "Npc". This object has an array called "Colours". The user needs to be able to change this value like this:

npc.colours[0] = 4334; //A colour is an integer value
npc.colours[1] = 234242;

But there is no way to modify this type of behavior. I can only change the O_SETIND for npc[INDEX] but not npc.colours[INDEX].
The only way i can think of doing this is by making "colours" its own data type, which actually points to the "npc" object. This is how i have it:

Code:
void GM_CDECL GraalNpc::OPColourIndexSet(gmThread * a_thread, gmVariable * a_operands)
{
    GraalNpc* thisObject = static_cast<GraalNpc*>(a_operands[0].GetUserSafe(GraalNpc::GetColoursType()));
    int colourIndex = a_operands[1].GetIntSafe();
    int colourValue = a_operands[2].GetIntSafe();
    thisObject->SetColour(colourIndex, colourValue);
}


Is there any other way?


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 10, 2011 10:24 pm 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 698
What you've described is correct. To access the index operator, color must be a type itself.
If you don't want to do this, just expose set color function(s).
Code:
npc.SetColor(0, 4334);  // Standard bindings
npc.SetColor(1, 234242);
     or
npc.SetColors(4334, 234242); // Can handle variable args, can add start index etc.


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 12, 2011 11:00 am 
Offline

Joined: Sat Apr 25, 2009 1:40 am
Posts: 66
Ok so "colour" is it's own datatype. Let's say i have a script like this:

Code:
owner.colours[3] = 3232;


Is there any way to get the value of "owner" when the colours index-get/set is called?


Top
 Profile  
Reply with quote  
PostPosted: Sat Feb 12, 2011 12:21 pm 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 698
39ster wrote:
Is there any way to get the value of "owner" when the colours index-get/set is called?
Just like C++ there's no implicit access to the owner of a member type. You would have to add the owner as part of that type and include the appropriate logic such as informing owner of a color change on SetInd.

I guess another simple way to implement the color type would be something like...

1) In NPC, implement a GetDot operator which checks for "colours" and otherwise falls back to the original implementation.
2) In the GetDot, PushNewUser(this, TypeColor), where this IS the owner pointer. TypeColor is a registered user type.
3) Inside the NPC class, implement bindings for TypeColorSetInd() index operator.

I think that would just about accomplish it, producing the interface you first describe with very found bound functions (perhaps just two).

What it does is...
1) Override dot operator to allow access to the pretend color type.
2) Implement this pretend color type which is logically part of the owner and since it contains ONLY the owner pointer, does not even require a GCDestruct binding.
3) Implement the index operator for the color type, which might as well be (a static function) in the NPC class since that is its only purpose.

Let me know how you go.


Top
 Profile  
Reply with quote  
PostPosted: Mon Feb 14, 2011 3:06 am 
Offline

Joined: Sat Apr 25, 2009 1:40 am
Posts: 66
That's actually how i've been doing it 8)

The obvious thing to do is what you said before...by creating a member function called "SetColour()" and "GetColour()". The problem is i'm trying to emulate an existing language/api. The second obvious thing would be to make "colours" a gmTableObject and simply return it from the npc.DotGet request. The problem with that is there needs to be some logic when the user modifies a colour value.


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