Moderators IIYAMA Posted January 14, 2014 Moderators Share Posted January 14, 2014 https://wiki.multitheftauto.com/wiki/SetTimer Required Arguments theFunction: The function you wish the timer to call. (Notice: Do not use a 'local' function, it must be global!) timeInterval: The number of milliseconds that should elapse before the function is called. (the minimum is 50)(1000 milliseconds = 1 second) timesToExecute: The number of times you want the timer to execute, or 0 for infinite repetitions. Why I can't use local functions for my timers? I am doing it for a long time and it is working.... and never had any strange problems with it...... Link to comment
DiSaMe Posted January 14, 2014 Share Posted January 14, 2014 I don't understand this either. After all, function cannot be "local" or "global", it's just a value which, like any other value, can be stored in local and global variables. Link to comment
tosfera Posted January 14, 2014 Share Posted January 14, 2014 I don't understand this either. After all, function cannot be "local" or "global", it's just a value which, like any other value, can be stored in local and global variables. A function can be made local, look at this example: local function testFunction () end Each function you create without the 'local' will automaticly be created as a 'global' function. I have no idea what's the exact difference between them but there is something haha. Maybe it's because of the scope for other files, but not sure if this is because of the OOP version of LUA... Link to comment
Moderators IIYAMA Posted January 14, 2014 Author Moderators Share Posted January 14, 2014 @ CrystalMV Yes, that is what I meant. Very strange, no explanation, but no problems with it. @tosfera I make all possible functions variables local, because they are 2/3 times faster then a normal function variable. A function returns their own variable, except in this case it returns a local one. local function myFunction(text) outputChatBox("myFunction "..text) end local mySecondFunction = function(text) outputChatBox("mySecondFunction "..text) end local myStrangFunction function myStrangFunction(text) outputChatBox("myStrangFunction "..text) end local myFunctionTable = {myFunction,mySecondFunction,myStrangFunction,outputChatBox} addEventHandler("onResourceStart",resourceRoot, function() for i=1,#myFunctionTable do myFunctionTable[i]("HI!") end end) All function variables became local and get looped inside a table. Included a function we already know "outputChatBox". Link to comment
DiSaMe Posted January 14, 2014 Share Posted January 14, 2014 I don't understand this either. After all, function cannot be "local" or "global", it's just a value which, like any other value, can be stored in local and global variables. A function can be made local, look at this example: local function testFunction () end Each function you create without the 'local' will automaticly be created as a 'global' function. I have no idea what's the exact difference between them but there is something haha. Maybe it's because of the scope for other files, but not sure if this is because of the OOP version of LUA... That's wrong. Every value can be accessed from anywhere it is passed to. All I can see in your example is that you're creating a function and storing it to a local variable 'testFunction'. Yet, I don't see such things like "local" or "global" values, no matter if they're numbers, strings, tables or functions. The line 'local testNumber = 1' doesn't create a "local number" either. Link to comment
Moderators IIYAMA Posted January 15, 2014 Author Moderators Share Posted January 15, 2014 I started to learn lua after I started mta, to be honest I don't know the names for the stuff, I only know how they can be useful. How would you describe it? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now