If you are requesting technical assistance with Twine, please specify:
Story Format: Sugarcube
Hello everyone, I am having trouble with a basic set command. Everything around this works, but this one in particular, the description of clothing, doesn’t appear. It just prints out $itemdesc, instead of the actual variable I have set for $itemdesc . Here is the part of the code in the storyinit passage
<<if $playeroutfit === 'Work Clothes'>>
<<set $outfitdesc to "A light blue string crop top with jean shorts.">>
I have the other options under elseif’s, and a closing /if tag at the end.
Here is the passage under the equipment stats, that the player can click on and look through.
So the $playerweapon and $playeroutfit variables both work as they should, but for some reason the outfitdesc just literally prints out ‘$outfitdesc’.
I did the quick find to make sure there was no other $outfitdesc in any of the other passages that could be overwriting the storyinit, and it only appears in the equipment passage and storyinit.
I have no idea what I did/am doing wrong. Any help is greatly appreciated.
Thanks for the response,
I tried the eq, but that didn’t work.
I did remove the single parentheses, but now it’s just saying [undefined].
Does this mean that there’s something wrong with what I have in the StoryInit passage?
What’s in the Storyinit passage? Since it says “undefined” that means the variable isn’t getting set - either in storyinit, or in your <<if $playeroutfit ===[…]>> passage. Make sure you’re setting the variable in Storyinit as a string $playeroutfit = "nothing" or $playeroutfit = "" and not just $playeroutfit = false - if the variable type doesn’t match (string vs. boolean) I don’t believe it can set to different type.
I’m not sure about whether single and double quotes are completely synonymous, as far as I know they are… but I’ve noticed if I use single quotes in something like <<print either (‘one’, ‘two’, ‘three’)>> I can’t use a contraction unless I start with double quotes <<print either(“You can’t.”, “You won’t.”)>>
if/else can be tricky sometimes, especially when there’s complicated nesting.
I’d recommend hitting Play in the IDE and track your $playeroutfit and $outfitdesc variables using the “bug” pane on the lower right as you go through the relevant passages. You can at least track if the variable isn’t getting set in the Storyinit somehow, or if it’s missing in the “if===” passage.
This is the full storyInit passage. The $playeroutfit set works perfectly, so I may just give up and bundle the description right after the outfit. (mildly adult content warning) //outfits// <<if $playeroutfit === 'Work Clothes'>> <<set $outfitDescription to "A light blue string crop top with jean shorts.">> <<elseif $playeroutfit === 'Evening Dress'>> <<set $outfitDescription to "A nice jade-green number that goes down just barely past the mid thighs. It's folded front leaves a lot of $name's thighs exposed.">> <<elseif $playeroutfit === 'Maid Outfit'>> <<set $outfitDescription to "An outfit based on old school french maid wear. The amount of frills and exposed skin do a lot for some people. Not recommended for actual cleaning.">> <<elseif $playeroutfit === 'Leather Armour'>> <<set $outfitDescription to "Basic leather armour thick enough to deflect some rather weak blows, but only (barely) covers the vital organs. Looks more like an outfit from some questionable anime series your smelly cousin loves.">> <<elseif $playeroutfit === 'Chainmail'>> <<set $outfitDescription to "Don't kid yourself. This does literally nothing. Its barely a bikini. If it somehow manages to block anything I will be very surprised. Made from metal so it won't stain, so it has that going for it. Which is nice.">> <</if>>
Just to add on to what Hanon was saying, please be aware that <<if>> macros and the like don’t normally hang around and do things later on if the conditional part changes. They only do something at the single moment they’re first executed. You’ll need to run them again at any point where you might need them to do whatever it is that you want them to do.
Hope that helps clear things up, if that’s what you were thinking.
Bro, you guys are so smart.
I took that whole passage out of storyinit, and now it’s working.
I am now going to try and make a listbox in the equipment passage that lets the player put on the various armors and clothes they pick up. If you guys have any suggestions, I would love to hear it!
Rather than using an <<include>> macro like that, it would probably be better to make it into a custom SugarCube widget instead, since then you could have it set everything appropriately based on the value passed to the widget.
To make a widget like that, create a non-special passage and give it “widget” and “nobr” tags (the latter so that it will ignore line breaks). Then put something like this in the passage:
<<set $playeroutfit = $args>>
<<case "Work Clothes">>
<<set $outfitDescription = "A light blue string crop top with jean shorts.">>
<<case "Evening Dress">>
<<set $outfitDescription = "A nice jade-green number that goes down just barely past the mid thighs. It's folded front leaves a lot of $name's thighs exposed.">>
Once you’ve filled in the “...etc...” part above with actual code, you’d then only need to do something like <<checkclothes "Work Clothes">> in your passages in order to set everything appropriately for the given outfit. (See also the <<switch>> macro documentation for details on how it works.)
Another thing you might do, instead of looping back to the same passage just to update the clothes description, you could instead update the displayed information directly when the link is clicked by tweaking Hanon’s code like this:
<<link "Put on the work uniform.">>
<<checkclothes "Work Clothes">>
The <<replace>> macro updates the content of the “clothes” <span> due to the ID passed to it ("#clothes" means “the element with an ID of ‘clothes’”).
Note that the two single-quotes around $playeroutfit in the above code is just markup to make it so that the text within will be displayed in bold, and the two backslashes (\) above are there to prevent unwanted line breaks (see here) while still keeping the code readable.
Try it out. Hopefully you’ll like the effect.
Please let me know if you have any questions about how any of that works.