Assigning array elements

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

Bainespal
Posts: 151
Joined: Fri Jul 09, 2010 8:59 am

Assigning array elements

Post by Bainespal »

Arrays are one programming construct that I never understood very well in either Hugo or Inform. Right now, I'm trying to make two scenery objects with blank noun and adjective properties, and then to assign dictionary words at a point in the game so that the player will be able to refer to these objects at the right time but not before. I can't simply move the objects to the location when I need them, because they both span two or more rooms, using the found_in property. So, I leave them alone but don't mention them or give them any keywords until I'm ready to set them up.

I saved the lists of keywords that I want to end up as nouns/adjectives for the objects into four arrays -- one for each object's noun and adjective properties. I tried making the noun and adjective properties routines that would return the arrays if the right condition was met or would return false otherwise. Then I tried leaving the noun and adjective properties completely empty (nothing but a new line after the word "noun" in the code) and assigning their values to the arrays in a different routine somewhere.

Looking to the Hugo Book, I saw where it says that "entire arrays passed as arguments" are illegal. Then, I tried setting each keyword one at a time in the routine that makes the changes to the game state when the two scenery objects become available to the player. I left blank "slots" in the noun/adjective property definitions, like this:

Code: Select all

noun 0, 0, 0, 0
Then I tried setting them with something like this:

Code: Select all

object.noun[0] = "sky": object.noun[1] = "sun": object.noun[2] = "clouds"
That still didn't work. It doesn't even give any different results at all then my previous attempts did.

Thank you, and sorry for being so long-winded. I'm being a little ambiguous about the content of my project because I'm holding out for a slim hope of entering it in the IF Comp if I get done in time.

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

Post by Roody_Yogurt »

Yeah, no, you're getting properties confused with arrays (which is understandable since they are kind of similar looking and there are problems you could solve using either approach).

First off, read this: http://hugo.gerynarsabode.org/index.php ... properties

Basically, the syntax you'll be wanting to use is:

Code: Select all

object.noun #1 = "sky": object.noun #2 = "sun"
object.noun #3 = "clouds"
Sorry for the delay on this. I have been moving my files over to a new computer the last couple days.

Bainespal
Posts: 151
Joined: Fri Jul 09, 2010 8:59 am

Post by Bainespal »

I never questioned my assumption that the noun property contained an array as its value. I think I just understood arrays as far as being lists of values. Or maybe I was remembering Inform 6 -- I vaguely remember seeing examples in the Inform Designer's Manual about manipulating object keywords as array entries, I think.

Anyways, it works now -- which is totally awesome! By the way, that HxE article is very informative; properties in Hugo are more flexible than I thought they were. It turns out this was all simpler than I'd imagined. :)
Roody_Yogurt wrote:Sorry for the delay on this. I have been moving my files over to a new computer the last couple days.
No, I'm sorry for bothering you again. You really don't have to help me, you know, but I appreciate it. Anyways, I still have a little more of the initial implementation to do; I knocked off another NPC in the meantime.

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

Post by Roody_Yogurt »

Yeah, properties are pretty flexible. It is interesting to look at other people's code to see how they like to handle things. ICJ handles a lof of his problems with arrays while Kent Tessman does a lot of stuff with properties resulting in weirdly-specific property-manipulating routines like PropertyList that I doubt anyone else has yet used (although I'm still trying to think of situations where I'd need it).

Both ways show that you can often write a routine to sort and deal with your property or array however you like.

Anyhow, no worries about the trouble. It is good to know that other people are working on Hugo code, and I am happy to help out, especially as you try to meet the comp deadline.

Post Reply