Howdy, Stranger!

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

Sugarcube: Interactive Macro, Displaying Click Function for Two Variables

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

  • Try the following:
    Free Hours: <span id="freehours">$freehours</span>
    
    Build Hours: <span id="buildhours">$buildhours</span> \
    <<click "[+]">>
    	<<set $buildhours++, $freehours-->>
    	<<replace "#buildhours">>$buildhours<</replace>>
    	<<replace "#freehours">>$freehours<</replace>>
    <</click>> \
    | <<click "[-]">>
    	<<set $buildhours--, $freehours++>>
    	<<replace "#buildhours">>$buildhours<</replace>>
    	<<replace "#freehours">>$freehours<</replace>>
    <</click>>
    
  • Thank you very much, that works exactly as I want.
  • @TheMadExile Sorry for showing out of nowhere in this discussion, but I as wondering if you knew how to adjust your code in a way where the player only had a certain number of clicks available (let's say three), to share between the two options. I'm a total newbie, I just really liked what you did, and was trying to adapt it. thanks :)
  • @Jajajewels: You need to state the name and full version number of the story format you are using, as answers can be different for each one.

    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.
  • @greyelf yeah, sorry I forgot to mention the format. Unfortunately I'm working on Sugarcube 2.18 so this add-on doesn't work, but I took a look at it, and it seems really cool. Maybe when I start a new project and I update it I can use it. Thanks anyway!
  • Jajajewels wrote: »
    Unfortunately I'm working on Sugarcube 2.18
    As I stated in my previous comment, the <<numberpool>> add-on is for the SugarCube 2 versions of the story format.

    So if you are using Sugarcube 2.18.0 then that addon will work for you.
  • Jajajewels wrote: »
    @TheMadExile Sorry for showing out of nowhere in this discussion, but I as wondering if you knew how to adjust your code in a way where the player only had a certain number of clicks available (let's say three), to share between the two options. I'm a total newbie, I just really liked what you did, and was trying to adapt it. thanks :)
    I'm going to parrot greyelf here. What you're asking about is the chief reason the <<numberpool>> macro set add-on for SugarCube v2 was written, so I'd probably recommend looking at that first—specifically, a <<numberpool>> and a few <<numberbox>>.

    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.
Sign In or Register to comment.