Howdy, Stranger!

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

[Sugarcube 2] - Using a button to check a variable

In the code below, am I attempting this in a way that is even remotely correct? Should the button be wrapped in a <<click>> macro or something similar?
<<if visited("Instructions")>>
{{{>> }}}Before we go any further, I'd like to know a little more about you. What is your name, young adventurer?
<<else>>\
{{{>> }}}Welcome to the land of Terra. Allow me to introduce myself. I am Az'rha and I will be your guide through this adventure. Before we go any further, I'd like to know a little more about you. What is your name, young adventurer?
<</if>>\
<span id="name">{{{>> }}}<<textbox "$playerName" "" autofocus>></span><span id="button"><<button "Enter">><<replace "#output1">>You say your name is $playerName, correct? Remember, you will be unable to change it later. &#8594; <<click "Yes">><<replace "#output2">>It is nice to meet you, $playerName.<</replace>><<replace "#output3">>[[Continue &#8594;|characterCreation2]]<</replace>><</click>><</replace>><</button>></span>

<span id="output1"></span>
<span id="output2"></span>
<span id="output3"></span>

Comments

  • I just ran the code:
    <span id="output1"></span>
    <span id="output2"></span>
    <span id="output3"></span>
    
    <span id="name">
      {{{>> }}}<<textbox "$playerName" "" autofocus>>
    </span>
    <span id="button">
      <<button "Enter">>
        <<replace "#output1">>
          You say your name is $playerName, correct? Remember, you will be unable to change it later. &#8594; 
          <<click "Yes">>
            <<replace "#output2">>
              It is nice to meet you, $playerName.
            <</replace>>
            <<replace "#output3">>
              [[Continue &#8594;|characterCreation2]]
            <</replace>>
          <</click>>
         <</replace>>
       <</button>>
    </span>
    
    And it seemed fine. Output image is attached.

    What is it not doing that you want it to do?
  • Also, I'm pretty sure <<click>> is deprecated. You should probably be using <<link>>, just FYI.
  • edited February 2017
    Clicking the button doesn't do anything; literally nothing changes. I also didn't know that about <<click>>. I scanned <<link>> briefly in the documentation but haven't used it. Is it more or less the same as <<click>> in practice? Also, I copy/pasted your code and it doesn't work for me. I genuinely don't understand what I'm doing wrong.
  • Hm. Well, we can isolate the problem. First thing's first, can you humor me and start a new story file, without any edits to your CSS and JS and run the code and see if it works there? It's possible that some wires got crossed somewhere else, considering the code works for me in an otherwise empty file.

    Second thing is to see what your #button element is up to and make sure it's not anything crazy. It's likely that the text you're putting into #output1, etc is also taking on those properties, since the text is originating from inside that span.

    If I had to guess, I'd guess that something is mixed up in the CSS somehow, like the #button text color is the same as the #output background color; something like that.

    And yes, <<link>> is functionally identical to <<click>>. You can just run a find/replace through your code to change over. I don't know if it's a big deal, but support for it could go away in future versions of SugarCube, so I'd at least stop using it going forward.

    And just so we're on the same page, here's the code as it's running for me, compiled to html and attached. It's possible that my definition of working is not the same as yours, so I just want to make sure we're on the same page there.

    My output spans are above the code, ignore that--shouldn't matter.
  • I'm so embarrassed I could die. Just before I came back here to check, I doubled-checked my CSS and I had outputs 1-5 set to "display: none". I had forgotten that I had set it that way awhile back for something else I was attempting. Thank you so much for your help!
  • historic66 wrote: »
    I'm so embarrassed I could die. Just before I came back here to check, I doubled-checked my CSS and I had outputs 1-5 set to "display: none". I had forgotten that I had set it that way awhile back for something else I was attempting. Thank you so much for your help!
    Haha. There's no embarrassment here. Glad you figured it out!
Sign In or Register to comment.