Howdy, Stranger!

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

[sugarcube 2.x] Selector error with if statements...

Ok so I am trying to create a passage that shows different text based on which passage the player came from. I watched a tutorial explaining how to use <span> in conjunction with <<replace>> to replace text and it worked for the one I put on the title page but now that I'm using if statements it is giving me this error:
Error: <<replace>>: no elements matched the selector "#xArea"

I've tried a variety of things but they all seem to give the same error. This is the code as of this moment:
<span id="xArea">Error: invalid passage access. If you are seeing this please report it.
<<if $exArea == 1>>
<<replace "#xArea">>
You stand up from your cubicle and take a look at your surroundings. A busy day in the GETTO offices.
<</replace>>
<<else>>
<<replace "#xArea">>
Error: invalid area number. If you are seeing this please report it.
<</replace>>
<</if>>
</span>

Now I know there is probably a better way to go about this but this was all I could think up to do this atm. If anyone has a better method to achieve this then I'd greatly appreciate it if you'd tell me or at the least point me in the right direction. Also please note that there are no linebreaks in the code if that's even a factor, I just added them here for readability.

Comments

  • There are two issues with the way you are using the <<replace>> macro:

    1. You are using it within the xArea span element you want to modify.
    eg. the end span tag should be before the <<if>> macro.

    2. You are trying to replace the contents of the xArea span element before it has been added to the page being rendered, which happens after all the passage's content has been processed. This is why you are getting that error message.

    Is there a reason you are not doing the following?
    <<if $exArea == 1>>You stand up from your cubicle and take a look at your surroundings. A busy day in the GETTO offices.<<else>>Error: invalid area number. If you are seeing this please report it.<</if>>
    
  • greyelf wrote: »
    -Snip-
    1. The tutorial I looked at didn't go too much into the span element and they put the <<replace>> inside of span. So I just assumed I needed to put everything within the span tags.

    2. I have no idea what order all these commands are processed in, is there a reference or something somewhere?

    I didn't realize how much I was overcomplicating this. I thought I had to use <<replace>> to keep the player from seeing residual text. I'm guessing passages forget everything once you leave them except stuff you put in variables through <<remember>> and <<set>>?

    Thanks for the help, I really appreciate it.
  • shakey2 wrote: »
    1. The tutorial I looked at ...
    As I don't know which tutorial you mean, nor which Story Format it was written for, I can't say if it was correct or not.
    shakey2 wrote: »
    2. I have no idea what order all these commands are processed in, is there a reference or something somewhere?
    Not really.
    Generally the contents of a passage is processed from top to bottom but there are exceptions like the contents of <<click>> macros or Setter links which are processed when the related link is selected.
    shakey2 wrote: »
    I didn't realize how much I was overcomplicating this. I thought I had to use <<replace>> to keep the player from seeing residual text.
    The output the Reader sees is generated using the current Passage's contents, if content is gated by an <<if>> macro and it's condition is false then that content is not added to the output.
    shakey2 wrote: »
    I'm guessing passages forget everything once you leave them except stuff you put in variables through <<remember>> and <<set>>?
    Yes, using variables is how you normally pass information between passages. Generally you should not need to use the <<remember>> macro.
  • If you haven't already, I'd suggest checking out the SugarCube (v2) documentation.

    Additionally, I'll second greyelf on <<remember>>. Forget you ever saw mention of it. Ninety-nine times out of a hundred it is the absolute wrong tool for the job.
  • If you haven't already, I'd suggest checking out the SugarCube (v2) documentation.

    Additionally, I'll second greyelf on <<remember>>. Forget you ever saw mention of it. Ninety-nine times out of a hundred it is the absolute wrong tool for the job.

    I've had that document up the whole time. I haven't had time to give it a thorough study though, and some of it confuses me. I mean I have no idea what any of that "wiki" stuff actually does...
Sign In or Register to comment.