Beowulf:
Here’s my take, using the adv3lite library (if you’re not using that library, some code modifications will be required but the logic should work):
In the gPlayerChar object’s beforeTravel() method, set the ticket number and the number currently being served for the next ticket to be retrieved in the waiting room:
[code]thePlayer: Actor ‘The player’ @entry
“The player.<.p>”
isHim = true
beforeTravel(traveller, connection)
{
// reset the ticket number and currently serving number whenever the
// gPlayerChar enters to waiting room
if(connection.destination == waitingRoom)
{
ticketNum = getNewTicketNum();
ticket.ticketNum = ticketNum[1];
ticket.currentlyServing = ticketNum[2];
}
// retrieve ticket from player when gPlayerChar leaves the waiting room
if(gLocation == waitingRoom)
ticket.moveInto(waitingRoom);
}
;[/code]
The ticket numbering scheme depends on a function defined somewhere in your code base. I maintain a misc_functions.t file in each project for just such needs. (I have defined this method to return a number pair that is randomly selected from a defined list; you can define the method any way you want—to always return the same numbers, or to advance sequentially through your defined list, or…-?-):
getNewTicketNum()
{
// wating room ticket number and currently serving number returned as a
// list---ticketNums[1] is ticket number, ticketNums[2] is currently serving
// number at time of retrieval
local ticketNums = [[40,38],[41,38],[42,38]];
return rand(ticketNums);
}
In the waitingRoom object, define two variables to keep count of the number of turns between advances of the number being served, then monitor these variables in the waitingRoom object’s roomDaemon() method:
[code]waitingRoom: Room ‘Waiting Room’
desc
{
"The waiting room. ";
if(ticket.location != thePlayer)
“A sign above a roll of tickets says, Please take a ticket and
wait for your number to be called.”;
“<.p>”;
}
north = entry
// counters for number of waits
numWaits = 0
// number of waits before 'currently serving' number advances
maxWaits = 3
// announce number currently being served whenever the player commits an
// action in the waiting room; advance the 'currently serving' number as
// appropriate
roomDaemon()
{
if(numWaits++ == maxWaits)
{
numWaits = 0;
ticket.currentlyServing++;
}
"Now serving ticket number ";
say(ticket.currentlyServing + 1);
}
;[/code]
The ticket itself is a child of the waitingRoom object
+ ticket: Thing 'ticket'
desc
{
if(ticket.location == gPlayerChar)
"Your number is ";
else
"The next available ticket is ";
say(ticketNum);
". Currently serving ";
say(currentlyServing);
".<.p>";
}
// ticket number and currently serving number will be reset whenever the
// gPlayerChar enters the wating room; see beforeTravel() method in the
// gPlayerChar object definition
ticketNum = 0
currentlyServing = 0
;
Note that I have not handled what happens if the player has not responded to the clerk’s call for the number on the ticket. How that gets coded depends in large part on what it is you want to happen. But it should be easy to add that code once you’ve settled on a plan of action.
Jerry