I am currently making a game which is written in lua, I want it to change the background image when the player goes in a certain place. I have written this code but it will not work.
if ((player.x <= display.contentHeight / 3.8) and (player.x >= display.contentHeight / 3.5) and (player.y >= display.contentWidth / 100)) then
print(“entered town 1”)
end
Is there anything else that I could to do fix this problem?
Hey, thanks for the responce but it is landscape which is why i’ve done that. I’ve used a little cross to figure out which figures I should use for location. Thank you though
Ive only just started using lua tbh. I know a lot of python so I have knowledge of some things in lua. I’m really bad at the event listener stuff haha. In Python the if statement is all you need lol. What would I need to add to call this? Thanks
The point is unless you put the code in some sort of listener or function that is called regularly, it will only execute once, and your player is unlikely to be in the right place.
[lua]
local gameLoop = function()
// we want code in here to run once a frame
end
Runtime:addEventListener(“enterFrame”, gameLoop) // this is how we make it happen
Maybe I wrote the question wrong. I meant that whenever I add this code to corona, and I then go to start up corona simulator, instead of starting up my app, it is not responding and crashes.
You are blocking the main thread with never-ending code, so your app will appear to not be responding. It never has a chance to update the screen or do anything else, so the os assumes it is not responding.