Howdy, Stranger!

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

Having trouble with making text clickable to change a variable but not move to another passage.

edited May 2016 in Help! with 2.0
I am trying to output variables from an array of objects into a chart and make each of the first variables in a row clickable to change another variable, but not move to another passage. here is the code below of what I have so far, and it gives me an error each time. This is in sugarcube also.

<<nobr>>
<<set $currentCity="5">>
/*formats a table to output $randomCity array*/
<table border="1" width="100%" height="0%">
<tr>
<th>#</th>
<th>$cityList[0].name</th>
<th>$cityList[0].population</th>
<th>$cityList[0].taxRate</th>
<th>$cityList[0].crime</th>
</tr>
<<for $x=1;$x<11;$x++>>

<tr>
<td>$x</td>
<td>
<<click $cityList[$x].name >><<set $currentCity =$cityList[$x].name>><</click>>
</td>
<td>$cityList[$x].population</td>
<td>$cityList[$x].taxRate</td>
<td>$cityList[$x].crime</td>
</tr>

<</for>>
</table>
$currentCity
<</nobr>>

Comments

  • You must capture the current value of $x where it's used inside of the <<click>> macro when it's constructed, since the inside gets executed much later whenever the player clicks and the value of $x then will likely either be out of bounds or some other value you don't want.

    FIND:
    <<click $cityList[$x].name >><<set $currentCity =$cityList[$x].name>><</click>>
    
    REPLACE WITH:
    <<print "<<click $cityList[$x].name>><<set $currentCity = $cityList[" + $x + "].name>><</click>>">>
    


    Additionally. Where you're initially setting $currentCity:
    <<set $currentCity="5">>
    
    If $currentCity is supposed to be a number, rather than the string you have it set as, then you need to set it like the following:
    <<set $currentCity = 5>>
    
    Actual numbers are not quoted.
  • Thanks for the help.
Sign In or Register to comment.