This is the simplest version of my bars to use. The only variable that has to be specified is health, which will be the length of the bar. Outer 3 has been simplified because of this.\n\nTo include this in your twine project, copy Inner 3 and Outer 3 into it. You may rename them, but ensure everything still links to what it started with.\n\n<<set $health = 10>><<display 'Outer 3'>>\n<<set $health = 20>><<display 'Outer 3'>>\n<<set $health = 17>><<display 'Outer 3'>>\n\nThe above bars have 10, 20 and 17 health.
These bars run using the passages Outer 2 and Inner 2. The bars work exactly the same as in [[Demo 1]], except the symbol is not specified. It is "|", hard-coded into Inner 2. If you always intend to use the same symbol, the code should run slightly faster if you use this method rather than that shown in Demo 1.\n\nIf you are implementing this in your own project, you will need to copy the passages Inner 2 and Outer 2. You may rename them if you wish, but ensure the links between them remain intact.\n\n<<set $health = 30>><<set $increment = 5>><<display 'Outer 2'>>\n\nIn the above bar, health is set to 30 and increment is set to 5.\n\n<<set $health = 31>><<set $increment = 4>><<display 'Outer 2'>>\n\nIn this bar, health is 31 and increment is 4.\n
The bars on this page are using the passages Outer 1 and Inner 1. Each bar has three variables - health, which is what the bar is intended to measure, increment, which is the number represented by each unit of the bar, and symbol, which is what each unit of the bar is displayed as. Outer 1 prints the value of health for each bar, divides health by increment, and saves this value as block. It uses a ceiling function (Math.ceil, everyone loves a little javascript) so that if block is not an integer, it is always rounded up. If block is greater than 0, Inner 1 is fired off, which prints the symbol, subtracts 1 from block, and fires itself off if block is still greater than 0. By the time this stops calling itself, it has printed the symbol block times.\n\nIn order to implement bars like these in your twine project, you will have to copy the passages Outer 1 and Inner 1. You may wish to rename them in order for them to make sense in your passage structure, but remember to ensure all the links between them remain.\n\n<<set $health = 30>><<set $increment = 5>><<set $symbol = "O">><<display 'Outer 1'>>\n\nThe above bar has health at 30, increment at 5, and symbol at "O". I do not know whether the symbol requires quotation marks, but it's better to be safe than sorry, and has not let me down yet.\n\n<<set $health = 31>><<set $increment = 5>><<set $symbol = "O">><<display 'Outer 1'>>\n\nThe above bar has health at 31, increment at 5, and symbol at "O". It shows that if any rounding occurs, it is rounding up, as intended by the use of the ceiling function\n\n<<set $health = 15>><<set $increment = 3>><<set $symbol = "N">><<display 'Outer 1'>>\n\nThe above bar has health at 15, increment at 3 and symbol at "N". It shows 5 N, as expected.\n\n<<set $health = 7>><<set $increment = 10>><<set $symbol = "H">><<display 'Outer 1'>>\n\nThe above bar has health at 7, increment at 10, and symbol at "H". It shows one H, as health is greater than 0, but less than the increment value.
|<<set $health = $health - 1>><<if $health gt 0>><<display 'Inner 3'>><<endif>>
|<<set $blocks = $blocks - 1>><<if $blocks gt 0>><<display 'Inner 2'>><<endif>>
<<print $symbol>><<set $blocks = $blocks - 1>><<if $blocks gt 0>><<display 'Inner 1'>><<endif>>
This little twining was written to test / demo methods for drawing bars.\n\n[[Demo 1]] is the most complicated, allowing the most variables.\n\n[[Demo 2]]\n\n[[Demo 3]] is the least complicated, with the least variables.\n\nAll of these use the same method, recurring a passage using an if condition within itself, as suggested [[here|http://eturnerx.blogspot.co.uk/2012/11/twine-howto-loops.html]].\n\nThere is, as far as I know, only one bug in these bar charts. If health is set to 0, it will not be printed. If you know that a bar should represent zero, this can be worked around, but if it turns up in a variable, we're stuffed mate.
Kitbeard
Bar Chart Test
<<print $health>> <<set $blocks = Math.ceil($health / $increment)>><<if $blocks gt 0>><<display 'Inner 2'>><<endif>>
<<print $health>> <<if $health gt 0>><<display 'Inner 3'>><<endif>>
<<print $health>> <<set $blocks = Math.ceil($health / $increment)>><<if $blocks gt 0>><<display 'Inner 1'>><<endif>>