Countdown Timer Code

HegemonKhan
here's my countdown timer code (I'm sure it can be done much simplier and easier, especially via the use of the "% = ~modulus operator"), but this took me forever to get it to finally work (I hope it works fully ~ from 60:00:00 to 00:00:00), as this was a big challenge for me.

bloody and flaming ashes!, took me forever to realize that I needed the quotes before the Object.Attribute in the Timer:

game.count_down_timer_string = "" + Object.Attribute ...etc

by not having the quotes in front, the underlying code chops off the leftmost zero, and this causes my countdown coding to not work. BLEEPING BLEEPING BLEEPING... I thought the rest of my code had an error somewhere in it, or that the "math mechanic sequence" of mine was faulty... ARGHHHHHHH !!!!

(if you wanna see the bleeping bleeping craziness, take out those quotes, and plug in values for the "tens hours" attribute !)

<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>d67ec73f-f879-4911-9d88-c02ea527c534</gameid>
<version>1.0</version>
<firstpublished>2014</firstpublished>
<attr name="statusattributes" type="simplestringdictionary">count_down_clock_string = Countdown: !</attr>
<attr name="count_down_clock_string" type="string">60:00:00</attr>
<attr name="changedcount_down_clock_string" type="script">
ClearScreen
msg ("Countdown: " + game.count_down_clock_string)
</attr>
<attr name="count_down_clock_ones_second_integer" type="int">0</attr>
<attr name="count_down_clock_tens_second_integer" type="int">0</attr>
<attr name="count_down_clock_ones_minute_integer" type="int">0</attr>
<attr name="count_down_clock_tens_minute_integer" type="int">0</attr>
<attr name="count_down_clock_ones_hour_integer" type="int">0</attr>
<attr name="count_down_clock_tens_hour_integer" type="int">6</attr>
<attr name="changedcount_down_clock_ones_second_integer" type="script">
if (game.count_down_clock_ones_second_integer = 9) {
if (game.count_down_clock_tens_second_integer = 0) {
game.count_down_clock_tens_second_integer = game.count_down_clock_tens_second_integer + 5
}
else if (not game.count_down_clock_tens_second_integer = 0) {
game.count_down_clock_tens_second_integer = game.count_down_clock_tens_second_integer - 1
}
}
</attr>
<attr name="changedcount_down_clock_tens_second_integer" type="script">
if (game.count_down_clock_tens_second_integer = 5) {
if (game.count_down_clock_ones_minute_integer = 0) {
game.count_down_clock_ones_minute_integer = game.count_down_clock_ones_minute_integer + 9
}
else if (not game.count_down_clock_ones_minute_integer = 0) {
game.count_down_clock_ones_minute_integer = game.count_down_clock_ones_minute_integer - 1
}
}
</attr>
<attr name="changedcount_down_clock_ones_minute_integer" type="script">
if (game.count_down_clock_ones_minute_integer = 9) {
if (game.count_down_clock_tens_minute_integer = 0) {
game.count_down_clock_tens_minute_integer = game.count_down_clock_tens_minute_integer + 5
}
else if (not game.count_down_clock_tens_minute_integer = 0) {
game.count_down_clock_tens_minute_integer = game.count_down_clock_tens_minute_integer - 1
}
}
</attr>
<attr name="changedcount_down_clock_tens_minute_integer" type="script">
if (game.count_down_clock_tens_minute_integer = 5) {
if (game.count_down_clock_ones_hour_integer = 0) {
game.count_down_clock_ones_hour_integer = game.count_down_clock_ones_hour_integer + 9
}
else if (not game.count_down_clock_ones_hour_integer = 0) {
game.count_down_clock_ones_hour_integer = game.count_down_clock_ones_hour_integer - 1
}
}
</attr>
<attr name="changedcount_down_clock_ones_hour_integer" type="script">
if (game.count_down_clock_ones_hour_integer = 9) {
game.count_down_clock_tens_hour_integer = game.count_down_clock_tens_hour_integer - 1
}
</attr>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
<timer name="count_down_clock_timer">
<enabled />
<interval>1</interval>
<script>
SetTimeout (1) {
if (game.count_down_clock_tens_hour_integer = 0 and game.count_down_clock_ones_hour_integer = 0 and game.count_down_clock_tens_minute_integer = 0 and game.count_down_clock_ones_minute_integer = 0 and game.count_down_clock_tens_second_integer = 0 and game.count_down_clock_ones_second_integer = 0) {
DisableTimer (count_down_clock_timer)
}
else if (game.count_down_clock_ones_second_integer = 0) {
game.count_down_clock_ones_second_integer = game.count_down_clock_ones_second_integer + 9
}
else if (not game.count_down_clock_ones_second_integer = 0) {
game.count_down_clock_ones_second_integer = game.count_down_clock_ones_second_integer - 1
}
}
game.count_down_clock_string = "" + game.count_down_clock_tens_hour_integer + game.count_down_clock_ones_hour_integer + ":" + game.count_down_clock_tens_minute_integer + game.count_down_clock_ones_minute_integer + ":" + game.count_down_clock_tens_second_integer + game.count_down_clock_ones_second_integer
</script>
</timer>
</asl>

jaynabonne
That's a rather novel use of change scripts. Kudos. :)

Just for fun (and contrast), here's a "mod" version. I extended it to include days as well, just so you can see the full pattern.

Enjoy! lol

<!--Saved by Quest 5.4.4873.16527-->
<asl version="540">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="Testing Game Stuff">
<gameid>d67ec73f-f879-4911-9d88-c02ea527c534</gameid>
<version>1.0</version>
<firstpublished>2014</firstpublished>
<attr name="start" type="script">
this.count_down_clock_seconds = 30*60*60+10
</attr>
<statusattributes type="stringdictionary">
<item>
<key>count_down_clock_string</key>
<value>Countdown: !</value>
</item>
</statusattributes>
<attr name="count_down_clock_string" type="string"></attr>
<attr name="count_down_clock_seconds" type="int">0</attr>

<attr name="changedcount_down_clock_string" type="script">
ClearScreen
msg ("Countdown: " + game.count_down_clock_string)
</attr>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
</object>
<function name="Format2Digits" parameters="number" type="string">
return (Right("0" + number, 2))
</function>
<timer name="count_down_clock_timer">
<enabled />
<interval>1</interval>
<script>
SetTimeout (1) {
if (game.count_down_clock_seconds = 0) {
DisableTimer (count_down_clock_timer)
} else {
game.count_down_clock_seconds = game.count_down_clock_seconds-1
n = game.count_down_clock_seconds
seconds = n % 60
n = n / 60
minutes = n % 60
n = n / 60
hours = n % 24
n = n / 24
days = n
game.count_down_clock_string = Format2Digits(days) + ":" + Format2Digits(hours) + ":" + Format2Digits(minutes) + ":" + Format2Digits(seconds)
}
}
</script>
</timer>
</asl>

jaynabonne
I just realized something - I had taken your code as a starting point, and I just noticed the SetTimeout in there. I'm not sure why it's there, but it causes the clock to be delayed by a second. It seems to work better without it, unless you had a reason for it being there.

HegemonKhan
hmm... I'm not sure why it's there... I don't remember adding that into the code, or does it come with the GUI~Editor of the Timers (as I used it to set up the timer) ???

---------

I just use what I can use, what I know how to do, and what I can understand, so I'm limited in my code designs... the more coding that I learn the more ideas and capability I'll have with using better code designs for what I want done.

I still have trouble with the mod operatorus... with my brain understanding how to apply it correctly for the things that I want done. Heck, even the if~then stuff is still hard for my brain, sighs. My brain was going to explode as I was trying to follow and understand my own "change" scripts... sighs. Maybe I was just tired, but I could hardly make sense of them when I was trying to think through their (well, my code design's) process, to try to find what I thought was causing (or location of) my error in the code, before I finally realized it had something to do with no quotes in front of the atributes with it taking off the left most zero. I think it took me at least 8 hrs to get this simple countdown timer code of mine to work, it's just frustrating that it took me 8 hrs to craft something so simple as this stuff, sighs.

-------

anyways, (I guess) thanks for the "novel use of changed scripts" compliment of yours, lol. It's how my brain understood trying to get this to work... ya... I think badly and~or weirdly...

Also, thanks for posting your own code! time to study up on it, hehe :D

george
HegemonKhan wrote: I think it took me at least 8 hrs to get this simple countdown timer code of mine to work, it's just frustrating that it took me 8 hrs to craft something so simple as this stuff


Before you started to code you wouldn't have been able to do that at all, and down the road you'll be able to do it in an hour or less, so don't let it bother you :)

HegemonKhan
thanks, I understand, though it'd be nice if I could be learning to code better, faster, lol. I want to make great games, but I'm severly limited by my lack of coding (and lack of game design ability, game mechanics, writing, and etc, lololol). I'm just very impatient, my progress is too slow for my liking. Just being able to code some thing in that works is a challenge enough, then trying to code something in for its actual application within the game (code design and game design "affinity", lol), trying to then figure out the game mechanics involved, and how to code them in... sighs. A long journey begins with small steps, and thus will take many many many small steps just to travel a few strides forward, lol. I'm so thankful for quest and all of you for helping me come this "far" already! Just ignore my venting impatience (I got this epic ambitious RPG that I want to make, lol), hehe :D

I go back and forth, between learning to code, designing (well, mostly just brainstorming) the foundation of games, trying to re-organize my disorganized notes and codings, trying to think of and write story~plot ideas, and etc... I jump around too much, but it is hard to stay focused on one thing, as it gets boring fast focusing on that single thing. Game Makers are truly amazing people!

george
I think you're doing great HK, remember, everyone overestimates what they can do in 1 year, underestimates what they can do in 5 years, and has no idea how much they could accomplish in 10 years :).

jaynabonne
And I've been writing code in one form or another for over 30 years. I've not only written a lot of code (and made all the mistakes), but I've also read a lot of code and learned from it. That was why I posted - so you could see another way. Even if you don't use the mod operator, just the thought of tracking seconds might be simpler than each digit separately. (Sometimes it's when you turn the problem on its head that a simpler solution emerges.)

From what I've seen, HK, I'd agree - you're doing great. :)

HegemonKhan
I was originally going to do that (everything based on just the "second" attribute and trying to use the mod operatus for it) on a separate occasion with working on a game (not related to this countdown timer attempt), but then I thought, what if in-game, I want to add a few hours to the time, I (believe) I would need to have an attribute for each unit (second, minute, hour, day, ~week, month, and year) anyways to be able to handle this, which I'm not sure how'd I do that via the mod operatus or in some other way, other than the most direct "somewhat easy" way of my usage of the cumbersome (my "brute force" approach, as I still don't have much coding knowledge) "if" and "changed" scriptings. Though, my countdown timer code is mostly actually based upon the "second" attribute (in fact) as well:

the seconds countdown, and when they get to zero, on the next timer second interval, the second gets changed back to "9", which then causes the "minute" attribute to lower (or is changed to the "9" or "5", which lowers the next unit or it is changed to "9" or "5", lol), and thus this "chain reaction" pattern partially repeats for the rest of the units, but it's entirely controlled (properly, I hope, lol) by the ticking down of the "second" attribute:

the "second" attribute lowers the "minute" attribute, which in turn lowers the "hour" attribute (note: I actually have a "ones" and a "tens" attribute for each of the unit attributes), and thus, if we remove the "second" attribute from lowering, or if we were to lower the other units, than the countdown would be seriously flawed~messed up and~or not even work at all.

so, my countdown timer code (based upon using just that single "second" attribute) has nothing to do with (doesn't help with) this problem of how to code seomthing where you can change any of the units, and still keep the correct time~date~timer~countdown correct of the system of it.

so, for an extensive "date~time and~or timer~countdown system", I'm not sure if you could just code for a single unit ("second") for the rest of the code to be based upon, you'd need to connect (code for) all the units, so that you can change any unit, while keeping the system correct.

so, I'm not sure how to go about this in terms of code design, besides the "brute force" usage of "if" and "changed" scripts... a lot to learn in coding, I have, laughs.

--------------

as can be seen, I can somewhat do the coding, but my real lack of coding ability is with learning of how to design the coding, to do what I want, as the actual coding isn't too hard to learn how to do, but you need to know the what~how (design) to code something. If this makes any sense. I need to get much more experience~knowledge of code designing~theory, I still haven't got around to learning how you add strings together to create a script, as I see you use for a lot of things, jayna, which I have called this "string parsing" coding, lol. What are the ways (or if there are any ways) to develop or to learn how improve ones code designing knowledge or brain~mind set of thinking, besides just doing more coding, would learning the programming modeling stuff (all the charts diagrams and etc organizational stuff) work? This doesn't seem to pertain to code designing, just in making it easier to do the coding itself. How do you learn the "tricks or tactics or methods" of coding in different designs?

I guess my brain is too "single approach" focused, it's hard for me to think differently, to come up with a different way of tackling a code problem, I have trouble with creative ways to go about designing a code method to do the thing that I want.

I know code design is from years of experience with coding, 30 years is a long time, jayna, hehe, but is there anything that I can read or study to help my brain in being more creative towards designing a code for something? Is there anything that can help train~teach my brain to have a better, more creative, "coding thought process" ??? (though, I still need to learn how to do the actual coding of these different designs too ~ like your "string to script" coding + the other stuff you did in your 3d map generation coding too, mod operatus, and etc stuff, lol).

I'm getting too far ahead of myself... I still need to get more proficient in just equipment coding (and I still haven't delved into magic~spell coding either). so, let me force myself into doing~learning these things, first... I just need better discipline... lol.

This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums