Problems with while loop

Hello, new to Lua and programming as a whole. Coming from GameSalad.

Can anyone tell me why this while loop is crashing the simulator?

while actor.y >= 240 do
actor.alpha = (actor.y-240)/80
end
thanks [import]uid: 8192 topic_id: 1763 reply_id: 301763[/import]

divide by 0 zero?
while actor.y > 240 and not >= [import]uid: 6873 topic_id: 1763 reply_id: 5223[/import]

@TheGiant. No that didn’t work. [import]uid: 8192 topic_id: 1763 reply_id: 5224[/import]

When the while condition is true, you are in an endless loop. It will run this loop forever when as you just ask for the position. And that will be in one frame the fact, so it will run forever in this frame. Or worse, you have that code in your main script, before the engine takes over.

CORONA is event based! First you initialize the engine and your game with your main.lua script. Once the the script is done, the engine will take over. Your lua functions are called each frame when an eventlistener is called. [import]uid: 5712 topic_id: 1763 reply_id: 5225[/import]

@MikeHart,

Thank you for the info. The only problem is that what you just said is like arab to me. I am reading the references and the getting started and all the info you said doesn’t seem to be anywhere. It seems that the approach in Corona is quite different that what I am used to. Where can i get more info that will set me on the right path.

I understand how to write the syntax and all of that. It’s the core idea that I don’t get. Gamesalad is object based. You start and object and it has variables and methods associated with it. You have global variables you use to make the objects interact with eachother and you have instances of the object.

It seem Corona is quite different. What does event base mean?

Thanks in advance. [import]uid: 8192 topic_id: 1763 reply_id: 5233[/import]

@amingoni

Take a look at the Samurai Kitchen sample code at http://developer.anscamobile.com/content/additional-samples#Samurai_Kitchen_game

It is probably a way for you to see how an event model programming is setup and what it takes to get all the pieces in place to make things animate.

Carlos [import]uid: 24 topic_id: 1763 reply_id: 5234[/import]

@amigoni,

Event-based means your program does nothing until an event occurs. That event could be a button pressed, the screen touched, an object on the screen moved by the user, or the completion of a sound or video.

The main portion of your Lua code will set up your variable, the screen and any objects needed to be displayed first. If you are creating a video player your code would set up the screen and a button the user can press to select or start a video. Your code is idle until the user presses the button (an event). Your code starts the video player and goes idle. The video ends which can generate another event where you cue up the next video or wait for another selection.

The best way to see this in action is to look through the sample code shipped with the SDK and check out the code samples on the Corona Developer’s site.

-Tom [import]uid: 7559 topic_id: 1763 reply_id: 5351[/import]

Thank you for the explanations.

I found this webpage with the pdf to really give an easy explanation of event driven programming for those that are not familiar with it.

http://eventdrivenpgm.sourceforge.net/

Now it all makes much more sense.

Thanks again. [import]uid: 8192 topic_id: 1763 reply_id: 5359[/import]

@MikeHart,

Sorry about the off topic. I am trying to implement the score list that you posted in the now closed code forum and I can’t reply there.

My score list is in reverse order meaning lowest score is best would i change the code below to show

[code] if ts.points >p then /[code]

[code]
function scoreList:CheckScore§
–****************************************************************
print ("#scoreList.list:"…#scoreList.list)
local i = 0
for i = 1,#scoreList.list,1 do
local ts = scoreList.list[i]
if ts.points < p then
return i
end
end
return 0
end
/[code]

or how else would I achieve that?

Thanks [import]uid: 8192 topic_id: 1763 reply_id: 5817[/import]