Howdy, Stranger!

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

: bad expression: Invalid left-hand side in assignment

Sugarcube: The following throws a "(Error: <<print>>: bad expression: Invalid left-hand side in assignment)" error. 

<<print "[[Open door" + "|Sorter1][$CurrentPos.LocEntry[3] =" + 5; + $CurrentPos.LocWall[3] = 5; + $Reset = true; + $DoorOpened=true + "]]">>

What does this mean?

Comments

  • It means you're terminating your expression in the middle of it, causing the string concatenation operators to be seen on the left-hand side of an expression (i.e. the &quot; + 5; + bitthe semi-colon terminates the current expression, which starts a new expression with the string concatenation operator).  You're also missing some quotes and string concatenation operators.

    In fact, why are you even using &lt;&lt;print&gt;&gt; there?  Based on your code, you don't need it.  You could simply do this:

    [[Open door|Sorter1][$CurrentPos.LocEntry[3] = 5; $CurrentPos.LocWall[3] = 5; $Reset = true; $DoorOpened = true]]
    You'd only need to use &lt;&lt;print&gt;&gt; in a situation like that if you wanted to force the early evaluation of a $variable, which you aren't doing (in that code anyway).
  • I found out what i was doing wrong after, all fixed. It wasn't a value passing failure but bad logic on my part (it would take a bit to explain it all) but my brain is functioning better this morning.

    Originally I did try that normal link code method and what i was trying to achieve wasn't working so i wrongly assumed that you couldn't have [] within the link|passage code because it uses them, i was assuming it wasn't passing the values.
    So i thought i'd try and use the print method to get around the what i thought was happening. But i was wrong..so wrong.
    My brain needed to come up for air lol.

    Sorry about that, but thanks for replying you helped me realize my error. 
  • Dazakiwi38 wrote:

    Originally I did try that normal link code method and what i was trying to achieve wasn't working so i wrongly assumed that you couldn't have [] within the link|passage code because it uses them, i was assuming it wasn't passing the values.


    As you've discovered, you can use square brackets within the wiki-text link or image markup (at least in SugarCube, I'm uncertain if the vanilla headers allow it).  There is a limitation to that, however.  Using square brackets (either array literals or property access using the square bracket notation) inside the wiki-text markup is allowed as long as they do not make the markup ambiguous, which basically means don't let them touch the square brackets of the markup.

    In other words:

    // WRONG: The closing square bracket of the array touches the closing pair of the markup, making them ambiguous.
    [[Go where?|There][$list to ["A", "B"]]]

    // CORRECT: The closing square bracket of the array is separated from the closing pair of the markup by a space.
    [[Go where?|There][$list to ["A", "B"] ]]
Sign In or Register to comment.