Problem With my Code

Ok, thank you, but how can I change this code to work? Thank you everyone so much for your help so far!

Well this looks like code that you want to continually check for a certain set of conditions and then do something when met, so you can put this in an enterFrame listener too.

In the nicest possible way you are trying to run before you can walk… you need to work through the tutorials and guides I linked for you so you understand.

Thank you man, don’t worry haha, I’m not someone who gets offended very often haha. It’s just that my college course is very fast and we are trying to make our own apps at the moment.

It’s working now! Thank you all so much!!

as you’ll probably want to move objects take a look at this as it covers the basics…  https://coronalabs.com/blog/2015/08/25/tutorial-animation-with-enterframe-listeners/

Thank you so much man. All of my code works now but there’s just one more question. How do I change the icon for apk’s. It doesn’t matter too much but I just want the app to look great.

Don’t worry, I’ve sorted it out lol. Have a great rest of your day!

Where have you put this code? It will need to be in an enterFrame listener that runs every frame, or a timer that runs every x milliseconds.

Your code checks .x with .height and .y with width.
Try checking .x with .width and .y with .height instead

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

Whether it’s portrait or landscape, width relates to the x axis and height the y axis.

For example, on iPad1, reported height is 1024 and width 768 in portrait, and in landscape height is 768 and width 1024.

You didn’t answer where this code is called btw.

 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

Where have you put this code - a timer, a listener, a button?

Hey Nick… I thought you’d left for “greener pastures”?

Yeah I don’t work with Corona anymore but still dip into the forums, a bit like seeing what an ex is up to on Facebook…

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

[/lua]

lol… so what are you doing now mate?

Thank you so much man for writing this code! It’s helped so much and it’s working great now. Thank you!!

Also, in python you can do import time and time.sleep(1). How do you implement time in lua?