|
-
Mar 29th, 2002, 02:14 PM
#1
Thread Starter
Addicted Member
How can I call a sub and tell it to stop executing?
Hi, I have a little problem.
I have a main loop something like:
Do
'code here
if Collision then Explode
Do Events
Loop
--------------------------------------------
Sub Explode()
'explosion code
End sub
So I have a loop that checks for collisions in my game and if there are any, it calls the Explode sub. Now my question is, how do I stop the Explode sub from executing after a certain amount of time. The timing itself is not the problem, I can use timer interval, but how do I STOP the explode sub?
Thanks a lot!
-
Mar 29th, 2002, 04:07 PM
#2
Addicted Member
-
Mar 29th, 2002, 05:05 PM
#3
Thread Starter
Addicted Member
How? Can you tell me? I tried making a boolean and saying that if it is falls then Exit Sub but nothing happens!
-
Mar 29th, 2002, 05:34 PM
#4
Hyperactive Member
I hope you get a better answer than this, but in the mean time try putting in a few more DOEVENTS (up to 10) and see if that helps. it's gonna slow you down for sure though.
-
Mar 31st, 2002, 06:20 AM
#5
Not NoteMe
in the timer
VB Code:
mycount = mycount+1
If mycount = 1000 '(or whatever) Then
Timer.Enabled = False
in the explode function
VB Code:
Sub Explode()
If mycount = 1000 Then Exit Sub
'explosion code
End Sub
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Mar 31st, 2002, 02:03 PM
#6
Frenzied Member
hm well why don't you have your explode sub do something like that
Code:
sub explode (timeToDie as long)
TimeToDie = gettickcout + TimeToDie
do
'do whatever you sub is supposed to do
loop until gettickcount > TimeToDie
end sub
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 1st, 2002, 09:40 AM
#7
Hyperactive Member
but what if he passes 100000? How does he get out of it if he wants to abort the explosion? At that point he's in the loop. How can timetodie be interactive?
-
Apr 1st, 2002, 10:56 AM
#8
Frenzied Member
well in case it needs to be interactive he could use a global var and set it to 0, so the loop would terminate.
but from his question I couldn't see he wanted interactivity, I know there have to be better ways than using a global variable. I will post one when I get home.
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 1st, 2002, 01:41 PM
#9
Frenzied Member
you could set up a boolean in your main loop
if bolExplo then Exlplode
in that case you would have to change your exlpode sub though that is has no loop of its own, because it is already looped in the mainloop.
Now you could change bolExplo everywhere in your mainloop.
another way to do it would be to set up the explode thing as a class. than you could have a boolean value as property of the object (created from that class) and the explode code as a method in which it checks the property.
Sanity is a full time job
Puh das war harter Stoff!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|