function stoping

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
wekilledbambi03
Posts: 31
Joined: Sat Oct 15, 2005 10:56 am

function stoping

Post by wekilledbambi03 »

is there a way to stop a function with an if then statement?
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

Code: Select all

if something==true then
    return
end
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
wekilledbambi03
Posts: 31
Joined: Sat Oct 15, 2005 10:56 am

Post by wekilledbambi03 »

could you explain that a little more? im still pretty new to coding. im sure it makes sense you know the stuff, but im dont. hahaha
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

"return" basically kicks the program out of the function.. when the program hits that line, it exits the function immediately, and returns to the point just after where you called the function.
Chaosmachine Studios: High Quality Homebrew.
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

LuMo wrote:

Code: Select all

if something==true then
This is a nice pleonasm :-)
LuMo
Posts: 410
Joined: Sun Aug 21, 2005 2:45 am
Location: Austria
Contact:

Post by LuMo »

hehe
well maybe easier to understand than
if something then
for a beginner...
cause something may be 1+1==2 :P
"Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com
wekilledbambi03
Posts: 31
Joined: Sat Oct 15, 2005 10:56 am

Post by wekilledbambi03 »

so would i put that in the function itself? like

Code: Select all

funtion something()
stuff = otherstuff
if pad:cross() then
return
chaos
Posts: 135
Joined: Sun Apr 10, 2005 5:05 pm

Post by chaos »

yes.
Chaosmachine Studios: High Quality Homebrew.
wekilledbambi03
Posts: 31
Joined: Sat Oct 15, 2005 10:56 am

Post by wekilledbambi03 »

alright thanks ill try it
wekilledbambi03
Posts: 31
Joined: Sat Oct 15, 2005 10:56 am

Post by wekilledbambi03 »

Code: Select all

function fly()
	bx = bx-2
	wx = wx-2
	if crashup() then
	return end
end
is that right? cause it doesnt work. it just runs the function.

Code: Select all

function fly()
	bx = bx-2
	wx = wx-2
	if y < uplimit then
	return end
end
tried tat too. did nothing. by the way the bx and wx are just parts of the scrolling bg. i want it to stop scrolling when something happens.
KawaGeo
Posts: 191
Joined: Sat Aug 27, 2005 6:52 am
Location: Calif Mountains

Post by KawaGeo »

wekilledbambi03 (what a long username.:)

The if-then statement in your last code is not affected at all. The function will return to the same caller, no matter what the result of the logical expression is. I'd suggest to return either true or false, something like this:

Code: Select all

function fly&#40;&#41;
   bx = bx-2
   wx = wx-2
   return &#40;y < uplimit&#41;
end
Note: the parenthesis pair is not required but for clarity's sake.

PS My late dog was named Bambi.
Geo Massar
Retired Engineer
Post Reply