Rank system

I am setting up a system for Ranks like in the army it is based on the stats. Not sure If I did it right.

<<if $strength <20>>
<<if $stamina <20>>
<<if $charisma <15>>
<<if $intelligence <30>>
<<set $rank to "Private">>
<<elseif $strength <=60>>
<<if $stamina <=60>>
<<if $charisma <=50>>
<<if $intelligence <=70>>
<<set $rank to "Corporal">>
<<elseif $strength <=90>>
<<if $stamina <=90>>
<<if $charisma <=80>>
<<if $intelligence <=100>>
<<set $rank to "Sergeant">>
<<elseif $strength <=130>>
<<if $stamina <=130>>
<<if $charisma <=120>>
<<if $intelligence <=150>>
<<set $rank to "Captain">>
<<elseif $strength <=180>>
<<if $stamina <=180>>
<<if $charisma <=170>>
<<if $intelligence <=200>>
<<set $rank to "Major">>
<<elseif $strength <=220>>
<<if $stamina <=220>>
<<if $charisma <=210>>
<<if $intelligence <=260>>
<<set $rank to "Colonel">>
<<elseif $strength <=280>>
<<if $stamina <=280>>
<<if $charsima <=270>>
<<if $intelligence <=310>>
<<set $rank to "General">>
<</if>>

Or would it work better as a widget?
I wanted it so the lowest tier Private started small then as the stats build you go to the next but all the stats have to be right in order to rank up.

1 Like

Is your tree supposed to look like this??

<<if $strength <20>>
  <<if $stamina <20>>
    <<if $charisma <15>>
       <<if $intelligence <30>>
          <<set $rank to "Private">>
      <<elseif $strength <=60>>
           <<if $stamina <=60>>
                 <<if $charisma <=50>>
                     <<if $intelligence <=70>>
                           <<set $rank to "Corporal">>
                     <<elseif $strength <=90>>
                           <<if $stamina <=90>>
                                   <<if $charisma <=80>>
                                            <<if $intelligence <=100>>
                                                  <<set $rank to "Sergeant">>
                                           <<elseif $strength <=130>>
                                                  <<if $stamina <=130>>
[etc]

Because you can merge conditional statement with && or and
<<if $var1 < 8 && $var2 > 6 >>

1 Like

ahh yea I forgot about the &&. I was coding right in twine rather than using visual studio code so it just all kind of blended together. Could it have all 4 Var or just 2? Like

<<if $strength < 20 && $stamina < 20 && $charisma < 10 && $intelligence < 30>>
<<set $rank to "Private">>

Or does it need to be split up in two. Im thinking maybe doing this in a widget would be easier in the end, but then would it update the rank as the stats update while in the widget?

1 Like

You can have as many as you want :woman_shrugging:
this AND this AND this AND this AND this AND [etc]

1 Like

I just realized I dont think this whole thing will work like I want it to. The first part might with all of it being less than the nimbers I want to be a Private but the second set would still be less even at the first part so it would be confused as to what rank it needs. So there needs to be a way to say if strength is between 20 and 60 then rank is corporal and so on.

1 Like

Put the highest ranks first, the lowest last

1 Like

Ok I got this part working good now Thanks. Now the last step to do is hide the go to next page until all the steps are taken. I basically have it set so you have a dropdown menue for age a textbox for name and three popup links for radibuttons once all those are done I want a link to appear saying Next to go to a new passage.

I tried the

<<if has notvisited() <5>>\
[[Next|next]]
<</if>>

but this does not seem to work

1 Like

notvisited() doesnt exist
<<if visited("PassageName") > 5>>

1 Like

There is no notvisited() function and has is not a valid operator

I suspect you want

<<if visited() < 5>>
[[Next|next]]
<</if>>

But I’m not 100% sure. Are you refreshing the passage after every pick? If not, the number of times the passage has been visited() will not change.

Generally it seems you want the game to react to you choosing values from dropdowns and radiobuttons. Sadly, there is no such function built into Sugarcube (i.e. the only events you can have the game react to are clicks on buttons and links with <<button>> and <<link>>).

To do what you want, you must take one of three approaches

  1. Use <<repeat>> to check the state of the passage every X seconds (or less) to see if the conditions have been met
  2. Use a javascript event handler to monitor the controls and do something when they are changed
  3. Use a third party macro like <<on>> or <<listen>> or <<live>> to do the same thing as (2) but without having to write your own JS

In general, option 1 is a bad idea, for all that it is the only one available as a default macro, since it means the game is constantly running checks even when nothing is happening, which will slow down the browser.

Option 2 is fine if you are comfortable with custom javascript. You could monitor the clicks on the radiobuttons like this:

* <label><<radiobutton "$pie" "blueberry" autocheck>> Blueberry?</label>
* <label><<radiobutton "$pie" "cherry" autocheck>> Cherry?</label>
* <label><<radiobutton "$pie" "coconut cream" autocheck>> Coconut cream?</label>

<div id="next">[[Next|next]]</div>

<<done>>
   <<run $(".macro-radiobutton").on('change', function() {
       if (State.variables.pie) {
           $('#next').show();
       } else {
           $('#next').hide();
       }
   })>>
<</done>>

However, your easiest bet is probably to install the <<listen>> macro (here), which is designed for just this. You’d use it like:

<<listen>>
* <label><<radiobutton "$pie" "blueberry" autocheck>> Blueberry?</label>
* <label><<radiobutton "$pie" "cherry" autocheck>> Cherry?</label>
* <label><<radiobutton "$pie" "coconut cream" autocheck>> Coconut cream?</label>
<<when>>
    <<replace '#next'>>[[Next|next]]<</replace>>
<</listen>>
<div id="next"></div>
1 Like

Yes The page refreshes each time. I have three groups one for career one for hobby and one for background each with radiobutton choices once the choice is made the main page with the links to them refreshes. I think I have this part all handled for the time being I need to add in time and day cycle which im already familiar with then to start adding events, which is where the fun comes in.

1 Like

Well in that case the first code I gave you will work.

However, I’d say that — in general — refreshing the passage constantly is a bad idea. It fires events, it puts new entries in the history, it makes saves bigger, and it makes the passage visually flicker on screen. If you can move to a live model like the ones I described in my longer reply, then you will be better off.

1 Like

yea thats unedrstandable but in this case its only going to be on this passage at the begining when creating the character and then never see it again during the game.

1 Like