WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   How print array? (https://www.wowinterface.com/forums/showthread.php?t=58504)

lungdesire 12-29-20 10:49 AM

How print array?
 
mass = {"one", "two", "three"}

test = "mass"

for i, v in pairs(test) do
print(v)
end

Why this code dont work and where error?

Rilgamon 12-29-20 10:55 AM

you assign the string "mass" to test. that fails in pairs. you should get a lua error. enable errors.

Vrul 12-29-20 11:13 AM

Quote:

Originally Posted by lungdesire (Post 338103)
mass = {"one", "two", "three"}

test = "mass"

for i, v in pairs(test) do
print(v)
end

Why this code dont work and where error?

Lua Code:
  1. local test = {"one", "two", "three"}
  2.  
  3. for i, v in pairs(test) do
  4.   print(v)
  5. end

briskman3000 12-29-20 11:25 AM

try table.foreach

table.foreach(tablename, print)

Walkerbo 12-31-20 07:04 PM

Quote:

Originally Posted by lungdesire (Post 338103)
mass = {"one", "two", "three"}

test = "mass"

for i, v in pairs(test) do
print(v)
end

Why this code dont work and where error?

I am still learning about programming but I wonder is the problem that you have a local table named mass and then you have a local string "mass" named test.

So when you are trying to iterate through the string variable test it fails as test is not a table.

Vrul has provided the actual answer.

lungdesire 01-02-21 07:36 AM

Thanks averyone. Use two-dimensional array


All times are GMT -6. The time now is 02:14 PM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI