Author Topic: adding hours to a clock  (Read 1347 times)

0 Members and 1 Guest are viewing this topic.

Offline totenmaske

adding hours to a clock
« on: July 08, 2012, 05:41:53 AM »
i want to pass time at a stage in my game (The player gets to pick between 1-24 hours), is it possible to make it so that when gTimeHours hits 24, it will add on the remainder of the time instead of going to 0 like i've set it to? I'm just not really sure how to do it.
Code: [Select]
(method (changeTimeHours addTimeHours)
= gTimeHours + gTimeHours addTimeHours
(if(> addTimeHours 0)
)
(if(>= gTimeHours 24)
= gTimeHours 0
++ gTimeDays
)
)

*edit*
I just decided to make my own script to deal with all this. Only thing is, i've never made my own before. When i call it i have a box appear and you type in how long you want to rest... "   (= lTimeHours(GetNumber("How Long?"))"
I just have a problem where every time i enter a number i get the little box popping back up, how do i leave a script once you've called it and finished using it?
« Last Edit: July 08, 2012, 07:46:38 AM by totenmaske »



Offline Cloudee1

Re: adding hours to a clock
« Reply #1 on: July 09, 2012, 03:11:58 AM »
Not sure what is going on with your input statement, but in the first section you could keep the remaining hours by subtracting 24 instead of resetting it to 0... if hours >= 24 then hours - 24, days ++... so if hours hits 26 then it would be reset to 2 instead of 0
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition

Offline totenmaske

Re: adding hours to a clock
« Reply #2 on: July 09, 2012, 06:39:50 AM »
Well... Doing it your way would have been a lot easier than what i did! I decided to change my way at it by making a switch method inside a switch method for all possible out comes. (I completely forgot to say that before when i edited my original post...)
Code: [Select]
(instance public ChangeHour of Script
(properties)
(method (init)
(super:init())
(= lTimeHours(GetNumber("How long would you like to sleep?"))
(switch(lTimeHours)
(case 1
(switch(gTimeHours)
(case 0 (= gTimeHours + gTimeHours lTimeHours)) //1 hour
(case 1 (= gTimeHours + gTimeHours lTimeHours)) //2 hour
(case 2 (= gTimeHours + gTimeHours lTimeHours)) //3 hour
(case 3 (= gTimeHours + gTimeHours lTimeHours)) //4 hour
(case 4 (= gTimeHours + gTimeHours lTimeHours)) //5 hour
(case 5 (= gTimeHours + gTimeHours lTimeHours)) //6 hour
(case 6 (= gTimeHours + gTimeHours lTimeHours)) //7 hour
(case 7 (= gTimeHours + gTimeHours lTimeHours)) //8 hour
(case 8 (= gTimeHours + gTimeHours lTimeHours)) //9 hour
(case 9 (= gTimeHours + gTimeHours lTimeHours)) //10 hour
(case 10 (= gTimeHours + gTimeHours lTimeHours)) //11 hour
(case 11 (= gTimeHours + gTimeHours lTimeHours)) //12 hour
(case 12 (= gTimeHours + gTimeHours lTimeHours)) //13 hour
(case 13 (= gTimeHours + gTimeHours lTimeHours)) //14 hour
(case 14 (= gTimeHours + gTimeHours lTimeHours)) //15 hour
(case 15 (= gTimeHours + gTimeHours lTimeHours)) //16 hour
(case 16 (= gTimeHours + gTimeHours lTimeHours)) //17 hour
(case 17 (= gTimeHours + gTimeHours lTimeHours)) //18 hour
(case 18 (= gTimeHours + gTimeHours lTimeHours)) //19 hour
(case 19 (= gTimeHours + gTimeHours lTimeHours)) //20 hour
(case 20 (= gTimeHours + gTimeHours lTimeHours)) //21 hour
(case 21 (= gTimeHours + gTimeHours lTimeHours)) //22 hour
(case 22 (= gTimeHours + gTimeHours lTimeHours)) //23 hour
(case 23 (++ gTimeDays)(= gTimeHours 0)) //1 day
) //Switch gTime end
) // case 1 lTime end
) // Switch lTime end
(if(<= lTimeHours 0)
Print("You need to pick a number between 1-24.")
) // end <=
(if(>= lTimeHours 25)
Print("You need to pick a number between 1-24.")
)// end >=
)// get number end
) //method end
) //instance end
it goes up to 24 cases to allow 24 hours of rest each time. (didn't think i should post the whole thing up :P)
As for the input statement, i made a mistake of doing (Method(doit() not (Method(init(), so it works fine now anyway... Took me awhile just to notice that is what i mucked up...

This script is 8.95Kbs, Should i not worry about that? or switch to what you said to take less space?
« Last Edit: July 09, 2012, 06:49:36 AM by totenmaske »

Offline Cloudee1

Re: adding hours to a clock
« Reply #3 on: July 09, 2012, 08:11:10 AM »
Unless you run into memory issues, I wouldn't worry about it. And even then, you could knock down that whole switch to one  or two lines so memory could be saved while still using your script, so no big worry
Halloween Competition Brass Lantern Prop Competition Groundhog Day Competition


SMF 2.0.14 | SMF © 2017, Simple Machines
Simple Audio Video Embedder

Page created in 0.114 seconds with 24 queries.