Computer time scripting (SOLVED)

Started by timlump, Sat 27/05/2006 22:16:07

Previous topic - Next topic

timlump

In my game I plan to have a realtime day/night system but although i know it should be possible how would I make the game run a piece of code say at 5pm.
Please help i have no idea where to begin without this forums brilliant help.

Ashen

DateTime functions & properties. (Particularly DateTime.Now and DateTime.Hour)

So something like:
Code: ags

DateTime *dt;

//rep_ex
dt = DateTime.Now;
if (dt.Hour == 17) {
  // Do stuff at 5:00 PM
  // Add dt.Minute and dt.Second checks to make it happen at EXACTLY 5, rather than for the whole hour
}

I know what you're thinking ... Don't think that.

timlump

where would i put that exactly

Khris

You'd put it in the global script.

Insert this at the beginning, outside any function:
Code: ags
DateTime *dt;


The following belongs inside the repeatedly_execute function:
Code: ags
//rep_exÃ,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã,  Ã, <--- INDICATION OF WHERE TO PUT IT BY ASHEN
dt = DateTime.Now;
if (dt.Hour == 17) {
Ã,  // Do stuff at 5:00 PM
Ã,  // Add dt.Minute and dt.Second checks to make it happen at EXACTLY 5, rather than for the whole hour
}


timlump

i tried your code and it refuse to work but luckily with a little copying and pasteing
i managed to get exactly the scripting effect i wanted.
Now may game features a 24 hour day time /night time effect.

Khris

This sounds like "Your suggestion didn't work, but I got it working on my own by following your instructions." ;)

SMF spam blocked by CleanTalk