function stoping
Moderators: Shine, Insert_witty_name
-
- Posts: 31
- Joined: Sat Oct 15, 2005 10:56 am
function stoping
is there a way to stop a function with an if then statement?
Code: Select all
if something==true then
return
end
-
- Posts: 31
- Joined: Sat Oct 15, 2005 10:56 am
"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.
This is a nice pleonasm :-)LuMo wrote:Code: Select all
if something==true then
-
- Posts: 31
- Joined: Sat Oct 15, 2005 10:56 am
so would i put that in the function itself? like
Code: Select all
funtion something()
stuff = otherstuff
if pad:cross() then
return
-
- Posts: 31
- Joined: Sat Oct 15, 2005 10:56 am
Code: Select all
function fly()
bx = bx-2
wx = wx-2
if crashup() then
return end
end
Code: Select all
function fly()
bx = bx-2
wx = wx-2
if y < uplimit then
return end
end
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:
Note: the parenthesis pair is not required but for clarity's sake.
PS My late dog was named Bambi.
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()
bx = bx-2
wx = wx-2
return (y < uplimit)
end
PS My late dog was named Bambi.
Geo Massar
Retired Engineer
Retired Engineer