What I'm trying to do: In the project I'm working on the player assigns various tasks a given amount of time. Example: the player has forty hours to work with and can assign four hours to training, three hours building, nine hours to reading, etc. I am doing this via the click function of Sugarcube where a player adds or removes an hour from each task. When I click to add an hour I want it to change two variables (the task being changed and the overall time available) and display the change for both on the current screen.
The Problem: The variables are being modified just like I want (when I click to add an hour it does indeed add to that variable and subtract an hour from free time), the issue is display. I get the variable being modified (i.e. build) to display/update on screen, but have no idea how/if I can also adjust the appearance of the second variable being modified (free hours). What I would like is for at the top of the screen to be a display for free hours (time remaining) that gets updated as tasks below are modified.
Code:
Free Hours: <<print $freehours>>
Build Hours: <span id="buildhours"><<print $buildhours>></span>\
<<click "[+]">><<set $buildhours++, $freehours-->><<replace "#buildhours">><<print $buildhours>><</replace>><</click>> \
| <<click "[-]">><<set $buildhours--, $freehours++>><<replace "#buildhours">><<print $buildhours>><</replace>><</click>>
This is basically just a copy of the code from the sugarcube documentation with the words changed to my variables. Everything for build hours works like I want, but I have no idea what (if anything) I need to add to have the free hours display update with changes.
Thank you very much any help.
Comments
If you are using one of the SugarCube 2 versions then I suggest you look at the <<numberpool>> add-on, which is listed under Add-ons in the Downloads section of the main document page.
So if you are using Sugarcube 2.18.0 then that addon will work for you.
If you try out the set and it doesn't have the look you want, then I, or someone else, could show how to do it with a modified version of the above code I suppose.