Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

How do i make a loop for objects
Started by ugsomiks13 Nov 22 2018 03:00 AM

2 replies to this topic
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 1 posts
  • Corona SDK

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

Would appreciate the help

[TOPIC: post.html]

XeduR @Spyric

[GLOBAL: userInfoPane.html]
XeduR @Spyric
  • Contributor

  • 368 posts
  • Corona SDK

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

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





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!

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Corona Geek

  • 1,637 posts
  • Corona SDK

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.