In my program i get error Syntax error: c:…\mail.lua:73: 'how to fix it? [import]uid: 189039 topic_id: 32285 reply_id: 332285[/import]
Show us all the code in that snippet, and we can help you.
Joakim [import]uid: 81188 topic_id: 32285 reply_id: 128411[/import]
im trying to make that if balls collide it adds +1 to score
[code]
function ballsCallide
if ball.y => ball2.y and ball.y =< ball2.y
and
if ball.x => ball2.x and ball.x =< ball2.x
score = score + 1
myText.text = score
end
[import]uid: 189039 topic_id: 32285 reply_id: 128413[/import]
I am not sure what you are trying to do within your function, and there where errors in plenty places. Your statements looks weird and I don’t understand the logic of your (if then) statement.
This is a sample of the function that works, but I am not sure if it does the stuff you want it to do…
function ballsCallide()
if (ball.y \>=ball2.y and ball.y \<= ball2.y) then
--Do stuff
elseif (ball.x \>= ball2.x and ball.x \<= ball2.x ) then
--Do stuff
end
end
You should use some other routines for collisions, since this will be a nightmare to optimize. There are plenty of tutorials out here and you should look into those, to speed up your learning curve!
Keep it up!
Joakim [import]uid: 81188 topic_id: 32285 reply_id: 128416[/import]
Just a quick note… neither of these conditions will likely happen, unless the X or Y value of the two balls is exactly equal (and I’m talking about at the decimal level like 10 decimal points out!). ball.x can’t be both > than AND < than ball2.x at the same time.
On syntax, it should be \<= or \>=, not =, as Joakim properly noted.
Again, there’s the outside but virtually impossible chance the values will be equal at some point. I suspect you want to use the OR operator, not the AND operator, true?
Brent
[import]uid: 9747 topic_id: 32285 reply_id: 128427[/import]
I suggest that you look into “sprites” and “collision” handling - that would be a much better approach.
Joakim [import]uid: 81188 topic_id: 32285 reply_id: 128439[/import]
I searched for sprites and collision handling and this is what i came up with, but it seems something is still wrong with this code or something seems to be missing
[code]
local function postCollisionCallbackBetweenballandball2(event)
print("Sprite " … event.object1.ball … " has collided with " … event.object2.ball2)
end
loader:useLevelHelperCollisionHandling()
loader:registerPostColisionCallbackBetweenTags(ball,ball2, postCollisionCallbackBetweenballandball2 )
[import]uid: 189039 topic_id: 32285 reply_id: 128479[/import]
Show us all the code in that snippet, and we can help you.
Joakim [import]uid: 81188 topic_id: 32285 reply_id: 128411[/import]
im trying to make that if balls collide it adds +1 to score
[code]
function ballsCallide
if ball.y => ball2.y and ball.y =< ball2.y
and
if ball.x => ball2.x and ball.x =< ball2.x
score = score + 1
myText.text = score
end
[import]uid: 189039 topic_id: 32285 reply_id: 128413[/import]
I am not sure what you are trying to do within your function, and there where errors in plenty places. Your statements looks weird and I don’t understand the logic of your (if then) statement.
This is a sample of the function that works, but I am not sure if it does the stuff you want it to do…
function ballsCallide()
if (ball.y \>=ball2.y and ball.y \<= ball2.y) then
--Do stuff
elseif (ball.x \>= ball2.x and ball.x \<= ball2.x ) then
--Do stuff
end
end
You should use some other routines for collisions, since this will be a nightmare to optimize. There are plenty of tutorials out here and you should look into those, to speed up your learning curve!
Keep it up!
Joakim [import]uid: 81188 topic_id: 32285 reply_id: 128416[/import]
Just a quick note… neither of these conditions will likely happen, unless the X or Y value of the two balls is exactly equal (and I’m talking about at the decimal level like 10 decimal points out!). ball.x can’t be both > than AND < than ball2.x at the same time.
On syntax, it should be \<= or \>=, not =, as Joakim properly noted.
Again, there’s the outside but virtually impossible chance the values will be equal at some point. I suspect you want to use the OR operator, not the AND operator, true?
Brent
[import]uid: 9747 topic_id: 32285 reply_id: 128427[/import]
I suggest that you look into “sprites” and “collision” handling - that would be a much better approach.
Joakim [import]uid: 81188 topic_id: 32285 reply_id: 128439[/import]
That code is using a thirdparty library that comes with a tool called Level Helper. You cant get that to work without the tools. Read through the docs here on this website, and look at the tutorials - that will help you more.
This is a perfect start to learn the basic with Corona and Lua.
http://developer.coronalabs.com/content/getting-started-corona-game-edition
here you can find a lot of tutorials
and don’t forget the documentation for Corona. Even if I have been coding Corona for 1.5 year, I visit this place several of times every day.
http://docs.coronalabs.com/api/
Joakim [import]uid: 81188 topic_id: 32285 reply_id: 128558[/import]
I searched for sprites and collision handling and this is what i came up with, but it seems something is still wrong with this code or something seems to be missing
[code]
local function postCollisionCallbackBetweenballandball2(event)
print("Sprite " … event.object1.ball … " has collided with " … event.object2.ball2)
end
loader:useLevelHelperCollisionHandling()
loader:registerPostColisionCallbackBetweenTags(ball,ball2, postCollisionCallbackBetweenballandball2 )
[import]uid: 189039 topic_id: 32285 reply_id: 128479[/import]
thanks, I just started learning… [import]uid: 189039 topic_id: 32285 reply_id: 128602[/import]
That code is using a thirdparty library that comes with a tool called Level Helper. You cant get that to work without the tools. Read through the docs here on this website, and look at the tutorials - that will help you more.
This is a perfect start to learn the basic with Corona and Lua.
http://developer.coronalabs.com/content/getting-started-corona-game-edition
here you can find a lot of tutorials
and don’t forget the documentation for Corona. Even if I have been coding Corona for 1.5 year, I visit this place several of times every day.
http://docs.coronalabs.com/api/
Joakim [import]uid: 81188 topic_id: 32285 reply_id: 128558[/import]
thanks, I just started learning… [import]uid: 189039 topic_id: 32285 reply_id: 128602[/import]