Countdown Clock

TheTTheT Member Posts: 80
edited November -1 in Working with GS (Mac)
Hey,
I wonder if it is possible to have a countdown clock like 1:20:59 (minutes:seconds:milliseconds) that can be displayed on screen. I know how to make it display on the scren, however I have issues with the math of it. I was looking through the forum first and found this post: http://gamesalad.com/forums/topic.php?id=576#post-3100
but it was no good for me, because the code snippit from codemonkey seems to crash the entire GS on play. Hope I can get some help on this. Also is there a symbol for "attaching" variables together for the display text thing, like "1"&:&"20"&:&"59" ("" variable, : -> text, attach char: &)
Thanks!

Comments

  • TheTTheT Member Posts: 80
    No Mastermind Coder in here ? =P
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Inconceivable!

    1) Did you make sure you double check what you copied there?
    2) Are you pulling attributes from the expression editor when it has something like self.myTime?
    3) Are you using the expression editor?
    4) the '..' is what is used for concatenation.
  • TheTTheT Member Posts: 80
    1) yeah, checked it.
    2) Not sure what you mean by that, but I have tried the same exact code with self.timer and with another global variable CountDown, didn't work
    3) Yes, I used the editor
    4) I noticed already another time that when I used the .., the game just crashes (just tried it again, did the same thing)
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    See http://gamesalad.com/game/play/26566
    Also should be near the top of the shared games.
  • urhungryurhungry Member Posts: 112
    Did you copy the code or retype it? Copying had caused errors in other reports.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    I copied it, but needed to replace the text showing the attributes with actual attributes selected from the expression editor. And remove any spaces around them.
  • TheTTheT Member Posts: 80
    Alright, thanks a lot for the detailed example ! Really appreciate it !
    Don't know why it didn't work before with the other code, but well, thanks :)
  • TheTTheT Member Posts: 80
    One more question, how can I do it that the last 2 digits show milliseconds instead of seconds ? I tried some tweaking by myself with the %10 (guess that's the format ?) and /60 /3600 but after I crashed the app about 2 times, I figured out it may be better just to ask you ..? ;)
  • TheTTheT Member Posts: 80
    Codemonkey, or anyone else who happens to know the solution, could you please help me on this one issue so I can get this part completed ?
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    I try not to display milliseconds because each change in the time requires a redraw of the text and that takes up some of your precious resources.
    Tenths of a second isn't too bad. Just add this at the end of the seconds.

    ..(floor( game.Time *10))%10
  • TheTTheT Member Posts: 80
    Thanks for the equation, had to rewrite it a bit for the countdown.
    Here is my chunk of code if someone once needs a countdown timer with /10 seconds:
    ..floor( game.CountDown - game.Time *10)%10

    Hey, codemonkey, how's about /100 seconds, would that also eat much resources ?
    Maybe, like this: ..floor( game.CountDown - game.Time *100)%10
    (% is for how many places are displayed isn't it ?)
    Maybe we should make a wiki out of this post ;)
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    is game.CountDown already multiplied by 10? If not you may need parentheses around it and game.Time.

    100th of a second after the 10th of a second function started crashing for me. Its just a lot of redrawing. so I would not recommend it.
  • TheTTheT Member Posts: 80
    Yeah, nevermind, I figured it out.
    It didn't really look good with the /100, but the /10 is great ! Anyways, Thanks a lot for your help :)

    PS: CountDown already is in seconds, so it works
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Heh. What was I thinking? :p
Sign In or Register to comment.