|
#1
|
|||
|
|||
|
I have a table set up as a two dimensional array let us say 10 x 10 and each element contains a number.
I want to fill a smaller array of say 5 x 5 with the numbers contained in a 5 x 5 section of the larger table. I have tried the obvious as would be done with normal arrays in say Basic, but it gives the error that I am attempting to index a field ( a nil value) Please can somebody help before I go bald. |
|
|
|||
|
|
|
#2
|
|||
|
|||
|
Can you post the part of code in wich you are trying to use the array, pls?
|
|
#3
|
||||
|
||||
|
From the error message I guess that you have a variable/image/whatever named the same as something that's on the line that gives the error message.
Okay I know this sounds vague, and I'm not sure if this is the case, but check if you have named some variable the same as another thing.. for example, naming an image "button" gives an "attempt to call field 'event' (a nil value)" when you call button.click(). Ok it's not really the same as your error but I think it's about the same issue. It would indeed help if you posted the code. |
|
#4
|
|||
|
|||
|
Thanks for responding. I can't really include all the code but here are the table declarations and the errored code.
The variable values are known to be correct. The error main.lua:90: attempt to index field '?' (a nil value) Lua Run Error : attempt to index field '?' (a nil value) Code:
--create grids
MiniGrid = {}
for Col=1,kMagnify do
MiniGrid[Col] = {} -- create a new Col
for Row=1,kMagnify do
MiniGrid[Col][Row] = 0
end
end
Grid = {}
for Col=1,kCells do
Grid[Col] = {} -- create a new Col
for Row=1,kCells do
Grid[Col][Row] = 0
end
end
--copy part of grid to minigrid
for Col=1,kMagnify do
for Row=1,kMagnify do
--copy to mini from grid line 90 follows
MiniGrid[Col][Row] = Grid[cX+Col*kCell+1][cY+Row*kCell+1]
end
end
|
|
#5
|
|||
|
|||
|
try replace
Code:
--copy part of grid to minigrid for Col=1,kMagnify do for Row=1,kMagnify do Code:
--copy part of grid to minigrid for Col=1,kMagnify-1 do for Row=1,kMagnify-1 do |
|
#6
|
|||
|
|||
|
Thanks but no it doesn't. If I had been using 0 to 4 (kMagnify) then it would but I have four entries 1-4 and kMagnify is 4.
Any other suggestions please? Am I trying to change a key rather than data? I must confess a little difficulty with tables. Last edited by Donone; 05-13-2010 at 02:06 AM. |
|
#7
|
||||
|
||||
|
Maybe Grid[cX+Col*kCell+1][cY+Row*kCell+1] doesn't exist.
You've created Grid[1][1] till Grid[kCells][kCells] , and if you just calculate "cX+Col*kCell+1" I guess it's way higher than kCells or is maybe some weird fraction. Edit: which values did you print and were nil? |
|
#8
|
|||
|
|||
|
Thank you for your time in looking at this. You are correct in that Grid[cX+Col*kCell+1][cY+Row*kCell+1] does not exist. cX goes too high (85), wow.
The nils came from my printing the array content just outside the creating loop which meant I was checking one off the end as i,j had completed. Now solved. Thanks for pointing me to it. The solution always seems to be something stupid added to blindness. |
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 02:26 PM.











Linear Mode
