For a visual feedback system, I want to highlight <td>s in a table to show the player their development:
<<set $path to [1,2,1,2,2,3,1,2,1,2]>>
<table id="eval">
<tbody>
<tr>
<td> </td>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>sum</td>
</tr>
<tr>
<td>Level 5</td>
<td id="4x1"> </td>
<td id="4x2"> </td>
<td id="4x3"> </td>
<td id="4x4"> </td>
<td id="4x5"> </td>
<td id="4x6"> </td>
<td id="4x7"> </td>
<td id="4x8"> </td>
<td id="4x9"> </td>
<td id="4x10"> </td>
<td><<print $path.count(4)>></td>
</tr>
<tr>
<td>Level 4</td>
<td id="3x1"> </td>
<td id="3x2"> </td>
<td id="3x3"> </td>
<td id="3x4"> </td>
<td id="3x5"> </td>
<td id="3x6"> </td>
<td id="3x7"> </td>
<td id="3x8"> </td>
<td id="3x9"> </td>
<td id="3x10"> </td>
<td><<print $path.count(3)>></td>
</tr>
<tr>
<td>Level 3</td>
<td id="2x1"> </td>
<td id="2x2"> </td>
<td id="2x3"> </td>
<td id="2x4"> </td>
<td id="2x5"> </td>
<td id="2x6"> </td>
<td id="2x7"> </td>
<td id="2x8"> </td>
<td id="2x9"> </td>
<td id="2x10"> </td>
<td><<print $path.count(2)>></td>
</tr>
<tr>
<td>Level 2</td>
<td id="#1x1"> </td>
<td id="1x2"> </td>
<td id="1x3"> </td>
<td id="1x4"> </td>
<td id="1x5"> </td>
<td id="1x6"> </td>
<td id="1x7"> </td>
<td id="1x8"> </td>
<td id="1x9"> </td>
<td id="1x10"> </td>
<td><<print $path.count(1)>></td>
</tr>
<tr>
<td>Level 1</td>
<td id="0x1"> </td>
<td id="0x2"> </td>
<td id="0x3"> </td>
<td id="0x4"> </td>
<td id="0x5"> </td>
<td id="0x6"> </td>
<td id="0x7"> </td>
<td id="0x8"> </td>
<td id="0x9"> </td>
<td id="0x10"> </td>
<td><<print $path.count(0)>></td>
</tr>
</tbody>
</table>
<<for $i to 0; $i lt $path.length; $i++>>\
<<set $index to $i+1>>\
<<set $id to "#" + $path[$i] + "x" + $index>>\
<<addclass $id "green">>\
<</for>>\
I get the error
Error: <<addclass>>: no elements matched the selector "#2x4"
for each combination. I was wondering if the "#"-sign was the issue or am I addressing the <td>s incorrectly?
Comments
You need to use some method to delay the running of your for loop, one of these methods is to use a Task Object like postdisplay.
Using the PassageDone special passage: I used a temporary variable here to keep the variable store clean.
Using a postrender task: (goes in Story JavaScript)
Can I bother you with another thing? I have another array $answerLog that stores, whether the questions have been answered correctly or incorrecty. The indexes match those of $path.
Could you help me <<addclass>> two different classes, let's say "red" and "green", depending on the contents of $answerLog?
You say that the indices are the same. Will the selectors be the same as well (e.g. "#2x4") or is this for something else?
So my $path-array holds the levels at which questions were answered.
$answerLog has the same size and contains 'true' or 'false' at the same index, reflecting if the questions were answered correctly or not.
The respective index+1 could be read as the round (1 through 10), thus corresponding to the last digit of the <td>-ids in the above table.
e.g.: would mean that:
etc.
So the selectors will be the same, $answerLog determines, which class should be added.
(red for false, green for true).
Thank you!
Try:
Though if you really need it in a passage you can get away with a tiny break created with <<timedcontinue 0.1s>>.