| View previous topic :: View next topic |
| Author |
Message |
wekilledbambi03
Joined: 15 Oct 2005 Posts: 31
|
Posted: Sat Oct 15, 2005 11:44 am Post subject: function stoping |
|
|
| is there a way to stop a function with an if then statement? |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sat Oct 15, 2005 7:36 pm Post subject: |
|
|
| Code: | if something==true then
return
end
|
_________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
wekilledbambi03
Joined: 15 Oct 2005 Posts: 31
|
Posted: Sun Oct 16, 2005 10:42 am Post subject: |
|
|
| 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 |
|
| Back to top |
|
 |
chaos
Joined: 10 Apr 2005 Posts: 135
|
Posted: Sun Oct 16, 2005 1:07 pm Post subject: |
|
|
"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. |
|
| Back to top |
|
 |
Shine
Joined: 03 Dec 2004 Posts: 728 Location: Germany
|
Posted: Sun Oct 16, 2005 6:27 pm Post subject: |
|
|
| LuMo wrote: | | Code: | if something==true then
|
|
This is a nice pleonasm :-) |
|
| Back to top |
|
 |
LuMo
Joined: 21 Aug 2005 Posts: 410 Location: Austria
|
Posted: Sun Oct 16, 2005 7:50 pm Post subject: |
|
|
hehe
well maybe easier to understand than
for a beginner...
cause something may be 1+1==2 :P _________________ "Good artists copy, great artists steal."
Pablo Picasso
go2lumo.com |
|
| Back to top |
|
 |
wekilledbambi03
Joined: 15 Oct 2005 Posts: 31
|
Posted: Mon Oct 17, 2005 11:11 am Post subject: |
|
|
so would i put that in the function itself? like
| Code: | funtion something()
stuff = otherstuff
if pad:cross() then
return |
|
|
| Back to top |
|
 |
chaos
Joined: 10 Apr 2005 Posts: 135
|
Posted: Mon Oct 17, 2005 11:35 am Post subject: |
|
|
yes. _________________ Chaosmachine Studios: High Quality Homebrew. |
|
| Back to top |
|
 |
wekilledbambi03
Joined: 15 Oct 2005 Posts: 31
|
Posted: Tue Oct 18, 2005 10:07 am Post subject: |
|
|
| alright thanks ill try it |
|
| Back to top |
|
 |
wekilledbambi03
Joined: 15 Oct 2005 Posts: 31
|
Posted: Sun Oct 23, 2005 9:29 am Post subject: |
|
|
| Code: | 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: | 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. |
|
| Back to top |
|
 |
KawaGeo
Joined: 27 Aug 2005 Posts: 191 Location: Calif Mountains
|
Posted: Sun Oct 23, 2005 1:37 pm Post subject: |
|
|
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: |
function fly()
bx = bx-2
wx = wx-2
return (y < uplimit)
end
|
Note: the parenthesis pair is not required but for clarity's sake.
PS My late dog was named Bambi. _________________ Geo Massar
Retired Engineer |
|
| Back to top |
|
 |
|