Jump to content
This Topic

Recommended Posts

Posted

After I've initialized the array using a function, I can do this:

 

globals.myarray[1][1] = 0

 

and it works, but if I do this:

 

local fx=globals.reti

local fy=globals.retj

 

System:Print(...) ..

fx, fy are now equal to 1,1

 

This won't work:

globals.myarray[fx][fy] = 0

 

I get this error: 253 : attempt to index a nil value

 

What is going on?

 

thanks

Posted

This will create a multi-dimensional array of 10 x 10 with every value set to zero:

 

myarray = {}
for f=1, 10 do
   myarray[f] = {}
   for g=1, 10 do
       myarray[f][g] = 0
   end
end

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Posted

It's odd, that's what I have but when I access it in another function (after it has been initialized and called), then crashes with a 'nil' like it has gone out of scope. BUT if I hardcode the numbers, it works.

 

 

myarray[fx][fy] = 0 -- nil error

 

myarray[3][1] = 0 -- works

Posted

We will probably need to see all of the code that initializes the array and then accesses it in another function to determine the problem. But if I had to guess is that you are setting the 'fx' & 'fy' variables local to a function other than the function you are accessing the array with so those are not defined in the access function. Again without seeing your full code example, its hard to troubleshoot.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Posted

Many thanks, after thinking about the 'fx and fy' variables and some testing, I realized those were a string value instead of numeric. I converted them to a number using tonumber(fx) and tonumber(fy), and it works as expected. :)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...