Page 2 of 2

Re: Hypercard books

Posted: Sun Dec 01, 2013 11:19 pm
by SparkOut
Repeat control structures also have other ways to exit according to what criteria you set.

For instance, you can begin with

Repeat 3 times

Or
Repeat until tStop is true

Or various other options.
If you are using a "send in" time loop you need to check a value which you set according to events that happen, and only do the "send" if it meets the conditions.

Re: Hypercard books

Posted: Mon Dec 02, 2013 4:35 pm
by chris25
Hallo Sparkout, thankyou for your tips. Repeat (times) and exit repeat have no effect. Problem is that on the sprite demonstration which I thoroughly studied, He only relays to you one example without flexibility. It's just a demo with the code that has the sprite repeating itself ad finitum, simple enough. But I want to stop the darn thing! Repeat until tVariable is true means I have to define the variable as: ""when 7th image appears, go to last image and then move automatically down"".This move automatically is not a problem to fit in, but the first half is killing me. Anyway This would be the 'False' state; But, tVariable (since it only needs to be a temporary Var for one handler) has to become 'true' at the last second - I have absolutely no wisdom here. I actually was trying to understand the send in time a few days ago, but lack of further instruction here means I am lost on this.Will have to keep going until something clicks on this one in a few months perhaps.

All in all I just thought I would post one last question. Thought perhaps there might be hope yet.
Kind regards
Chris

Re: Hypercard books

Posted: Mon Dec 02, 2013 4:40 pm
by Mark
Chris,

Can you post the code that keeps repeating the action or can you post a link to the demo?

Kind regards,

Mark

Re: Hypercard books

Posted: Mon Dec 02, 2013 5:13 pm
by chris25
Hallo Mark, I'm sure people are getting fed up with me on this, it's just when I have my teeth into something it's hard to let go..well this is the code, I could post the whole stack as is? That would give you context?
Kind regards
chris

Code: Select all

on collisions
   if intersect (btn "subExplode" , img "mine1") then --add 8 mines to this??
      if 6 > gSubInterval then
         add 1 to gSubInterval  --determines speed of sequence of image change below
      else
         put 2 into gSubInterval  --determines speed of same as above but why???
         if gSubExplode is 7 then
            put 1 into gSubExplode
         else
            add 1 to gSubExplode
         end if
         --lock screen
         set the icon of btn "SubExplode" to the id of img ("blacksub" & gSubexplode & ".png" ) 7 IMAGES INVOLVED HERE
         --unlock screen
      end if
   end if
   --answer "oops"
   --exit to top
   --  ?? No Good - if intersect ( btn "SubExplode" , img "mine1" ) then
   --      repeat with i = 1 to 7
   --           set the icon of button "SubExplode" to ("BlackSub_" & i & "_.png")
   --      end repeat
   --   end if
end collisions

Re: Hypercard books

Posted: Mon Dec 02, 2013 9:00 pm
by SparkOut
I answered something to do with this on the other thread.
Your collision detection handler is called every iteration of the main loop. If the intersect of the sub with the mine is true, then you start the explosion routine. But the main loop continues, and continues to call the collision detection routine, where - yes, the sub and mine still intersect, so the explosion loop happens again.
When you detect the collision you need to do something like, ahem, set a flag, to say "the sub has already collided". In the main loop, you need to call the collision detection routine ONLY if the "subHasAlreadyCollided" variable (ie flag) has not been set to true. If it doesn't call the collision detection handler because it knows it doesn't need to, you can just get on with the graceful death scene.