|Category||Farming Simulator 2009|
|Mark Farrington (chorleyboy)||11.03.2010 16:38|
I can't seem to get the timer event to work in my extra source file mod script. I'm not sure what I'm doing wrong (maybe timers are not supported in this type of mod?). Here's a cut down version of my script.
<-- snip -->
self.timerId = addTimer(10000, "myModEventListener.myTimerCallback", nil);
<-- snip -->
I get a timer ID created just fine but I never see my "Test" message logged in the game log. To work around this issue I'm using the update event and keeping track of the time that way but I guess that timers would be more efficient?
Any help much appreciated. Thanks,
|Stefan Geiger - GIANTS Software||12.03.2010 09:16|
|The problem is, that each mod is located in a separate namespace, thus the engine can not find the callback function "myModEventListener.myTimerCallback".
You should use the target object instead, to point to the correct object.
self.timerId = addTimer(10000, "myTimerCallback", self);
This also has the advantage that you can use the variable "self" in the function myModEventListener:myTimerCallback().
|Mark Farrington (chorleyboy)||19.03.2010 10:09|
Many thanks for your help, my timer now works perfectly.
|Christer F (unknown)||02.06.2010 00:53|
|I can't get this to work and it's driving me crazy.
MyExampleMod:keyEvent(unicode, sym, modifier, isDown)
I have among other things these lines:
self.unloadTimerID = addTimer(1000, "handleUnloading", self);
print ("unloadTimer id: " .. self.unloadTimerID);
And the print statement completes with a timer id (usually starts at 59).
Then I have this function:
And that print statement never occurs.
Can anyone see something wrong?
|Stefan Geiger - GIANTS Software||04.06.2010 09:23|
|Is the MyExampleMod a vehicle specialization?
If this is the case, the problem is that functions are not registered to self. So you are not able to call self:handleUnloading which is what the timer tries to do.
To make this working, you should call this in the MyExampleMod:load function:
self.handleUnloading = MyExampleMod.handleUnloading;
|Christer F (unknown)||08.06.2010 23:38|
|Thank you so much! It works! Perhaps this is the same problem I have with the collision trigger. I have test this at that problem also.
Note: Log in to post. Create a new account here.