night and day

darkgoddessnight
16 Oct 2006, 23:17
well, I am slowly learning to read code as a second language but this one is a toughie. I want to implement time in my game, including night and day but I am not exactly sure how I would go about doing this. I am planning on making a 24 hour period in about 4 hours real time and I would like to have it where the turning of the seasons affect the time night and day lasts. You know, the solstices and equinoxes...and also, I would like to implement seasons, winter summer spring and fall and have different look descriptions for outdoor areas during those times, like leaves on the ground in autumn, or snow in winter. I know I am asking alot, but I have dreams of grandeur and am hoping someone knows how to do this :D.
Thanks in advance,
Shadow :D

Elexxorine
17 Oct 2006, 11:31
Ok, I don't know how to do seasons/variable lengths of day, but I do have a time-day/night code you can use, it should work on its own. Here you go:
	define variable <sec1disp>
type numeric
scope global
value <0>
display <Time: %hourdisp%:%sec2disp%%sec1disp%.>
onchange {
if ( %sec1disp% = 10 ) then {
set numeric <sec1disp; 0>
inc <sec2disp>
}
if ( %hourdisp% > 6 ) and ( %hourdisp% < 19 ) then flag on <day> else flag off <day>
}
end define

define variable <sec2disp>
type numeric
scope global
value <0>
onchange {
if ( %sec2disp% = 6 ) then {
set numeric <sec2disp; 0>
inc <hourdisp; 1>
}
}
end define

define variable <hourdisp>
type numeric
scope global
value <7>
onchange if ( %hourdisp% = 24 ) then set numeric <hourdisp; 0>
end define
Put that one in the 'define game' block, this other one goes at the ned of your ocde:
define timer <secadd>
interval <0>
action inc <sec1disp; 2>
enabled
end define
I have two second values so it will show '9:03' instead of '9:3', and looks better that way.

GameBoy
17 Oct 2006, 12:30
You could implement days, months etc. using a similar function as you would with time. As the seconds increase, so do the minutes, hours.

You could use arrays, as that is probably the best way.

Elexxorine
17 Oct 2006, 12:36
Yeah, you'd have an array for month names, as these wouldn't just be numbers. You can even have another array to state how many days are in each month if they change, you can keep going, building up: seconds, hours, days, months, years, and so on...

Also a crude way to do seasons is to have each month set to one, eg: winter=dec, jan, feb, spring=march, april, may, summer=june, july, aug, autumn=sept, oct, nov. And each season has a set number of 'daylight hours' or each month could.

There you go...

Shadowalker
25 Oct 2006, 02:43
Hello, I was looking through my PC the other day and re-discovered quest. I'd like to play around with it a bit if/when I have some time, but it's been a while and I've forgotten a lot. Anyway, I was playing around with the code elexxorine posted for a time cycle, and I'd like to make a custom command to change the time. I've started on the hours first, so just ignore the seconds, minutes, and day flag for now. I've remembered (I think) how to enter the what the user types in into a string variable (I use QDK so an attempt to explain it in coding terms won't help me :P) and then put that into a numeric variable. I've gotten it to only accept numbers from 0-24, otherwise it won't work. The problem is, I can't remember how to get it to accept numbers only; if you type in a letter it will change the time to 0 (zero). Any ideas? Here is the code: (Oh, and type in 'change time' to start the sequence.)

' "Time"
' Created with QDK 3.53 - UNREGISTERED VERSION

define game <Time>
asl-version <350>
gametype singleplayer
start <Room>
game info <Created with QDK 3.53 - UNREGISTERED EVALUATION VERSION.>
command <change time;change the time;time;change;change times;change clock;clock;change the clock> {
msg <What would you like to set the hours to?>
enter <change>
if ( #change# >= 0 ) and ( #change# <= 24 ) then set numeric <hourdisp; #change#> else msg <I'm sorry, that is either an unavailable number or you have entered an incorrect format. Please re-enter the code 'change time' to restart this process.>
}
define variable <sec1disp>
type numeric
value <0>
display <Time: %hourdisp%:%sec2disp%%sec1disp%.>
onchange {
if ( %sec1disp% = 10 ) then {
set numeric <sec1disp; 0>
inc <sec2disp>
}
if ( %hourdisp% > 6 ) and ( %hourdisp% < 19 ) then flag on <day> else flag off <day>
}
end define
define variable <sec2disp>
type numeric
value <0>
onchange {
if ( %sec2disp% = 6 ) then {
set numeric <sec2disp; 0>
inc <hourdisp; 1>
}
}
end define
define variable <hourdisp>
type numeric
value <7>
onchange if ( %hourdisp% = 24 ) then set numeric <hourdisp; 0>
end define
end define

define synonyms
end define

define room <Room>
end define

define timer <secadd>
interval <0>
action inc <sec1disp; 1>
enabled
end define

define text <intro>

end define

define text <win>

end define

define text <lose>

end define


Shadowalker
25 Oct 2006, 06:54
I found a way to make sure you can only enter the numbers 0-24. Substitute this code for the part in blue in the code posted above:

command <change time;change the time;time;change;change times;change clock;clock;change the clock> {
msg <What would you like to set the hours to?>
enter <change>
if ( #change# = 0 ) or ( #change# = 2 ) or ( #change# = 3 ) or ( #change# = 4 ) or ( #change# = 5 ) or ( #change# = 6 ) or ( #change# = 7 ) or ( #change# = 8 ) or ( #change# = 9 ) or ( #change# = 10 ) or ( #change# = 11 ) or ( #change# = 12 ) or ( #change# = 13 ) or ( #change# = 14 ) or ( #change# = 15 ) or ( #change# = 16 ) or ( #change# = 17 ) or ( #change# = 18 ) or ( #change# = 19 ) or ( #change# = 20 ) or ( #change# = 21 ) or ( #change# = 22 ) or ( #change# = 23 ) or ( #change# = 24 ) then set numeric <hourdisp; #change#> else msg <I'm sorry, that is either an unavailable number or you have entered an incorrect format. Please re-enter the code 'change time' to restart this process.>
}


The only thing is, you need to enter each number in individually. Is there an easier way?