View Single Post
08-26-16, 04:35 PM   #1
Twitchy250
A Deviate Faerie Dragon
Join Date: Aug 2016
Posts: 14
Lua loop Multidementional Array help

Hello wowinterface,

I am beginning learning Lua to start writing wow addons. ( I do have prior experience due to html and php)

I am trying to loop through a multidementional array displaying certain info from them.

Lua Code:
  1. function HelloWorld()
  2.   a = {{1,2,3}, {4,5,6}, {7,8,9}}
  3.   m = print (#a);
  4.  
  5.   for i=0,3,1
  6.   do  
  7.     print(a[1]);
  8.  
  9.   end
  10. end

This example works except the outputting of the array which seems to display random data.

The second part of my problem is the array would be a variable legnth so using 3 as a peramiter is too specific to properly pull out data.

Lua Code:
  1. function HelloWorld()
  2.   a = {{1,2,3}, {4,5,6}, {7,8,9}}
  3.   m = print (#a);
  4.  
  5.   for i=0,m,1
  6.   do  
  7.     print(a[i][1]);
  8.  
  9.   end
  10. end

I've tried several different things debugging, including the example above grabbing the number of sections in the array to determine how many times to loop, but using a variable instead of an exact number seems to break the for loop and doesn't output anything.

I've also done several google searches.

It would be much appreciated if someone could help me fix the issue or let me know of a better way of doing this.

All help is appreciated! Thanks
  Reply With Quote