Quantcast
How print array? - WoWInterface
Thread Tools Display Modes
12-29-20, 10:49 AM   #1
lungdesire
A Deviate Faerie Dragon
Join Date: May 2020
Posts: 13
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?
  Reply With Quote
12-29-20, 10:55 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 813
you assign the string "mass" to test. that fails in pairs. you should get a lua error. enable errors.
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
12-29-20, 11:13 AM   #3
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 403
Originally Posted by lungdesire View Post
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
  Reply With Quote
12-29-20, 11:25 AM   #4
briskman3000
A Warpwood Thunder Caller
 
briskman3000's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 90
try table.foreach

table.foreach(tablename, print)
__________________
My Addons: Convert Ratings Honor Track
  Reply With Quote
12-31-20, 07:04 PM   #5
Walkerbo
A Flamescale Wyrmkin
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 113
Originally Posted by lungdesire View Post
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.
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz

Last edited by Walkerbo : 12-31-20 at 07:11 PM.
  Reply With Quote
01-02-21, 07:36 AM   #6
lungdesire
A Deviate Faerie Dragon
Join Date: May 2020
Posts: 13
Thanks averyone. Use two-dimensional array
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How print array?

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off