Results 1 to 9 of 9

Thread: How can I call a sub and tell it to stop executing?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202

    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!

  2. #2
    Addicted Member kikelinus's Avatar
    Join Date
    Nov 2000
    Posts
    219
    You can use Exit Sub....

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2001
    Location
    Great White North, ey?
    Posts
    202
    How? Can you tell me? I tried making a boolean and saying that if it is falls then Exit Sub but nothing happens!

  4. #4
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    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.

  5. #5
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    in the timer
    VB Code:
    1. mycount = mycount+1
    2. If mycount = 1000 '(or whatever) Then
    3. Timer.Enabled = False

    in the explode function

    VB Code:
    1. Sub Explode()
    2. If mycount = 1000 Then Exit Sub
    3. 'explosion code
    4. 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.


  6. #6
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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!

  7. #7
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    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?

  8. #8
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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!

  9. #9
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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
  •  



Click Here to Expand Forum to Full Width