Adding room dimensions after Room Title output

Posted by Gadush on Sat 17 Jun 2006 05:16 AM — 11 posts, 38,341 views.

#0
Hey all,

I want to add something in after the Room Title, but I can't find where the information should go. It seems like it would maybe be in act_info somewhere? Is the title part of ROOM_INDEX_DATA, and if so, where can I find what all composes ROOM_INDEX_DATA? Sorry, as it is obvious I am a muddling newb, and further I have been away from all this coding stuff for a bit.

What I have is room size data being stored as x,y, and z. I can edit the size of a room, and set the sizes. It saves and loads and all.
What I want, is for those sizes to appear after the title in each room:

A Small Cottage [15 x 10 x 10]

This is a small cottage, blah blah blah.

Can anyone kick me in the right direction with this?
Thanks in advance,
Gadush
USA #1
Did you store your room sizes in the room structure? Then normally, the room title etc. should be in the same place: in mud.h. The structure's name isn't actually ROOM_INDEX_DATA, it's room_index_data; this is due to an annoying limitation in C that went away in C++. (You can actually get around it in C, too, by typedefing an anonymous structure type, but you have to know to look for it. Anyhow.)

So yes, look in mud.h and that will be where the full list of data members of rooms will be.

A good way to figure out where the code needs to be changed is to simply trace through the code for a command that you understand. Consider do_look, for example. Follow the code for it and you will eventually find where it prints out the room title. It's a good way to familiarize yourself with the code, too, so I strongly advise an approach like this, instead of just searching for the right data member name.
#2
Hi all,
Well, I am at it again, the muddling guy trying to understand all this stuff. With a LOT of help, I added room dimensions to smaug, at least partially. Right now, using 'redit rsize' I can assign x, y, and z variables such as 10 x 10 x 10 to any room. It saves, loads, etc. I haven't really done anything with those variables yet though, and I am stuck on a simple part. If I was more intelligent and less bullheaded, I would just give up. Anyway, all I am trying to do right now is get the assigned sizes to display after the room name.

This is added to build.c, to give a room three dimensions x, y, and z.
It works, and saves, and loads. But I can't figure out how to access those numbers, to display them after the room name.

/* added to for rsize */
    if ( !str_cmp( arg, "rsize"  ) )
    {
	char xcoord[MAX_STRING_LENGTH];
	char ycoord[MAX_STRING_LENGTH];
        char zcoord[MAX_STRING_LENGTH];
      	argument = one_argument( argument, xcoord);
      	argument = one_argument( argument, ycoord);
      	argument = one_argument( argument, zcoord);
//Putting this here to verify that what your entering is valid
      	if ( !xcoord || xcoord[0] == '\0' || !ycoord || ycoord[0] == '\0' || !zcoord ||zcoord[0] == '\0')
    	{
			send_to_char( "Set the room size: width, length, height.\n\r", ch );
			send_to_char( "Usage: redit rsize <value> <value> <value>\n\r", ch );
			return;
    	}
//Didn't realize it was location and not room
      	location->x = atoi(xcoord);
      	location->y = atoi(ycoord);
      	location->z = atoi(zcoord);
      	ch_printf(ch, "Room size set to:\n\r\tWidth: %d\n\r\tLength %d\n\r\tHeight %d\n\r", location->x, location->y, location->z);
   		return;
    }


Here is do_look:



/* 'look' or 'look auto' */
	
	set_char_color( AT_RMNAME, ch );
	send_to_char( ch->in_room->name, ch );
	send_to_char( "          Size: %d X %d X %d\n\r",   
      location->x,
      location->y,
      location->z );


This won't work, because location isn't declared, etc. How do I grab the variables?
I just can't get this stuff, dang it. How can I access the variables x, y, and z, that I set in build with rsize function? I want to be able to have 'look' show:

A Small Cottage Size: <x> X <y> X <z>
Where x, y, and z are the variables set in the room. Those variables are part of room_index_data.
Thanks,
Gadush
USA #3
cant you do like...

sprintf( buf, "%s Size: %d X %d X %d\n\r", ch->in_room->name, ch->in_room->x, ch->in_room->y, ch->in_room->z);
send_to_char( buf, ch );

wouldn't that work?
#4
Nope, it gives the error that buf is undeclared and exits the compile.
USA #5
You need to declare buf then.
char buf[MAX_STRING_LENGTH];
#6
Thanks, that did it. I feel like a doofus, but oh well.
I might as well get used to it, and just keep trying to understand. I have a couple of books on C now, and I'm going through them, but sometimes it just puts me right to sleep after a day's labor roofing. =P

Anyhow, thanks for the tremendous help all.

Gadush

USA #7
Quote:

Nope, it gives the error that buf is undeclared

Quote:

This won't work, because location isn't declared


You seem to have a misunderstanding with how variables work. In C you need to declare a variable before it is used. The reason you are getting undeclared errors is becuase you never told the compiler what "location" or "buf" were.

What Saito suggested would work perfectly fine. If you were to pursue what you were trying to do you would need to do something along the lines of (using your code):

        ROOM_INDEX_DATA *location = ch->in_room;

	set_char_color( AT_RMNAME, ch );
	send_to_char( ch->in_room->name, ch );
	ch_printf(ch, "          Size: %d X %d X %d\n\r",   
      location->x,
      location->y,
      location->z );


The only real change is the line that defines location. This informs the compiler what location is, and would take care of your "location undeclared" errors.

Note also to do it your way you would need to use ch_printf (or sprintf and then send_to_char the buffer like Saito suggested). Send_to_char does not support the passing of a variable number of arguments.
#8
Thanks for the reply. That is the sort of thing, besides the commands that are now being defined and listed on Gammon (*smile*), that I was hoping to get a handle on.
Quote:

Send_to_char does not support the passing of a variable number of arguments.

Send_to_char is a function, right? It would be nice to have that function documented, with an example of how to use it and what exactly it does. Thanks!

ROOM_INDEX_DATA *location = ch->in_room;

I am trying to understand the above line. It is an assignment. What is the pointer to location? How would you read that statement in plain english?
Thanks for all the help.
Gadush
USA #9
kinda means location is the name your giving to room data. To me I just think of it as an alias to the data or something.
USA #10
If you are familiar with mathematics, you would read it as something like this:

Let location be a variable, containing the object equal to the field in_room of the structure referred to by variable ch.



The big difference is that the programmer's equal sign is an assignment, whereas the mathematician's equal sign is a proposition that can be true or false (like the programmer's double-equal sign).