GameMonkey Script

GameMonkey Script Forums
It is currently Fri Mar 22, 2019 10:11 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Mon Feb 28, 2011 8:15 pm 
Offline

Joined: Mon Feb 28, 2011 8:06 pm
Posts: 12
Let's say I have a UserType bound. To that UserType, I have bound a function, Foo(). Assume "ObjA" is an instance of my UserType.

Here is some code that works:
Code:
ObjA.Foo();


Here is some code I'd like to use, but that doesn't work:
Code:
thread(ObjA.Foo);


Here is a work-around:
Code:
f = function() { ObjA.Foo(); };
thread(f);


Is this the correct way to spin up a thread for a bound UserType function? Do I have to jump through this hoop to make it work, or is there some way to set up the function so I can pass it directly?


Top
 Profile  
Reply with quote  
PostPosted: Tue Mar 01, 2011 10:47 pm 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 708
Welcome to the forum Tiok :)
I think I see what the problem is. When you pass ObjA.Foo as a function to thread(), the 'this' is not automatically passed. Whereas when you simply call the function yourself, it is a 'type' function with implicit 'this'.
The work around should be:
Code:
ObjA:thread(ObjA.Foo);
Let us know how that goes.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 02, 2011 3:43 pm 
Offline

Joined: Mon Feb 28, 2011 8:06 pm
Posts: 12
Apparently I slimmed down my example a step too far, then. I still get the error using your example work-around. Here is a more complete set of code that I am using.

Code:
local script = table();
script.ObjA = GetMyObject("uniqueID");

script.EventHandlerFunction = function()
{
    block(signal);
    .ObjA:thread(.ObjA.Foo);
};

script.StartupFunction = function()
{
    this:thread(.EventHandlerFunction);
    this:thread(GlobalFunctionThatEventuallySignalsEventHandler);
};

script:thread(script.StartupFunction);


Yeah, the code looks a little silly, but it's necessary to do all the zany threading for my particular event system.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 03, 2011 2:41 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 708
Can you tell me exactly what the error or incorrect behavior is? If you break point or debug around the error, can you determine what is going on? It would be very helpful if you could write a fragment of code that could reproduce the issue with GME.exe.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


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