Twine 2 Sugarcube simple array confusion

When I run this:

<<set $Wealth to 2>>

<<set $WealthQualty to ['destitute', 'poor', 'of average wealth', 'prosperous', 'wealthy']>>

Wealth: Your level of wealth is <<print $WealthQuality[$Wealth]>>

I get “Cannot read property ‘2’ of undefined”

Since the variable of $WealthQuality is 2, I expect to get back “Your wealth level is of average wealth”. What am I missing?

Thanks, gang.

Looks like you misspelled $WealthQuality?

Or maybe you misspelled $WealthQualty. :)

As Andrew said, it should be:
<<set $WealthQuality to
with an “i”.

Lots of times the worst “stumpers” when debugging code are the tiniest letter, space, or punctuation errors, since they’re so easy to miss. In college I helped one friend debug some code that he’d stared at for three hours unable to fix. I spent an hour looking at it before I saw the problem, and it turned out it was a single out-of-place space (* / instead of */) which caused a chunk of code to be incorrectly commented out.

Have fun! :slight_smile:

As a matter of fact with variables it’s usually a good idea to use and abuse the copy/paste function.

Oh my goodness. Thanks, guys. What a silly thing to overlook. I stared at this thing for hours. Well, it worked, so at least I know I’m on the right track!