How do i make a loop for objects

I need a help with a code please, i am working on a game currently and in the game the player is will try to avoid falling cars from the top from each lane. I currently have a code which will do that but its not working the way i want it to

Function move (event)
If event.phase ==‘began’ then
Local car =display.newImageRect(“hjkuh.png”,59,100)
Car.x = display.containCenterX
Car.y = display.containCenterY
end
End
Runtime:addEventListener(“touch”,move)

Would appreciate the help

I’m not sure if you are trolling, or just completely new to programming in general. :smiley:

In any case, I would recommend that you have a look these two pages to get started:

https://coronalabs.com/learn

https://docs.coronalabs.com/guide/

As for your code, it isn’t clear what you want to do. The people around here want to help, but they do so on their spare time, so making it as easy as possible for them to help you makes them more likely to help you. For instance, you say that “the player has to avoid falling cars from the top of each lane”, but your code doesn’t reflect anything of the sorts. You also don’t explain where and how you plan to have those lanes, what they are supposed to be exactly and how you want the cars to fall, etc.

Your code, as it stands now, has several errors in it that will crash your app, such as:

  • “Function” instead of “function”, using capital F doesn’t create a function, it’ll just crash.

  • “Local” instead of “local”, same as before, using capital L doesn’t create a local variable, it’ll just crash.

  • You are trying to create “car” variable, but then you are moving “Car”. Lua is CaSe SeNsItIvE and those are two different variables.

  • You have misspelled “content” as “contain”.

  • The usual “End” instead of “end” issue.

  • IF this function worked, i.e. you fixed all those errors, then all you’d do is create an imageRect in the centre of the screen. The car variable’s reference would also be lost due to it being local within the function (read about scope).

  • No indentation (this won’t cause the code to crash, but just makes it harder to read).

So, I recommend that you familiarise yourself with the basics regarding Corona and Lua first because I am getting the impression that you don’t really have a clue about programming yet, and that’s ok, we all had to start at some point in our lives.

Happy coding and learning!

Indeed, if you fixed all the syntax errors, your code would just create a new car every time the player touched the screen. That car would not do anything, would not fall as you want, because you haven’t added any physics or manual code to move it.

But first, as XeduR says, read the two links provided as well as looking at all the tutorials and samples you can get your hands on (google is your friend), so you have a much bigger chance to bring your game idea to life without fumbling around in the dark.

I’m not sure if you are trolling, or just completely new to programming in general. :smiley:

In any case, I would recommend that you have a look these two pages to get started:

https://coronalabs.com/learn

https://docs.coronalabs.com/guide/

As for your code, it isn’t clear what you want to do. The people around here want to help, but they do so on their spare time, so making it as easy as possible for them to help you makes them more likely to help you. For instance, you say that “the player has to avoid falling cars from the top of each lane”, but your code doesn’t reflect anything of the sorts. You also don’t explain where and how you plan to have those lanes, what they are supposed to be exactly and how you want the cars to fall, etc.

Your code, as it stands now, has several errors in it that will crash your app, such as:

  • “Function” instead of “function”, using capital F doesn’t create a function, it’ll just crash.

  • “Local” instead of “local”, same as before, using capital L doesn’t create a local variable, it’ll just crash.

  • You are trying to create “car” variable, but then you are moving “Car”. Lua is CaSe SeNsItIvE and those are two different variables.

  • You have misspelled “content” as “contain”.

  • The usual “End” instead of “end” issue.

  • IF this function worked, i.e. you fixed all those errors, then all you’d do is create an imageRect in the centre of the screen. The car variable’s reference would also be lost due to it being local within the function (read about scope).

  • No indentation (this won’t cause the code to crash, but just makes it harder to read).

So, I recommend that you familiarise yourself with the basics regarding Corona and Lua first because I am getting the impression that you don’t really have a clue about programming yet, and that’s ok, we all had to start at some point in our lives.

Happy coding and learning!

Indeed, if you fixed all the syntax errors, your code would just create a new car every time the player touched the screen. That car would not do anything, would not fall as you want, because you haven’t added any physics or manual code to move it.

But first, as XeduR says, read the two links provided as well as looking at all the tutorials and samples you can get your hands on (google is your friend), so you have a much bigger chance to bring your game idea to life without fumbling around in the dark.