I'm attempting to use a table as a means to do two things at once. For example:
s = passengers -- user input
t = {[3] = car, [7] = bus, [24] = plane, [45] = train}
for k,v in ipairs t do
if s = k then
z = v * 10 -- cost per person
end
end
Now this is extremely basic for what I'm trying to do. I have a list of about 12 items that each have their own number. I want to know if I can do what I did above with the table and provide each of the 12 items with their own key value and then use that ? This key value would represent each items particular, unique number. Also, can I then use that key's value in a later equation, such as above?
ipairson a table with "holes" like that.ipairsbehaviour is defined only for tables that have contiguous indices from 1 to n.car,bus, etc. are variables that will create an empty table. You are also missing the(and)aroundtin theipairscall and you mean==and not=in theifcondition.