Time Difference Help

chaosdagger
24 May 2016, 18:06
Ok so I'm making a game using the Clock Library found on the help page (I had set up my own clock a long time ago with help from people on the forums, but this one is just so much easier to use lol.) My problem however is I am having main game time run on the premise that each action takes a minute, but in fights (like D&D) turns change to only being 6 seconds each. So what I'm wondering is although I know I need to disable the main clock increase when shifted to a fight, how do I set it so that going back to main time from a fight only adds to the clock 1 minute for every ten turns, and everything in between those ten turns is ignored?

HegemonKhan
24 May 2016, 19:00
for what you described... you can just divide by 10, as when working with integers, the rounding is truncated in quest (I think, lol):

game.minutes = game.minutes + (game.combat_rounds / 10)
// 5 / 10 = 0
// 10 / 10 = 1
// 14 / 10 = 1
// 15 / 10 = 1
// 19 / 10 = 1
// 20 / 10 = 2

----------

though, if you wanted to do more advance stuff, there's:

the 'modulus ' Operator: %

this is a division operation, except it finds the remainder

the modulus operator is great for 'cycles', such as 0-59 seconds/minutes or 0-11/0-23 hours, etc etc etc

for example:

game.military_hours = game.turns % 24
// turn: 0, hour: 0
// turn: 1, hour: 1
// turn: 23, hour: 23
// turn: 24, hour: 0
// turn: 25, hour: 1
// turn: 47, hour: 23
// turn: 48, hour: 0

game.civilian_hours = game.turns % 12
// turn: 0, hour: 0
// turn: 1, hour: 1
// turn: 11, hour: 11
// turn: 12, hour: 0
// turn: 13, hour: 1
// turn: 23, hour: 11
// turn: 24, hour: 0

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

also, the modulus allows for stuff like this:

is the number even or odd?

if (game.number % 2 = 0) { msg ("The number is even") } else { msg ("The number is odd") }
// any number divided by 2, not having a remainder, is even
// 10 / 2 = 5 R 0 = even
// 11 / 2 = 5 R 1 = odd
// 19 / 2 = 9 R 1 = odd
// 20 / 2 = 10 R 0 = even

and so you can use this for many other things, which use other values besides (divisible by) 2... and probably able to use other values besides '=0' too.

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

here's some links of my own work with trying to learn date+time coding:

viewtopic.php?f=18&t=4162 // this was before I knew of the modulus operator, lol
viewtopic.php?f=18&t=4317 // and here's more of me struggling with date+time coding, lol

chaosdagger
24 May 2016, 19:55
Ah that is so damn simple it could have bit me! Thanks very much.

HegemonKhan
24 May 2016, 20:00
P.S.

also, if you don't know of a way to do the disabling, here's a way:

simply put the actual time scripting within an 'if' Script, using a Boolean Attribute as a toggle for when do the actual time vs not (combat actions/rounds or whatever other actions/events such as for example checking a "character info screen" or whatever).

for example, using Pixie's 'notarealturn' Boolean Attribute (search forum for it, if you want to find/see his threads/posts on it):

<game name="sample">
<attr name="notarealturn" type="boolean">false</attr>
<attr name="minutes_count" type="int">0</attr> // this is your minutes total count tally, also displayed in the status attribute pane
<attr name="minutes_time" type="int">0</attr> // this is for your 0-59 minutes, to be, displayed in the status attribute pane
<statusattributes type="simplestringdictionary">minutes_count = Total Minutes: !; minutes_time = Clock Time (minutes): !</statusattributes>
</game>

<turnscript name="global_turnscript">
<enabled />
<script>
if (not game.notarealturn) {
game.minutes_count = game.minutes_count + 1
game.minutes_time = game.minutes_count % 60
}
</script>
</turnscript>

<object name="orc">
<attr name="fight" type="script">
game.notarealturn = true // toggling off the Boolean Attribute, to stop your actual time keeping while you fight the orc
// your fight scripting...
// and when the fight is over, toggling back on the Boolean Attribute, for your actual time keeping to continue:
if (orc.current_life <= 0) {
game.notarealturn = false
}
</attr>
<attr name="displayverbs" type="simplestringlist">fight</attr>
</object>

<verb>
<property>fight</property>
<pattern>fight</pattern>
<defaultexpression>You can't fight that.</defaultexpression>
</verb>