[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Adding room dimensions after Room Title output
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Adding room dimensions after Room Title output

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Gadush   (92 posts)  [Biography] bio
Date Sat 17 Jun 2006 05:16 AM (UTC)
Message
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
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #1 on Sat 17 Jun 2006 06:03 AM (UTC)
Message
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.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Gadush   (92 posts)  [Biography] bio
Date Reply #2 on Wed 21 Jun 2006 02:49 PM (UTC)
Message
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
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #3 on Wed 21 Jun 2006 03:36 PM (UTC)
Message
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?

Everything turns around in the end
[Go to top] top

Posted by Gadush   (92 posts)  [Biography] bio
Date Reply #4 on Wed 21 Jun 2006 11:51 PM (UTC)
Message
Nope, it gives the error that buf is undeclared and exits the compile.
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #5 on Wed 21 Jun 2006 11:55 PM (UTC)
Message
You need to declare buf then.
char buf[MAX_STRING_LENGTH];

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Gadush   (92 posts)  [Biography] bio
Date Reply #6 on Thu 22 Jun 2006 12:52 AM (UTC)
Message
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

[Go to top] top

Posted by Nick Cash   USA  (626 posts)  [Biography] bio
Date Reply #7 on Thu 22 Jun 2006 12:57 AM (UTC)
Message
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.

~Nick Cash
http://www.nick-cash.com
[Go to top] top

Posted by Gadush   (92 posts)  [Biography] bio
Date Reply #8 on Thu 22 Jun 2006 02:02 AM (UTC)
Message
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
[Go to top] top

Posted by Metsuro   USA  (389 posts)  [Biography] bio
Date Reply #9 on Thu 22 Jun 2006 02:05 AM (UTC)
Message
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.

Everything turns around in the end
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #10 on Thu 22 Jun 2006 02:15 AM (UTC)
Message
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).

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


6,995 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]