nowofresh Posted December 31, 2010 Share Posted December 31, 2010 Can u help me and tell me about, • for k,v in pairs • ipairs I was reading tutorials and I cant connect it with mta Can u get me examples lua + Mta ? Link to comment
Castillo Posted December 31, 2010 Share Posted December 31, 2010 addCommandHandler("test", function () for i,v in pairs (getElementsByType("player")) do outputChatBox(tostring(getPlayerName(v)) end end) this will output all names of the players online. http://www.lua.org/manual/5.1/manual.html#2.4.5 Link to comment
nowofresh Posted December 31, 2010 Author Share Posted December 31, 2010 function callServerFunction(funcname, ...) local arg = { ... } if (arg[1]) then for key, value in next, arg do arg[key] = tonumber(value) or value end end loadstring("return "..funcname)()(unpack(arg)) end addEvent("onClientCallsServerFunction", true) addEventHandler("onClientCallsServerFunction", resourceRoot , callServerFunction) What do this script ?? Link to comment
Castillo Posted December 31, 2010 Share Posted December 31, 2010 uhm read in the wiki for what is it. Link to comment
nowofresh Posted December 31, 2010 Author Share Posted December 31, 2010 key(valvue) is for function, tables ? is it constanse Link to comment
MexUK Posted December 31, 2010 Share Posted December 31, 2010 ipairs() is for tables where the keys are type 'number', start at 1 and increase by 1 on the next element the elements don't have to be added to the table in key order local Table = { 'a', 'b', 'c' } local Table = { [1]='a', [2]='b', [3]='c' } local Table = {} Table[1] = 'a' Table[2] = 'b' Table[3] = 'c' local String = table.concat(Table, " ") local Table = { unpack(Table) } for i,v in ipairs(Table) do end pairs() is for when the above doesn't apply, the keys can be any type lua supports, it will loop around all the elements in the table, but they are in a random order local Table = { 'key'='a', 'key2'='b', 'key3'='c' } local Table = {} Table['key'] = 'a' Table['key2'] = 'b' Table['key3'] = 'c' local Table = {} Table[2] = 'a' Table[8] = 'b' Table[0] = 'c' for k,v in pairs(Table) do end 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