hi.
Im doing a kind of adventure game
so, I have a table with all screens I wanted, this way:
map[x] = {filename = “xx.png”, north, south, left, right}
where x is a integer (aways) and north, south, etc… is a link to some another table position (north = 1 means if I press a button UP I will show map[1], ecc)
well, Im having some problem here, because I did a global variable called background, I change this variable to the current scene.
But aways crash. After 3 or 4 buttons pressed, The program crashes.
My program work like this:
function loadscreen (screen)
--background:removeSelf()
background = display.newImageRect("image/amz"..telas[screen]["filename"]..".jpg", 480, 320)
localGroup:insert( background )
background.x = \_W / 2
background.y = \_H / 2
.
.
.
-- Interface / Arrows
if type(telas[screen]["up"]) == "number" then
setas[1] = display.newImageRect("image/arrow-up.png", 61, 28)
setas[1].x = 90
setas[1].y = 243
setas[1]:addEventListener("touch", pressUp )
localGroup:insert(setas[1])
else
setas[1]:removeSelf()
setas[1]:removeEventListener("touch", pressUp )
setas[1] = nil
end
So, the button do this:
function pressLeft(event)
if event.phase == "ended" then
if setas[4].lado then
local new\_pos = setas[4].lado
posicao = new\_pos -- So para garantir que o valor é o atual
print ("Nova posicao:", new\_pos)
loadscreen(new\_pos)
end
end
end
I just the code to understand the logic, all buttons are the “same” code (only changes direction).
Any ideias how to do this? [import]uid: 9133 topic_id: 21605 reply_id: 321605[/import]
The problem WAS logic.