Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

"Either" only choosing last option on specific variable

Hello! I've been trying to make a fantasy town generator with Twine.

Everything's worked fine up to this point, but I've been having a strange problem.

I'll break it down using the entire code I've got so far:
<<set $surface to either ("fresh green grass","dry sand","smooth plastic","rocky terrain")>>\
<<set $skycolor to either ("blue","red","green","bright white","dark black","colorful")>>\
<<set $housestype to either ("houses made of hay","houses made of brick","houses made of metal","houses made of wood","houses made of sticks and logs")>>\
<<set $howmanycreaturessummedup to either ("empty","few","moderate","crowded")>>\
<<if $howmanycreaturessummedup = "empty">> <<set $howmanycreatures to either ("Wind blows through the area. It's the only sound you hear","The place looks like nobody's lived there for a very long time","The only populace here is animals")>><<endif>>\
<<if $howmanycreaturessummedup = "few">> <<set $howmanycreatures to either ("Occaisionally you hear footsteps, but you don't see anyone","Sometimes you hear a whisper or two, but you don't see anyone","The population seems to be scarce here")>><<endif>>\
<<if $howmanycreaturessummedup = "moderate">> <<set $howmanycreatures to either ("There's a moderate amount of intelligent life here. Small enough not to crowd, large enough to not feel empty","The town's population number seems to be pretty average","The place isn't crowded, but not empty either")>><<endif>>\
<<if $howmanycreaturessummedup = "crowded">> <<set $howmanycreatures to either ("The town is so crowded you can barely see","The bustle of people is very loud","This place is so full it's a miracle that any houses are available at all")>><<endif>>\
You find yourself standing on <<$surface>>. Above you is a glorious <<$skycolor>> sky.

Around you are <<$housestype>>. <<$howmanycreatures>>.

Testing: <<$howmanycreaturessummedup>>

Kind of a mess, sorry.

Anyway, this is what I'm trying to do.

I want the passage to have random things plugged in, as the "either" function does.

$surface, $skycolor, and $housestype work perfectly fine in this regard.

Then I tried to get a little more complicated.

I wanted the next passage to detail the average amount of people/creatures present. But, I also wanted three different phrases for each average.

This is the section of the code where I attempted to do just that:
<<set $howmanycreaturessummedup to either ("empty","few","moderate","crowded")>>\
<<if $howmanycreaturessummedup = "empty">> <<set $howmanycreatures to either ("Wind blows through the area. It's the only sound you hear","The place looks like nobody's lived there for a very long time","The only populace here is animals")>><<endif>>\
<<if $howmanycreaturessummedup = "few">> <<set $howmanycreatures to either ("Occaisionally you hear footsteps, but you don't see anyone","Sometimes you hear a whisper or two, but you don't see anyone","The population seems to be scarce here")>><<endif>>\
<<if $howmanycreaturessummedup = "moderate">> <<set $howmanycreatures to either ("There's a moderate amount of intelligent life here. Small enough not to crowd, large enough to not feel empty","The town's population number seems to be pretty average","The place isn't crowded, but not empty either")>><<endif>>\
<<if $howmanycreaturessummedup = "crowded">> <<set $howmanycreatures to either ("The town is so crowded you can barely see","The bustle of people is very loud","This place is so full it's a miracle that any houses are available at all")>><<endif>>\

In theory, it should pick a random average, then pick a random phrase from that average.

But for some reason, no matter how many times I test, $howmanycreaturessummedup always picks "crowded", even when I rearrange the list. I even tried changing the name of the variable, but it didn't help.

I even tried bringing the passage into a brand new story, but it does the same thing.

I figure it's probably something incredibly obvious that I missed, but I just can't figure it out. Please help.

Comments

  • edited April 2017
    What story format are you using? I'm assuming Sugarcane.

    You need to use ==, ===, 'is' or 'eq' in <<if>> macros; using = will cause it to set the variable. So, your last statement is setting the variable to "crowded" every time. Additionally, since $howmanycreaturessummedup (this is a painfully long variable name) should ideally only have one value, you can use <<elseif>> statements instead of a bunch of <<if>>s.

    Something like this might be a little more human-readable and less error-prone:
    <<nobr>>
      <<set $howmanycreaturessummedup to either("empty", "few","moderate", "crowded")>>
    
      <<if $howmanycreaturessummedup is "empty">>
        <<set $howmanycreatures to either(
          "Wind blows through the area. It's the only sound you hear", 
          "The place looks like nobody's lived there for a very long time",
          "The only populace here is animals")>>
    
      <<elseif $howmanycreaturessummedup is "few">>
        <<set $howmanycreatures to either(
          "Occaisionally you hear footsteps, but you don't see anyone",
          "Sometimes you hear a whisper or two, but you don't see anyone",
          "The population seems to be scarce here")>>
    
      <<elseif $howmanycreaturessummedup is "moderate">>
        <<set $howmanycreatures to either(
          "There's a moderate amount of intelligent life here. Small enough not to crowd, large enough to not feel empty",
          "The town's population number seems to be pretty average",
          "The place isn't crowded, but not empty either")>>
    
      <<else>>
        <<set $howmanycreatures to either(
          "The town is so crowded you can barely see",
          "The bustle of people is very loud",
          "This place is so full it's a miracle that any houses are available at all")>>
      <<endif>>
    <<endnobr>>
    
Sign In or Register to comment.