Click to See Complete Forum and Search --> : How can I call a sub and tell it to stop executing?
Dude1
Mar 29th, 2002, 01:14 PM
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!
kikelinus
Mar 29th, 2002, 03:07 PM
You can use Exit Sub....
Dude1
Mar 29th, 2002, 04:05 PM
How? Can you tell me? I tried making a boolean and saying that if it is falls then Exit Sub but nothing happens!
joey o.
Mar 29th, 2002, 04:34 PM
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.
SLH
Mar 31st, 2002, 05:20 AM
in the timer
mycount = mycount+1
If mycount = 1000 '(or whatever) Then
Timer.Enabled = False
in the explode function
Sub Explode()
If mycount = 1000 Then Exit Sub
'explosion code
End Sub
/\/\isanThr0p
Mar 31st, 2002, 01:03 PM
hm well why don't you have your explode sub do something like that
sub explode (timeToDie as long)
TimeToDie = gettickcout + TimeToDie
do
'do whatever you sub is supposed to do
loop until gettickcount > TimeToDie
end sub
joey o.
Apr 1st, 2002, 08:40 AM
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?
/\/\isanThr0p
Apr 1st, 2002, 09:56 AM
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.
/\/\isanThr0p
Apr 1st, 2002, 12:41 PM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.