I need to know how many rooms there are in my game.
Since there is no 'Game.RoomCount' property (shouldn't there be one?), how can I do this? Help!
The simple way is counting it yourself, and sticking this in your global script header:
#define RoomCount 15
(or however many rooms you have).
After all, the amount of rooms is hardly going to change mid-game.
Knowing the room count wouldn't necessarily be useful, because rooms can have such random numbers. You could have a RoomCount of 2, but the two rooms could be Room 53 and Room 641.
For what purpose do you need to know? It might be possible to implement something to help.
Moreover, since it is possible to add rooms to a already compiled games, so the room count can't be a hard-coded number during compilation.
Quote from: Pumaman on Thu 14/02/2008 21:14:03
Knowing the room count wouldn't necessarily be useful, because rooms can have such random numbers. You could have a RoomCount of 2, but the two rooms could be Room 53 and Room 641.
This is a different problem, but indeed it is a problem. AFAIK, the only way to get the room number at runtime is by fetching player.Room whenever a player is at a room. The other ways require you to be very methodic and organized, like creating (and maintaining) a room property or numbering the rooms sequentially.
QuoteFor what purpose do you need to know? It might be possible to implement something to help.
I had an idea about a module that would need to create a dynamic array with (Game.RoomCount * AGS_MAX_OBJECTS) positions. I changed my mind, and ended up doing things differently, but I guess Game.RoomCount would not be so hard to implement, and a module writer could benefit from it.
An easy way of determining it is this:
int i, roomcount;
while (i < 300) {
if (HasPlayerBeenInRoom (i)) roomcount ++;
i ++;
}
Of course, that doesn't count all rooms, but it does count the relevant ones.
Quote from: Radiant on Mon 18/02/2008 23:39:56
An easy way of determining it is this:
Interesting piece of code... Even after 8 months using AGS daily, I still bump into commands that I never heard of, like this HasPlayerBeenInRoom().
But this code would only count rooms the player has already been into. OTOH, if the function returned 'null' for any non-existant i-th room, it could be used to find all the room numbers up to 300.