forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

help !! about table of image.load

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
justatest



Joined: 19 Dec 2005
Posts: 10

PostPosted: Mon Dec 19, 2005 6:05 pm    Post subject: help !! about table of image.load Reply with quote

i have make a code like these :
Blocks_Pos = {

["c0"] = {img=Image.load("x0.png"), y=0, x=1},
["c1"] = {img=Image.load("x1.png"), y=2, x=1},
["c2"] = {img=Image.load("x2.png"), y=0, x=0},
["c3"] = {img=Image.load("x3.png"), y=0, x=3},
["c4"] = {img=Image.load("x4.png"), y=2, x=0},
["c5"] = {img=Image.load("x5.png"), y=2, x=3},
["c6"] = {img=Image.load("x6.png"), y=3, x=1},
["c7"] = {img=Image.load("x7.png"), y=3, x=2},
["c8"] = {img=Image.load("x8.png"), y=4, x=0},
["c9"] = {img=Image.load("x9.png"), y=4, x=3}

}

for key in Blocks_Pos do
screen:blit(offsetx+Blocks_Pos[key].x*unit_width, offsety+Blocks_Pos[key].y*unit_height, Block_Pos[key].img)
end



but the visit of Block_Pos[key].img get the err msg as "attempt to index global `Block_Pos' (a nil value)"

so, if i DO want to make a table of image.load , what should i do ? i use luaplayerwindows .
thx guys !
Back to top
View user's profile Send private message
mrn



Joined: 02 Nov 2005
Posts: 116

PostPosted: Mon Dec 19, 2005 7:37 pm    Post subject: Reply with quote

are you filling your Block_Pos in the main routine outside any function?
Then it is Global. You should fill it before using it.

If first you try to use it inside a function without filling it before ...
ya, i think this is the prblm here..
Back to top
View user's profile Send private message
justatest



Joined: 19 Dec 2005
Posts: 10

PostPosted: Mon Dec 19, 2005 7:50 pm    Post subject: Reply with quote

thx . but seem this is not the problem .

cos i can visit the Block_Pos[key].x and Block_Pos[key].y , but while i change the define as these:

Blocks_Pos = {

{img=Image.load("x0.png"), y=0, x=1, w=2, h=2},
{img=Image.load("x1.png"), y=2, x=1, w=2, h=1},
{img=Image.load("x2.png"), y=0, x=0, w=1, h=2},
{img=Image.load("x3.png"), y=0, x=3, w=1, h=2},
{img=Image.load("x4.png"), y=2, x=0, w=1, h=2},
{img=Image.load("x5.png"), y=2, x=3, w=1, h=2},
{img=Image.load("x6.png"), y=3, x=1, w=1, h=1},
{img=Image.load("x7.png"), y=3, x=2, w=1, h=1},
{img=Image.load("x8.png"), y=4, x=0, w=1, h=1},
{img=Image.load("x9.png"), y=4, x=3, w=1, h=1}

}

all thing work . i think i need more work on lua . ;)
Back to top
View user's profile Send private message
nevyn



Joined: 31 Jul 2005
Posts: 136
Location: Sweden

PostPosted: Tue Dec 20, 2005 8:23 pm    Post subject: Reply with quote

Brackets mean that you index, or take a value out of, an array. This is not what you were trying to do; your code had syntax errors. Just removing the brackets would've worked:
Code:
"c0" = {img=Image.load("x0.png"), y=0, x=1},
Back to top
View user's profile Send private message Send e-mail Visit poster's website
romero126



Joined: 24 Dec 2005
Posts: 200

PostPosted: Sat Dec 24, 2005 2:58 pm    Post subject: Reply with quote

Indexing is not the problem since index variables all the time.
try
Code:

Blocks_Pos = {
["c0"] = {img=Image.load("x0.png"), y=0, x=1},
["c1"] = {img=Image.load("x1.png"), y=2, x=1},
["c2"] = {img=Image.load("x2.png"), y=0, x=0},
["c3"] = {img=Image.load("x3.png"), y=0, x=3},
["c4"] = {img=Image.load("x4.png"), y=2, x=0},
["c5"] = {img=Image.load("x5.png"), y=2, x=3},
["c6"] = {img=Image.load("x6.png"), y=3, x=1},
["c7"] = {img=Image.load("x7.png"), y=3, x=2},
["c8"] = {img=Image.load("x8.png"), y=4, x=0},
["c9"] = {img=Image.load("x9.png"), y=4, x=3}

}

for key,value in Blocks_Pos do
    screen:blit(offsetx+value[x]*unit_width, offsety+value[y]*unit_height, value[img])
end


mixing variable types seems to be your issue make it simpler..

use the for key,value in var loops

remember to combine math functions with parenthesies only to tell it which to do first and which not to.. Yes this LUA does math like a normal person :-)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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