 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Mr Billy
Joined: 26 Oct 2005 Posts: 10
|
Posted: Fri Dec 23, 2005 10:40 am Post subject: problem with for statement and tables |
|
|
i have two tables, one holding my images(tiles) and one holding the layout of the tiles. i am using a for statement so i dont have many lines of code. when i use this code, i get an "attempt to index field '?' (a nil value)" error on the blit line. if i replace the y in layout[y] for a number, it seems to work. why doesnt it work with a variable?
| Code: | for y=1,16 do
screen:blit(0, ((y*32)-32), images[layout[y].block1])
end |
thanks _________________ "There is no spoone"
-The Matricks |
|
| Back to top |
|
 |
romero126
Joined: 24 Dec 2005 Posts: 200
|
Posted: Sat Dec 24, 2005 4:25 pm Post subject: |
|
|
Your Code
| Code: |
for y=1,16 do
screen:blit(0, ((key*32)-32), images[layout[y].block1])
end
|
Try this its simpler and will never give you any issues.
This is to make shure the table Images has what your looking for.
| Code: |
for key,value in layout do
if (images[value.block1]) then
screen:blit(0, ((key*32)-32), images[value.block1])
end
end
|
The code Checks if the value exists before trying to print it.
So you dont have errors like that if the data is nothing. Also it goes through the entire loop so you can set it with another statement.
If you just want it to do up to number 16 (that is if you numbered it)
| Code: |
if (images[value.block1]) and (key <= 16) then
screen:blit(0, ((key*32)-32), images[value.block1])
end
|
*Edited for typo' in key (Within code) |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|