Sorry if this has been covered before, I searched and found no results - maybe I searched for the wrong item.. any help with this would be much appreciated.
If have a table such as:
table = { user1 = 1, user2 = 1, user3 = 1, user4 = 2, user5 = 1 }
I wish to output in the hub any user with the value of "1"
for instance:
Table = user1, user2, user3, user5
i've tried a number of things and cannot get it to work right, I am fairly new to Lua, but learning fast, again any help with this would be much appreciated.
Hydrogen
table = { [user1] = 1, [user2] = 1, [user3] = 1, [user4] = 2, [user5] = 1 }
this is theway how indexing of tables works.
Yes but I wish to output any thing in the table with a value of "1",
ie:
I want the script to be able to output this into the hub:
Table = user1, user2, user3, user5
for index,value in table do -- do this till there are indexes & values in the table
if value=1 then -- if value is 1
SendToAll(value) -- sends tehe value into main
end
end
thats the general sketch
Just another show-how
local finalString = ""
for index,value in table do -- do this till there are indexes & values in the table
if value=1 then -- if value is 1
finalString = finalString..index..", "
end
end
SendToAll(finalString) -- sends tehe value into main
I appreciate your help very much :)
but wouldnt it go like this:
---------------------------------------------
for i,v in table do
if v == 1 then
SendToAll(i)
end
end
---------------------------------------------
Now all I need to figure out is how to make it one line, it is currently displaying:
user1
user2
user3
user5
I would like it to display:
user1, user2, user3, user5
Thank you for shedding some light on the subject for me... Im halfway there now
thank herodes for your reply .. although with this code:
function printtable(user,data)
local finalstring = ""
for i,v in test do
if v == 1 then
finalstring = finalstring.. i..", "
SendToAll(finalstring)
end
end
end
it displays this in main:
user1,
user1, user2,
user1, user2, user3,
user1, user2, user3, user5
how would I go about fixing this?
function printtable(user,data)
local finalstring
for i,v in test do
if v == 1 then
finalstring = finalstring.. i..", "
end
end
SendToAll(finalstring)
end
thank you bastya and herodes,
got it working now...
cheers