name property

This is a discussion / support forum for the Hugo programming language by Kent Tessman. Hugo is a powerful programming language for making text games / interactive fiction with multimedia support.

Hugo download links: https://www.generalcoffee.com/hugo
Roody Yogurt's Hugo Blog: https://notdeadhugo.blogspot.com
The Hugor interpreter by RealNC: http://ifwiki.org/index.php/Hugor

Moderators: Ice Cream Jonsey, joltcountry

fleagor

name property

Post by fleagor »

Hello,

I apologize if any of this doesn't come across cleanly or clearly, this is my first time posting to one of these boards. I had a question about the behavior of the "name" property for rooms and objects, and this is using Hugo v3.1.01. Normally I would do this (and please bare with me):

Code: Select all

room testroom "test room"
{
	long_desc
	{
		" You are surrounded by unfinished code.
		Obviously whoever did this has no idea
		what he's doing."
	}
}
But assuming that I had gone temporarily mad and wanted to do it this way:

Code: Select all

room testroom
{
	name
	{
		"test room"
	}
	long_desc
	{
		" You are surrounded by unfinished code.
		Obviously whoever did this has no idea
		what he's doing."
	}
}
so that I could use different color properties, or if I went off the deep end and wanted a switch statement to randomize room names, or whatever, I run into a problem.

Instead of this:

Test room
You are surround by unfinished code, etc.

I get this:

Test room
.

You are surround by unfinished code, etc.

So in the second example I get a newline followed by a period, still bold. The status line displays "MORE..." then after pressing Enter, displays the aforementioned period as the room name.

How can I avoid the addition of that period and the "MORE..." issue?

I noticed a different situation when I tried to use the name property in a similar way on a plain object, but hopefully the answer to how to fix this will also apply to that. Otherwise I can relate that one as well.

Also, for future additions/changes to Hugo, how about adding a "color" formatting sequence to embed in printed strings? Something like

Code: Select all

\C(foreground,background)
So you could do \C(RED,BLACK) right in the middle of a line, you know, to cause eyestrain and irritation. I imagine it could have applications for the forces of good as well. Also, I'd like to vote for png support as an addition. I saw that one mentioned in another post.

Thanks,

fleagor

User avatar
Ice Cream Jonsey
Posts: 30193
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Post by Ice Cream Jonsey »

I am not sure about the color thing, but I had a similar concern with names being appropriate and not appropriate for characters.

I had one character I wanted to turn into a ghost, but I didn't want that character to be able to be called a ghost until the time was right. The solution was this for starters:

Code: Select all


female_character Sydney "Sydney"
{
  charnumber 10
  maxhitpoints 100

  nouns "jessica" "" "" "" "drieden" "girl" "blond" "blonde" "jess"
  adjectives "jessica" "jess" 
}
The odd part is putting the "" characters there. What that does is essentially placehold so that later I can add the word "ghost" and "spirit" there. I was able to do that by putting

Code: Select all


Jessica.noun #2 = "ghost"
Jessica.noun #3 = "spirit"

In a routine that got called when the character changed.

Can this same principle work for room names?!!? I just happen to have the barebones of a new Hugo game going in another window, so I'm-a-gonna try it and I'll get right back to you in this thread with what I find.
the dark and gritty...Ice Cream Jonsey!

User avatar
Ice Cream Jonsey
Posts: 30193
Joined: Sat Apr 27, 2002 2:44 pm
Location: Colorado
Contact:

Post by Ice Cream Jonsey »

OK, this should work:

1) Setup your room as follows:

Code: Select all

room testroom ""
{ 

   long_desc 
   { 
      " You are surrounded by unfinished code. 
      Obviously whoever did this has no idea 
      what he's doing." 
   } 
}
And then set up a routine to give it a name. (You mentioned that you wanted it to randomize the room name, for instance.)

Code: Select all

routine RandomizeRoomName
{
  local x

  x= random(3)

  select(x)

  case 1
  {
     testroom.name #1 = "TestRoom1"
  }      

  case 2
  {
     testroom.name #1 = "TestRoom2"
  }

  case 3
  {
     testroom.name #1 = "TestRoom3"
  }
}
I think that should work for getting random names for your room in there.


--Robb
the dark and gritty...Ice Cream Jonsey!

Cryptonomic
Posts: 55
Joined: Wed May 05, 2004 4:35 am
Location: Chicago, IL
Contact:

Post by Cryptonomic »

Speaking just to the original post, if I have this:

Code: Select all

room testroom
{
   name "test room"

   long_desc
   {
      " You are surrounded by unfinished code.
      Obviously whoever did this has no idea
      what he's doing."
   }
}
it works fine. Note the only difference is I did not include { } characters around the name property.

Further, I could then do something like this:

Code: Select all

room testroom
{
   name "test room"

   long_desc
   {
      " You are surrounded by unfinished code.
      Obviously whoever did this has no idea
      what he's doing."
   }

   before
   {
      location DoSmell
      {
         testroom.name = "smelly test room"
      }
   }
}
Now if I type "smell" in the room, the name of the room will be changed to "smelly test room". Of course, you could also call a routine and do any randomizing you wanted.

fleagor

more name mayhem

Post by fleagor »

Wow, thanks for the fast replies! After looking at both your responses I thought I would try the sure-fire method for triggering the random room name routine, and by gods it worked!

As an added bonus, you guys pointing me toward routines showed me the way to do differently colored room titles. I'm sure it isn't the prettiest way, and maybe something could be done to make it easier to apply to an entire world, but I don't really know programming.

Code: Select all

room testroom ""
{
	long_desc
	{
		color DEF_FOREGROUND
		"Here lie words."
	}
	before
	{
		location DoLookAround
		{
			color YELLOW
			return RandomizeRoomName
		}
	}
}
A random room name every time you look, and in vibrant yellow! Thanks for the help.

I also found that I could replace the room class with a version that contains the before routine above so that I could have every title of every room in the same color, and handled all automatic for me, but I still had to insert a "color DEF_FOREGROUND" at the beginning of each long_desc to bring it back to the normal color.

I tried inserting

Code: Select all

long_desc
	{
		color DEF_FOREGROUND
		""
	}
}
into my new room class but it didn't catch the color call.
If you see a better or cleaner way to do this, or any other feedback/ideas, I'd appreciate it.

fleagor

Merk
Posts: 192
Joined: Mon Nov 22, 2004 3:19 pm
Location: Wichita, KS
Contact:

Post by Merk »

Wouldn't that only make the title color yellow when you look? If you enter the room for the first time, that code shouldn't even run... You would need to add an each_turn { } section to the room, remember what the last room was, and then run the code if the last room changed *or* if the "lookaround" verb was used. I did something a little different in TP. When I needed to do things like that (displaying the available directions when the wristwatch is in COMPASS mode, for instance), I had a variable called "roomdesc_seen" in every room. It would flip back to false in the next loop, so I could always tell whether or not the user had just viewed the room description -- whether they entered the room or typed "look". Using the last_room (or something) variable I added, I could also track movement even in terse mode. Worked pretty well.

As for the color changing thing, the reason you couldn't do it in your class is because the room description in each room overrides the one in the class. These things add to the class, but if something is already defined in the class, the newer version replaces it instead.

Cryptonomic
Posts: 55
Joined: Wed May 05, 2004 4:35 am
Location: Chicago, IL
Contact:

Post by Cryptonomic »

You can basically do what you are describing. Here is one example I did based on what you are describing:

Code: Select all

class twistypassage
{
  is light
  long_desc
  {
    color DEF_FOREGROUND
    "These are twisty passages."
  }
  before
  {
    location DoLookAround
    {
      color YELLOW
      return RandomName
    }
  }
}
So there is my class. Now here is a room derived from that class:

Code: Select all

twistypassage Passage
{
  long_desc "It is hard to tell this room from any other."
}
Then almost the same routine for randomizing given earlier:

Code: Select all

routine RandomName
{
  local x
  x = random(3)
  select(x)
    case 1
    {
      self.name = "Twisty"
    }
    case 2
    {
      self.name = "Twistier"
    }
    case 3
    {
      self.name = "Twistiest"
    }
}
That seems to work for me in that I get a random name and it is colored yellow, including on the first time in the room.

Merk
Posts: 192
Joined: Mon Nov 22, 2004 3:19 pm
Location: Wichita, KS
Contact:

Post by Merk »

Your room text returns to the normal color after the yellow title? I thought that your replacement of the long_desc{} would override your class def....??

Cryptonomic
Posts: 55
Joined: Wed May 05, 2004 4:35 am
Location: Chicago, IL
Contact:

Post by Cryptonomic »

Merk wrote:Your room text returns to the normal color after the yellow title? I thought that your replacement of the long_desc{} would override your class def....??
Yup. You are correct. My apologies. Let me look at this a bit more.

Merk
Posts: 192
Joined: Mon Nov 22, 2004 3:19 pm
Location: Wichita, KS
Contact:

Post by Merk »

The only way I can think of that would let it work as a class is if the class had this:

Code: Select all

long_desc {
    color DEF_FOREGROUND 
    PrintRoomDesc(self)
}
You would then make a "PrintRoomDesc" routine with a handler for each room. Alternately, you could just add another property to the list... for instance "room_descr" -- put the real room description in the room_descr property for each object, and instead of calling PrintRoomDesc(self) just call self.room_descr instead. Should work too.

Merk
Posts: 192
Joined: Mon Nov 22, 2004 3:19 pm
Location: Wichita, KS
Contact:

Post by Merk »

In essence (and I'm not actually running this -- and it has been a few weeks since I coded anything, so please excuse if it turns out this is wrong):

Code: Select all

property room_descr

class twistypassage 
{ 
  is light 
  long_desc 
  { 
    color DEF_FOREGROUND 
    self.room_descr !Print real description
  } 
  before 
  { 
    location DoLookAround 
    { 
      color YELLOW 
      return RandomName 
    } 
  } 
} 

twistypassage SomeRoom ""
{
    room_descr {
        "Blah blah, a twisty room, like the others."
    }
}

Cryptonomic
Posts: 55
Joined: Wed May 05, 2004 4:35 am
Location: Chicago, IL
Contact:

Post by Cryptonomic »

Merk wrote:Alternately, you could just add another property to the list... for instance "room_descr" -- put the real room description in the room_descr property for each object, and instead of calling PrintRoomDesc(self) just call self.room_descr instead. Should work too.
Right - I find that works and is probably the better solution. I tried it out and that seems to work perfectly well.

fleagor

Post by fleagor »

Merk wrote:Wouldn't that only make the title color yellow when you look? If you enter the room for the first time, that code shouldn't even run...
You're sort of right here. It gets run in color the first time, since I believe the parser just calls a DoLookAround, but when it displays things in compact mode, as per a subsequent visit to the room, it reverts to the default color. Good point though.

Back to the drawing board.

Merk
Posts: 192
Joined: Mon Nov 22, 2004 3:19 pm
Location: Wichita, KS
Contact:

Post by Merk »

You will probably need to change it back in the each_turn routine. If this isn't something you use for your rooms, then you can add each_turn {} to the room class definition and then it will be changed to default after the room description, whether it's printed or not.

fleagor

Post by fleagor »

I'll definitely give the each_turn routine a shot. It'll probably be a couple days before I'll have time again to work on this though. I just wish I could figure out what was causing the behavior with the name property, with it outputting the newline and period. If I could get around that then I could do what you did with the room_descr property in the long_desc, only for the name. Very nice solution you came up with, by the way.

Cryptonomic
Posts: 55
Joined: Wed May 05, 2004 4:35 am
Location: Chicago, IL
Contact:

Post by Cryptonomic »

fleagor wrote:I just wish I could figure out what was causing the behavior with the name property, with it outputting the newline and period.
I am not sure about your progress on the overall issue here but this issue is probably based on the one I mentioned above in my earlier post. If you use a name property routine (with curly braces, { }) you are going to get that period and newline. (I cover this in the tutorial I wrote as well, so hopefully I am right on this!) If you make the name property just a "regular" property (what I am starting to call a "property set") and not a property routine, you should be okay - at least in terms of not getting the newline and period.

fleagor

Post by fleagor »

My progress has been approximately zero since last time; I kind of chalked it up to asking for the impossible. I had really hoped I could do something like Merk's solution for long_desc by creating a different property room_descr, but to no avail.

How would I go about making the name property a property set (I imagine this will open a whole different can of worms, but I'm still curious)? I didn't know there was a way to replace properties like you can with classes, or maybe I'm not quite following what you're saying. Also I noticed that "name" is one of the few compiler-defined properties, does that change things?

fleagor

Post by fleagor »

Cryptonomic,

I'm in the process of reading through your "Crafting a Hugo Game - Part 2", and it explains everything! Thanks for the detailed write-up, and I also wanted to say good job on making the whole thing easy to follow.

Post Reply