Basically, I want this actor and eventually others to roam through the rooms, go to meals and sleep at night. I’m having a incredibly difficult time making them wander from room to room, so much that I’m using debugs to try and figure out what is wrong.
+ wright: Actor
name = 'Wright'
vocabWords = 'wright; brother; pup;
wolf; skunk'
desc = "This is your eight-year-old little brother, Wright. He has black and white fur markings that make him look a bit like a skunk."
isListed = true
// Give Wright a starting location
location = den
// Property to track his last known location to prevent spamming movement messages.
lastKnownLocation = nil
;
wrightScheduler: object
name = 'Wright Scheduler'
;
modify wrightScheduler
endTurn() {
// --- ADD THIS LINE FOR TESTING ---
say('<b>DEBUG: Wright scheduler is running. Time is <<gameTime.getTimeString()>>.</b><br>');
local curTime = gameTime.currentTime;
local playerRoom = me.getOutermostRoom();
local wrightRoom = wright.location;
local targetLocation = nil;
// 1. Determine Wright's target location based on important schedules (sleep, meals)
if (curTime >= 1320 || curTime < 360) {
// It's bedtime, he should be in the den.
targetLocation = den;
} else if ((curTime >= 480 && curTime < 540) || (curTime >= 780 && curTime < 840) || (curTime >= 1080 && curTime < 1140)) {
// It's mealtime, he should be in the dining room.
targetLocation = diningRoom;
}
// 2. If he doesn't have a scheduled place to be, consider wandering.
// He will only wander if the player is NOT in the same room.
if (targetLocation == nil && wrightRoom != playerRoom && rand(100) < 20) {
local possibleDestinations = [den, diningRoom, roof] - [wrightRoom];
if(possibleDestinations.length > 0) {
targetLocation = possibleDestinations[rand(possibleDestinations.length)];
}
}
// 3. If he has a destination and he's not already there, move him.
if (targetLocation && wrightRoom != targetLocation) {
// Announce his departure if the player can see him leave
if (wrightRoom == playerRoom) {
say('Wright gets a bit restless and wanders off. ');
}
// Move him to his new location
wright.moveInto(targetLocation);
// Announce his arrival if he enters the player's room
if (targetLocation == playerRoom) {
// Customize the message based on why he's moving.
if (targetLocation == diningRoom && wrightRoom != diningRoom) {
say('Wright trots into the dining room, ready to eat. ');
} else {
say('Wright wanders into the room. ');
}
}
}
}
;