Changing cash

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

User avatar
Tdarcos
Posts: 9341
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Changing cash

Post by Tdarcos »

I'm trying to change the name of the item for cash that's in the User's pocket. I can't seem to concatenate a number to get

Code: Select all

property CashOnHand

object cash
{
        Cashonhand 10
        in you
        name
        {
             return "you have $" number cashonhand " cash"
         }
         is static
}

I can't get it to concatenate the symbols together so that when I do INVENTORY it would say "You Have $0 cash".  If I use a print statement instead of a return, I get two periods after the item.
"I really feel that I'm losin' my best friend
I can't believe this could be the end."
- No Doubt, Don't Speak

Roody_Yogurt
Posts: 2181
Joined: Mon Apr 29, 2002 6:23 pm
Location: Milwaukee

Post by Roody_Yogurt »

Yeah, name has to return a dictionary entry, so you could either add every conceivable dollar-amount-phrase to the dictionary table (I wouldn't do this) or go a different route altogether.

Personally, I would use the "inv_desc" property instead:

Code: Select all

property CashOnHand

object cash "cash"
{
Cashonhand 10
in you
inv_desc
{
print "You have $" number self.cashonhand " cash."
return true
}
is static
}
Now, when the player checks his inventory, he'll get:
You have $10 cash.
You are also carrying (rest of inventory).

User avatar
Tdarcos
Posts: 9341
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

Post by Tdarcos »

Roody_Yogurt wrote:Yeah, name has to return a dictionary entry, so you could either add every conceivable dollar-amount-phrase to the dictionary table (I wouldn't do this) or go a different route altogether.

Personally, I would use the "inv_desc" property instead:

Code: Select all

property CashOnHand

object cash "cash"
{
Cashonhand 10
in you
inv_desc
{
print "You have $" number self.cashonhand " cash."
return true
}
is static
}
Now, when the player checks his inventory, he'll get:
You have $10 cash.
You are also carrying (rest of inventory).
Thank you, it was perfect, with one exception. With yours, the output is
You have
$10
cash

It needed to be
print "You have $"; number self.cashonhand; " cash."

I had no idea it would insert newlines between items, I only thought it did that if you didn't end the line with a semi-colon, not if you didn't put one after each item.

But thank you otherwise, it's perfect and exactly what I wanted.
"I really feel that I'm losin' my best friend
I can't believe this could be the end."
- No Doubt, Don't Speak

Post Reply