Community Forum

Timer issues

Forum Overview >> Farming Simulator 2009

CategoryFarming Simulator 2009
Created11.03.2010 16:32


Mark Farrington (chorleyboy) 11.03.2010 16:38
Hi,

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 -->

function myModEventListener:myTimerCallback()
print("Test");
return true;
end;

function myModEventListener:loadMap(name)
self.timerId = addTimer(10000, "myModEventListener.myTimerCallback", nil);
print("TimerId="..self.timerId);
end;

<-- 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,
Mark


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
Hi Stefan,

Many thanks for your help, my timer now works perfectly.

Cheers,
Mark

Christer F (Unknown) 02.06.2010 00:53
I can't get this to work and it's driving me crazy.
In function:
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:
function MyExampleMod:handleUnloading()
print("in handleunloading");

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.