Page 1 of 2

Pause Button

Posted: Fri Mar 04, 2011 5:49 am
by Danny
Hello all,
I'm trying to figure out how to pause my game with out throwing off the timer. The timer is this, when you press play, a timer starts and when it runs out it ends the game. Also when I've tried to pause the game and then all the apples start to fall in one big bunch of 5 or 6 or however many apples are still up there. I'm not sure how to pause either of these which is why i'm coming to you guys.

This is the script i've been using to drop the apples. I wasn't sure if this would help.

Code: Select all

on dropTheBalls
   local tTimeSpan, tBallID, tBallNum, tTempBallList
   put fld "fDropRate" into tTimeSpan
   put gBallList into tTempBallList
   repeat the number of items in gBallList times
      put random(the number of items in tTempBallList) into tBallNum
      put item tBallNum of tTempBallList into tBallID
      send "dropMe" to tBallID in tTimeSpan seconds 
      delete item tBallNum of tTempBallList
      add fld "fDropRate" to tTimeSpan
   end repeat
end dropTheBalls
Thanks,

Danny

Re: Pause Button

Posted: Thu Mar 17, 2011 4:51 pm
by Danny
Does anyone have any ideas?

Re: Pause Button

Posted: Thu Mar 17, 2011 5:25 pm
by Klaus
Hi Danny,

we need more info e.g. the script with the timer!
The script above does not have any timer in it.


Best

Klaus

Re: Pause Button

Posted: Thu Mar 17, 2011 5:30 pm
by Danny
Not a problem. Would this be enough? This is all the code I have for the apples...

Code: Select all

global gBallList


on openCard
   hide group "test"
    set the moveSpeed to fld "fDropSpeed"
   send dropTheBalls to me in 1 milliseconds
   send timerPlayed to me in 10800 milliseconds
   gameReset
   initializeBalls
   movePig
end openCard

on gameReset
   initializeBalls
   movePig
   hide group "test"
      put 0 into fld "fBallsCaught"
      put 0 into fld "fBallsDropped"
end gameReset

on timerPlayed
   set the layer of group "test" to 8
   show group "test"
   set the layer of img "Pig" to bottom
   end timerPlayed

on movePig
   set the layer of img "Pig" to 4
end movePig

on initializeBalls
   local tBallCounter, tBallID, tStartHeight, tStartRight, tLoc
   lock screen
  
   -- delete any old balls
   if the number of items in gBallList > 0 then
      repeat for each item tBallID in gBallList
         try
            delete tBallID
            end try
      end repeat
   end if
   put empty into gBallList
   
   -- create the new balls
   put item 2 of the loc of grc "grcStartField" into tLoc
   repeat with tBallCounter = 1 to fld "fNumBalls"
      clone img "BallTemplate"
      put it into tBallID
      put tBallID & comma after gBallList
      set the width of tBallID to fld "fBallSize"
      set the height of tBallID to fld "fBallSize"
    put random(220) + 10 & comma & random(200) + 20 into tLoc
    set the loc of img "BallTemplate" to tLoc
    
   end repeat
   delete the last char of gBallList
   
   unlock screen
end initializeBalls

on dropTheBalls
   local tTimeSpan, tBallID, tBallNum, tTempBallList
   put fld "fDropRate" into tTimeSpan
   put gBallList into tTempBallList
   repeat the number of items in gBallList times
      put random(the number of items in tTempBallList) into tBallNum
      put item tBallNum of tTempBallList into tBallID
      send "dropMe" to tBallID in tTimeSpan seconds 
      delete item tBallNum of tTempBallList
      add fld "fDropRate" to tTimeSpan
   end repeat
end dropTheBalls
Thanks,

Danny

P.S Let me know if you see anything I can optimize

Re: Pause Button

Posted: Thu Mar 17, 2011 5:55 pm
by Klaus
Hu Danny,

since you start the timer immediately, this needs a complete rethinking
of the concept to let the user "pause" the action.

I will have to think about it a bit longer :)


Best

Klaus

Re: Pause Button

Posted: Mon Mar 21, 2011 2:34 am
by Danny
Yeah, take your time. Let me know if you have any ideas and thanks for taking the time to think about it

Re: Pause Button

Posted: Mon Mar 21, 2011 11:51 am
by BvG
Why don't you make two timers. One that counts the time, and another one that does the animation stuff. Then you can stop the animation and the time can go on.

Re: Pause Button

Posted: Tue Mar 22, 2011 12:40 am
by Danny
How exactly do you pause a timer? Also when I quit the app and I come back there are items on the screen that were moving and are now frozen like they are part of the background and I don't know how to delete them.

Thanks,

Danny

Re: Pause Button

Posted: Tue Mar 22, 2011 1:09 am
by BvG
you can't pause a timer, but you can choose not to send it, the send in time command is the only way to have reoccuring code happen, outside of user actions, without completely blocking LiveCode apps (well there's some other cases like libURL calls, but that's beyond this discussion).

As for your app behaving strangely, there is really only one person who can fix that (hint, you see that person in a mirror).

Re: Pause Button

Posted: Tue Mar 22, 2011 1:43 am
by Danny
Well I'll take a look into the don't send timer idea.

That guy in the mirror looked strangely like me :shock: :lol: If that's the case, I guess it's time to start brainstorming some code to get this to work.
By the way did you know that you can get an app to multitask if you deselect "Exit on Suspend." Just a cool fact if you ever wanted to know.

Thanks,

Danny

Re: Pause Button

Posted: Tue Mar 22, 2011 2:34 am
by BvG
deselecting "exit on suspend" has nothing to do with multitasking. I Don't think it's even a Livecode feature, maybe a Windows thing?

Re: Pause Button

Posted: Tue Mar 22, 2011 5:31 am
by Danny
If you go into file->standalone settings->iOS it would be on the right. Also I'm running a Mac. I think it is irrelevant because you were right, when I tried switching a bunch of apps then returned to mine it just showed a black screen. I wonder why it's there..? I hope they add that feature soon!

Re: Pause Button

Posted: Tue Mar 22, 2011 10:13 am
by bn
Hi Danny,
If you go into file->standalone settings->iOS it would be on the right. Also I'm running a Mac. I think it is irrelevant because you were right, when I tried switching a bunch of apps then returned to mine it just showed a black screen. I wonder why it's there..? I hope they add that feature soon!
it is not implemented as yet. One guy had his app rejected in the app store because of the black screen when returning to the app. Don't use it.

kind regards

Bernd

Re: Pause Button

Posted: Tue Mar 22, 2011 2:34 pm
by Danny
Hey Bernd,
After I saw that it left a black screen I immediately knew I wasn't going to use it but if the guy got his app rejected for that then I'm for sure not going to use it. I still wonder why it's there in the first place. Thanks for letting me know!

Thanks,

Danny

Re: Pause Button

Posted: Tue Mar 22, 2011 4:27 pm
by BvG
Ah on iOS you can set this so your app resumes as left despite leaving it. that is not multitasking within your app, but running several apps within the os. And still, it's just keeping the app from quitting and keeping it in the background (but suspended). That is funnily exactly how applications behaved on mac os 7, it was called multifinder back then.