10 Jul, 2012, jareth wrote in the 1st comment:
Votes: 0
Hello,

I am trying to add a room_update function to a godwars derivative. The code compiles cleanly, and there are no
crashes because of it. Only issue is, the update does not function.

void room_update(void)
{
int i;
ROOM_INDEX_DATA *room;

for (room = room_list; room != NULL; room = room->next_room)
{
log_f("Entering room update!");
for (i=0;i<MAX_RTIMER;i++)
if (room->tick_timer[i] == 0)
room = room->next_room;
if (RTIMER(room, RTIMER_FLAME) < 0)
room->tick_timer[i] = UMAX(room->tick_timer[i], 0);
if (RTIMER(room, RTIMER_FLAME) == 1)
room_message(room, "The flames extinguish themselves");

for (i = 0; i < MAX_RTIMER; i++)
room->tick_timer[i] = UMAX(room->tick_timer[i] - 2, 0);

}

return;

}


Any thoughts or help, would be appreciated.
Jareth
10 Jul, 2012, Lyanic wrote in the 2nd comment:
Votes: 0
To start with, you're advancing to the next room in the linked list potentially multiple times per iteration…lines 6 and 11. Is that intended?
11 Jul, 2012, plamzi wrote in the 3rd comment:
Votes: 0
Assuming this is the only place where you decrement room->tick_timer[], and assuming that UMAX returns the greater one of two values, I see the following:

1. Line 9-11: If even one of the timers is at 0, no other timers will get decremented. Can't think of why this would be intended. Maybe what you're looking for at line 11 is to do 'break;' so that i is equal to the first timer that has reached 0?

2. Line 12: Timer will never fall under 0 because line 18 ensures it will always be at least 0.

3. Line 14: Timer will not become == 1 unless the tick timer was initially set to an odd value (because line 18 decrements by 2).
11 Jul, 2012, jareth wrote in the 4th comment:
Votes: 0
This iteration of our room_update function, was borrowed from a mud, where it was functional, with modifications only to remove room timers that were not in the game.

I have tried many things.

I would have thought something like this would work aswell.
void room_update(void)
{
ROOM_INDEX_DATA *room;

// set initial room vnum to 1, via limbo.
for ( room = get_room_index(ROOM_VNUM_LIMBO); room != NULL; room->next_room)
{
if(RTIMER(room,RTIMER_FLAME) > 1)
{
RTIMER(room,RTIMER_FLAME) = RTIMER(room,RTIMER_FLAME) - 1;
room_message(room,"The intensity of the flames diminish slightly.");
}
room_message(room, "Flame out.");


}
return;
}
11 Jul, 2012, plamzi wrote in the 5th comment:
Votes: 0
Sometimes borrowing from another code is harder than writing from scratch.

I think you need to start by telling us what you expect your code to do exactly; "does not function" is not specific enough. Then make sure you've posted enough code so that even people not familiar with your codebase can see what all is involved. For instance, we still haven't seen where those timers are set.

Also, if you want people to be able to help, you need to give them time to process your request before posting complete rewrites–or you'll be wasting some people's time. The second snippet you posted is very different, and it's clear that for every call to "room_update", all your rooms will get the message "Flame out." But that's a different issue from what you posted initially.

This is just an educated guess as to what you're trying to do:

void room_update(void)
{
ROOM_INDEX_DATA *room;
// set initial room vnum to 1, via limbo.
for ( room = get_room_index(ROOM_VNUM_LIMBO); room != NULL; room->next_room)
{
// update rooms with flame
if(RTIMER(room, RTIMER_FLAME) > 1)
{
RTIMER(room,RTIMER_FLAME)–;
if (RTIMER(room, RTIMER_FLAME))
room_message(room,"The flames diminish slightly.");
else
room_message(room, "The flames die out.");
}
// end update rooms with flame
} // end room update
}
11 Jul, 2012, jareth wrote in the 6th comment:
Votes: 0
Since I got ahead of myself, I apologize:

The idea is, a player with a specific power leaves the room, in doing so, ignites the room in fire.
void add_flame( CHAR_DATA *ch, long direction )
{

if (IS_NPC(ch)) return;
if (IN_WILDERNESS(ch->in_room->vnum)) return;
if(IS_DEMON(ch) && get_lore(ch,LORE_FUNDAMENT) > 1)
{

SET_RTIMER(ch->in_room, RTIMER_FLAME, 10);
send_to_char("You set a fire as you leave the room.\n\r",ch);
}
return;
}

This sets the room up with a timer (10) is just a random number we set.
I want room_update to check the room, if it has a timer, decrement the timer by 1

Using the code you supplied:
in case it was something I did wrong *aside from the spam flame out*
void room_update(void)
{
ROOM_INDEX_DATA *room;
// set initial room vnum to 1, via limbo.
for ( room = get_room_index(ROOM_VNUM_LIMBO); room != NULL; room = room->next_room)
{
log_string("Room_update"); // It does post a log at this point, then that is it… nothing else beyond.

// update rooms with flame
if(RTIMER(room, RTIMER_FLAME) > 1)
{
log_string("Checking the room!");
RTIMER(room,RTIMER_FLAME)–;
log_string("RTIMER_FLAME - 1");
if (RTIMER(room, RTIMER_FLAME))
room_message(room,"The flames diminish slightly.");
else
room_message(room, "The flames die out.");
}
// end update rooms with flame
} // end room update
}

edit to remove words not suitable to young ones…. sorry.
11 Jul, 2012, plamzi wrote in the 7th comment:
Votes: 0
Something is wrong with your for loop, if it only executes once. Does "get_room_index" return a pointer to a ROOM_INDEX_DATA struct? Is ROOM_INDEX_DATA a vector of rooms that is successfully looped through elsewhere?
11 Jul, 2012, jareth wrote in the 8th comment:
Votes: 0
It seems the only time vnums are being searched through is within a command called vopen, which checks every area, for unused vnums.
I was hoping that room_index_data would allow me to set a vnum, check the room flags at that vnum, and modify accordingly.

I have been successful in spamming myself off the mud a few times, with a log_message, but, other than that, nothing happens.
I probably should examine vopen, and see if I can modify that into an update routine.
11 Jul, 2012, plamzi wrote in the 9th comment:
Votes: 0
jareth said:
It seems the only time vnums are being searched through is within a command called vopen, which checks every area, for unused vnums.
I was hoping that room_index_data would allow me to set a vnum, check the room flags at that vnum, and modify accordingly.

I have been successful in spamming myself off the mud a few times, with a log_message, but, other than that, nothing happens.
I probably should examine vopen, and see if I can modify that into an update routine.


There's gotta be a way to loop through rooms, and ROOM_INDEX_DATA sounds right. But you have to see how it's defined. It could be an array of room index structs that you loop through numerically. If that's the case, your compiler should be complaining when you try to access "room->next_room". Or maybe next_room exists as a pointer but is not actually set? Just speculating.
11 Jul, 2012, Runter wrote in the 10th comment:
Votes: 0
I seem to remember a lot of these codebases not having a single linked list to traverse to go through all rooms.

If they're stored in like a hash table then you will need to loop through each bucket, and then through each room in the bucket.
12 Jul, 2012, jareth wrote in the 11th comment:
Votes: 0
Soo, a lot more tinkering, and the final outcome which works, and does what I want is:

void room_update(void)
{
int vnum;
ROOM_INDEX_DATA *room;
for (vnum = 1; vnum < 45000; vnum++)
if(( room = get_room_index(vnum)) != NULL)

{
if(room->tick_timer[RTIMER_FLAME] > 1)
{
room->tick_timer[RTIMER_FLAME]–;
log_string("Reduced the timer."); // debug statement.
}
if(room->tick_timer[RTIMER_FLAME] == 1)
{
room->tick_timer[RTIMER_FLAME] = 0;
room_message(room, "The flames extinguish themselves");
}
}
return;
}

It was the for loop.

Thanks for the help, and insight.
0.0/11