|
Excuse me, but how would I check the name of a value in a table? Could you give me an example? |
|
youssef04Join Date: 2011-01-22 Post Count: 1745 |
table = {"bob", "hi", "lol"}
for i,v in pairs (table) do
wait(1)
print(v)
end
PRINT:
--bob
--hi
--lol |
|
|
No. I meant in an if statement. Like: if v.Name == "blah" then |
|
|
|
@youssef04
Naming a table, "table" is a bad idea.
--------------------
@OP
list = {"Apples","Bananas",true,false}
if list[2] == "Bananas" then
print("Bananas are at list[2] inside the table \'list\'")
end |
|
|
yourtable = {"some", "values", "foo", "bar"}
function isInTable(tb, value)
for _,v in pairs(tb) do
wait();
if (v==value) then return true; end;
end
return false;
end
print(isInTable(yourtable, "some").." : "..isInTable(yourtable, "foobar"));
> "true : false"
That should do it. Just put the function somewhere. |
|
|
Could you guys code it into this? My head hurts from having to do some hacky crap in the other blocks of code:
function removeItem(y)
currentItems = #inventory
if (currentItems < 1) then
print('Nothing to remove')
else
for i = 1, currentItems do
if i == y then
table.remove(inventory, i)
print('Item removed.')
break
end
end
currentItems = #inventory
end
end |
|
|
function removeItem(y)
currentItems = #inventory
if (currentItems < 1) then
print('Nothing to remove')
else
for i = 1, currentItems do
if currentItems[i] == y then
table.remove(inventory, i)
print('Item removed.')
break
end
end
currentItems = #inventory
end
end |
|
|
Oh yeah, I forgot. currentItems is a number value. |
|
|
Damn, I'm seriously stumped. |
|
|
:D I fixed it! Open source YAYAYAYAYAYAYA!:
inventory = {}
maxItems = 10 -- change this to how many items you can store
currentItems = #inventory
function addItem(x)
currentItems = #inventory
if (currentItems < maxItems) then
local item = table.insert(inventory, (currentItems + 1), x)
print(x.. ' added')
currentItems = #inventory
else
print('Inventory already full.')
end
end
function removeItem(y)
currentItems = #inventory
if (currentItems < 1) then
print('Nothing to remove')
else
for i = 1, #inventory do
if inventory[i] == y then
table.remove(inventory, i)
print(y.. ' removed.')
break
end
end
currentItems = #inventory
end
end
addItem("sword")
addItem("axe")
removeItem("axe")
print(table.concat(inventory, ' ')) |
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
tble = {"derp","hi",tostring(lel),"abc"}
if table.concat(table):match(something.Name:lower()) then
print("Yusss")
end
--scripz go fatstar if'd table.concat |
|
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
Ur cool |
|
|