Search the Community
Showing results for tags 'method'.
-
I was making a new script with classes for mta, and i need to set a timer inside a method like this. function WorldGrid:updatePlayerZone(player) -- DOING NON RELEVANT SHI T HERE outputChatBox("worldGrid: " .. tostring(worldGrid) .. " player: " .. tostring(player)) setTimer(self:updatePlayerZone, 4000, 1, player) end end This couldnt even compile, because self:updatePlayerZone is not recognized as a function. So.. i checked setTimer mta wiki page. it says: theFunction: The function you wish the timer to call. (Notice: Do not use a 'local' function, it must be global!) So, i need to call a global function on setTimer. I tryed out this: function updatePlayerZoneWrapper(worldGrid, player) outputChatBox("worldGrid " .. tostring(worldGrid) .. " player: " .. tostring(player)) worldGrid:updatePlayerZone(player) end function WorldGrid:updatePlayerZone(player) outputChatBox("worldGrid before: " .. tostring(self) .. " player before: " .. tostring(player) setTimer(updatePlayerZoneWrapper, 4000, 1, self, player) end end But it didnt work neither.. I get: Attempt to call method 'updatePlayerZone' (a nil value) I continued reading setTimer wiki page, and i found this: arguments: Any arguments you wish to pass to the function can be listed after the timesToExecute argument. Note that any tables you want to pass will get cloned, whereas metatables and functions/function references in that passed table will get lost. Also changes you make in the original table before the function gets called won't get transferred. So, im coming to you guys, hoping you have a possible solution for this. Thanks for your time