Jump to content

global variable array problem


drarem
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...