More on recursion...

Shari gypsyware at earthlink.net
Thu Aug 29 15:22:01 EDT 2002


>If a handler calls another which calls another which
>calls the first, is this considered a handler calling
>itself?
>
>--- Mike replies:
>
>Shari, I'd recommend that you rewrite your code to
>avoid recursion completely. In the long run you will
>save yourself much time and effort. As for your
>example, let's assume that btns A,B, and C hold
>scripts that call each other in the manner that you
>describe (I'm just using btns instead of handlers). A
>better way is to have another btn D that controls the
>three btns. In btn D put the script:
>
>on mouseUp
>   repeat 100 -- as many times as you need
>   send mouseUp to btn "A"
>   send mouseUp to btn "B"
>   send mouseUp to btn "C"
>   end repeat
>end mouseUp
>
>In your other posts you mentioned something like
>"handlers calling each other." This should also be
>avoided.

Not doable to have all handlers called in order as described.  Not 
all handlers run each time.  So the game starts with the handler that 
will always start the hand (in a card game).  The game analyzes a set 
of factors to decide what to do next.  It will then call the 
appropriate handler.  This behavior repeats itself, each handler 
analyzing the current state of things, and then deciding what should 
happen next.  It will then call the appropriate handler.  At some 
point, the hand ends, the cards are collected, and the first handler 
is called to start the next hand.  This does not happen in the same 
place each time.  A hand can end at different times depending on the 
state of things.

I've set this game up specifically so that it can play all by itself. 
For my purposes, this is high desireable, and a very important factor 
in the game.

So the recursion issue is an important one.  I've made a few changes 
in the coding, such as adding "in 1 millisecond" to the appropriate 
"send" commands.  I think this fixed it.  I'm testing that now and 
have not encountered a recursion error yet.

Question:  If a handler calls itself with the "send" command, is this 
considered recursion?

on playGame
    # do this and that
    send playGame to me in 1 millisecond
end playGame
-- 
--Shareware Games for the Mac--
http://www.gypsyware.com



More information about the metacard mailing list