LCamelot wrote:
until the player wakes up 5 to 9 hours later (determined randomly; after all, you can't control how long you sleep).
I don't think is really true; many if not most people can control how long they sleep within an hour or two. And most people sleep a fairly consistent length of time, all else being equal; if every time I went to sleep I didn't know whether it'd be for nine hours or five...
I think you have generally the right idea here, but the code as you have it:
Quote:
Code:
Carry out sleeping (this is the standard sleeping rule):
let n be a random number between 360 and 480;
let x be a random number between -60 and 60;
let n be n plus x;
let t be the time of day;
increase t by n minutes;
say "You fall asleep...";
while the time of day is not t:
follow the turn sequence rules.
will go horribly wrong, because the while loop is in the wrong place; it'll advance the time to the time the player wakes up, then run through most of the rest of the day (waking up 24 hours after the player went to sleep!) You need something more like
Code:
let n be a random number between 360 and 480;
let x be a random number between -60 and 60;
let n be n plus x;
say "You fall asleep...";
while n > 0:
now n is n - 1;
follow the turn sequence rules.
Some considerations:
- This will not suppress any messages that are printed by the every turn rules. If you have any of those you'll need to do something about that (probably with a value like 'if the player is asleep') or the player will get barraged with a screenful of every turn messages.
- If you have a lot of every turn rules, running through this many turns at once has the potential to really slow Inform down. Be careful.
- If you want to interrupt sleep for whatever reason, add another condition to that 'while'.