I don't know how to shorten what I want but it's got to do with variables and choices

+1 vote
asked Aug 10 by AnoeticDuckling (1,930 points)
edited Aug 10 by AnoeticDuckling

Using Sugarcube 2

I really struggled shortening this to put it into a title, but I gave up, so here's my long af description

I want to a variable to be called $name and I want to use this many times, but I want this variable to be set by the user through a simple selection. I have two names I want to be available, Adam and Eve. Throughout the story I want to be able to call upon whatever name they chose with a simple $name, instead of using things like (however you put it in sugarcube, I put it in harlowe as that's what I'm most familiar with) 

(if: $name is "Adam")[Adam is your name]
(if: $name is "Eve")[Eve is your name]

or 

(if: $nameAdam is true)[blah blah]
(if: $nameEve is true)[blah blah]

I don't yet know how to put that in via sugarcube as I'm learning things as I need them or think of them. I don't want to assign separate variables for what they chose like $nameAdam or $nameEve because then I'll have to have if statements every time I want to say their name and that's annoying, but I'll do it if necessary.

I also want to assign another variable based on what they didn't choose. I want when Adam is chosen by the player, Eve will be given to the narrator and vice versa.

Also, I want some text to show up after the player makes a decision between the two names. So it's in the same passage. Would a text box, button, check box, radio button, or something else be best for something like this? I'm thinking a button would make this easier, but what do I know?

1 Answer

+1 vote
answered Aug 10 by Chapel (27,390 points)
selected Aug 10 by AnoeticDuckling
 
Best answer

Seems like you're way overthinking this. Try something like: 

::StoryInit
<<set $name to ''>>
<<set $otherName to ''>>

::somepassage
Choose your name: 

[[Adam|nextpassage][$name to 'Adam'; $otherName to 'Eve']]

[[Eve|nextpassage][$name to 'Eve'; $otherName to 'Adam']]

::nextpassage
Your name is $name. The other name is $otherName. 

It's possible I'm misunderstanding you, but that's really all there is to it. Note that I wrote this code from memory and didn't test it. 

Also, I want some text to show up after the player makes a decision between the two names. So it's in the same passage. Would a text box, button, check box, radio button, or something else be best for something like this? I'm thinking a button would make this easier, but what do I know?

I'm not quite sure what you mean, or how your selection works. Can you provide an example of what this might look like? 

commented Aug 10 by Chapel (27,390 points)
CHOOSE YOU NAME!!!!!!!!!! That's what I get for copying/pasting over and over.
commented Aug 10 by greyelf (31,160 points)
Cut-N-Paste: Type once, make the same mistake/error everywhere. LoL
commented Aug 10 by AnoeticDuckling (1,930 points)
Thank you both. Perhaps about the typed transition there's a way to assign all text in the css to use a transition?
commented Aug 10 by Chapel (27,390 points)
That's not really the issue, I don't think. The issue seems to be that the beginning of the animation is tied to the rendering process. This means that text that is delayed for any reason (timing, interaction, etc) isn't typed because it essentially missed its window (i.e. it isn't rendered with the rest); the transition is treated as though its already over when the text hits the page, and I'm not sure how to arbitrarily restart it.

You seem like a cool person, but I don't use typed.js or the integration module in my own stuff, so I'm not really willing to take the time it'd require to read the code and figure out a work-around (and I'm only guessing at the issue anyway). That said, the code's author/the developer of sugarcube has been known to stop by and answer questions, and I know some other people here use it, and there are other talented devs around as well, so all hope isn't lost. You might need to create a new question specifically about using typed.js with <<timed>> and <<replace>> macros though, since this question's title isn't really attracting the kind of expertise you need.
commented Aug 10 by AnoeticDuckling (1,930 points)
That's chill, I was only asking if was something known or not. Thank you for stopping by and being so helpful in the first place. I understand your explanation and that makes sense. I'll play around with it some more and do some more searching before I post another question about the typed transition.

Thanks so much for your help Chapel! You're like the second most awesome person ever!
...