Miika Posted June 7, 2015 Share Posted June 7, 2015 (edited) Again.. I'm having problem: how to get one item from table? If my table looks this: teams= { {"Team", 0, 255, 0}, {"Team2", 255, 0, 0}, {"Team3", 0, 0, 255}, -- I need to get all items from "Team3" and output to chatbox. {"Team4", 0, 255, 255}, } function test() outputChatBox(--[[Team3 here]], --[[Color numbers from table in here]]) end addCommandHandler("test", test) Is it possible? Edited June 7, 2015 by Guest Link to comment
-.Paradox.- Posted June 7, 2015 Share Posted June 7, 2015 viewtopic.php?f=91&t=84040 It might help you Link to comment
Miika Posted June 7, 2015 Author Share Posted June 7, 2015 https://forum.multitheftauto.com/viewtopic.php?f=91&t=84040It might help you Yeah, but your topic doesn't help me. It outputs first message from all table items. I need message and numbers from one item to chatbox. Link to comment
Dealman Posted June 7, 2015 Share Posted June 7, 2015 I'm assuming you want to use this table to create teams, right? If so, you can structure it like this instead; teams = { [1] = {"Team", 0, 255, 0}, [2] = {"Team2", 255, 0, 0}, [3] = {"Team3", 0, 0, 255}, [4] = {"Team4", 0, 255, 255} } createdTeams = {} for key, value in ipairs(teams) do -- Example on how you fetch a separate value from the multi-dimensional array outputChatBox("Team Name: "..tostring(teams[key][1])) outputChatBox("Red: "..tostring(teams[key][2])) outputChatBox("Green: "..tostring(teams[key][3])) outputChatBox("Blue: "..tostring(teams[key][4])) -- Create Teams (Server-Sided) local theTeam = createTeam(tostring(teams[key][1]), tonumber(teams[key][2]), tonumber(teams[key][3]), tonumber(teams[key][4])) table.insert(createdTeams, theTeam) -- You can save the team to a table so you can easily access it later on end Link to comment
Enargy, Posted June 7, 2015 Share Posted June 7, 2015 try: outputChatBox(tostring(teams[3][1]), teams[3][2],teams[3][3],teams[3][4]) Link to comment
Miika Posted June 7, 2015 Author Share Posted June 7, 2015 I'm assuming you want to use this table to create teams, right? If so, you can structure it like this instead; teams = { [1] = {"Team", 0, 255, 0}, [2] = {"Team2", 255, 0, 0}, [3] = {"Team3", 0, 0, 255}, [4] = {"Team4", 0, 255, 255} } createdTeams = {} for key, value in ipairs(teams) do -- Example on how you fetch a separate value from the multi-dimensional array outputChatBox("Team Name: "..tostring(teams[key][1])) outputChatBox("Red: "..tostring(teams[key][2])) outputChatBox("Green: "..tostring(teams[key][3])) outputChatBox("Blue: "..tostring(teams[key][4])) -- Create Teams (Server-Sided) local theTeam = createTeam(tostring(teams[key][1]), tonumber(teams[key][2]), tonumber(teams[key][3]), tonumber(teams[key][4])) table.insert(createdTeams, theTeam) -- You can save the team to a table so you can easily access it later on end --------------------------------------------------------------------------------------------------------------- try: outputChatBox(tostring(teams[3][1]), teams[3][2],teams[3][3],teams[3][4]) Thanks! It works perfectly 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