Karoffe Posted September 8, 2014 Posted September 8, 2014 First question is: for k, player in ipairs(getElementsByType("player")) do outputChatBox(getPlayerName(player)) in that example it will loop through every player.. how could i make it just loop 1 time and outputs it like that for example "playername1 playername2 playername3" Second question is: I remember i saw a loop like that for index in ipairs(table) do what is that used for ?
Bonsai Posted September 8, 2014 Posted September 8, 2014 Instead of outputting it directly, you could just add the player names to a string and output it after that loop.
Karoffe Posted September 8, 2014 Author Posted September 8, 2014 Instead of outputting it directly, you could just add the player names to a string and output it after that loop. an example please ? "add the player names to a string" How's that ? local name = name ..getPlayerName(player) ???
Bonsai Posted September 8, 2014 Posted September 8, 2014 Well, try it But don't use local inside the loop.
Karoffe Posted September 8, 2014 Author Posted September 8, 2014 Yea, Worked, what about the other question ?
Moderators IIYAMA Posted September 8, 2014 Moderators Posted September 8, 2014 local theSupermarket = { "oranges", -- index 1 "apples", -- index 2 "cheese", -- index 3 "pizza", -- index 4 } for index,content in ipairs(theSupermarket) do outputChatBox("The index is: " .. index .. ", the content is: " .. content .. ", bon appetit!") end
Karoffe Posted September 8, 2014 Author Posted September 8, 2014 Yes, i know that.. I mean what if the table looks like that ? for index in ipairs(table) do
Moderators IIYAMA Posted September 8, 2014 Moderators Posted September 8, 2014 if you want to use "table" which contains all table functions, you need to loop with pairs instead of ipairs. (table doesn't have a array) for index,data in pairs(table) do outputChatBox(index .. " " .. tostring(data)) end remove function: 0x421580 maxn function: 0x4219a0 insert function: 0x421800 concat function: 0x421ac0 pack function: 0x421900 unpack function: 0x4216b0 sort function: 0x4214f0 Will return all table functions + index. So now you know where the "unpack" function comes from. value1,value2,value3 = table.unpack(myTable) value1,value2,value3 = table["unpack"](myTable)
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