If you are requesting technical assistance with Twine, please specify:
Twine Version: 2.3.13
Story Format: Sugarcube 2.34.1
Hi everyone. I’m having trouble getting an array - $Record - to print without commas. I would like it to print each record on a new line (working) but each line with adjustable spaces if possible (for adding to a table).
Below is a sample of the current code (printing with commas)
As far as I know when you print an array in sugarcube, it’s always written in the form you’ve met, with commas between each members of the array.
However you can write an individual member of an array. For instance your array $Record is currently two arrays.$Record[0], itself an array consisting of 1,“Farming”,1 and 10, and $Record[1], again an array, consisting of 2,“Mining”,4 and 20.
As writing in each cell of your table the exact member of $Record will be both boresome and prone to provoke errors in the long run, here’s a code that should allow to build your table:
<table><tr><td><b>Day</b></td><td><b>Sector</b></td><td><b>Number</b></td><td><b>Value</b></td></tr>
<<for _i to 0;_i<$Record.length;_i++>><tr><<for _ii to 0;_ii<$Transaction.length;_ii++>><td><<if _ii<$Transaction.length-1>>$Record[_i][_ii]<<else>><<print "$"+$Record[_i][_ii]>><</if>></td><</for>></tr><</for>></table>
The first part of the code creates the title row, then the second part runs two nestled loops, one for each line, and one for each cell of the line. I’ve added a a test for the monetary value to add ‘$’ before the value, it will allow to keep the member of the array as a numeric variable.