Howdy, Stranger!

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

Using Replace macro with other whilst also utilising numbers. (SUGARCUBE, TWINE 2)

edited March 2016 in Help! with 2.0
Greetings,

I've gotten pretty far on my character creation system thus far, but here it seems I have reached another impasse - and I believe that this information may yet prove useful to other's who may or may not know how to do this (I tried finding the related information on the forum but it appears as though this particular situation may require a more involved method).

In the code displayed below, I wish to make it so that when $Str is in the area for $S1 to be true, then $S1 would immediately replace any other $S# that may be true before that time. This is so that when trying to choose a specific level for each stat - the associated stat trait is then displayed so as to give the player a more informed level of detail as to their best course of action.

I was also wondering if it then would not be simpler to introduce the associated changes that affected the other stats (from these Stat Traits) there and then on this page rather than on a seperate one, but I found that each <span id> will only display changes for one and only one, even if they are cloned (or perhaps that's just my lack of knowledge on the matter).

I know that the below is wrong, and will not change with the $Str level because it has none of the necessary code or macro (this is my clean copy which is not full of failed tests etc) but my question is - how would I make something like this work?
Stat Points: <<set $Skills to 150>><span id="skills">$Skills</span>

Strength:  \ 
<span id="stats-str-minus">\
<<button "-">>
	<<if $Str gt 20>>
		<<if $Str eq 150>>
			<<run $("#stats-str-plus button").prop("disabled", false);>>
		<</if>>    
		<<set $Str -=2, $Skills +=2>>
		<<replace "#stats-str">>$Str<</replace>>
		<<replace "#skills">>$Skills<</replace>>
		<<if $Str eq 20>>
			<<run $("#stats-str-minus button").prop("disabled", true);>>
		<</if>>
	<</if>>
<</button>> \
</span>\
<span id="stats-str">$Str</span> \
<span id="stats-str-plus">\
<<button "+">>
	<<if $Str lt 150 and $Skills gt 0>>
		<<if $Str eq 20>>
			<<run $("#stats-str-minus button").prop("disabled", false);>>
		<</if>>
		<<set $Str +=2, $Skills -=2>>
		<<replace "#stats-str">>$Str<</replace>>
		<<replace "#skills">>$Skills<</replace>>
		<<if $Str eq 150>>
			<<run $("#stats-str-plus button").prop("disabled", true);>>
		<</if>>
	<</if>>
<</button>>
</span>\


<<if $Str gt -100 and $Str lt 40>>
<<set $S1 to true>>
S1 TRUE
<</if>>

<<if $Str gte 40 and $Str lt 70>>
<<set $S2 to true>>
S2 TRUE
<</if>>

<<if $Str gte 70 and $Str lt 90>>
<<set $S3 to true>>
S3 TRUE
<</if>>

<<if $Str gte 90 and $Str lt 115>>
<<set $S4 to true>>
S4 TRUE
<</if>>

<<if $Str gte 115 and $Str lt 135>>
<<set $S5 to true>>
S5
<</if>>

<<if $Str gte 135>>
<<set $S6 to true>>
S6 TRUE
<</if>>

I would appreciate any available support on the matter. Thank you.

Comments

  • Tried putting the logic to work out the Sx values into a gadget and invoking it from inside the if after you've changed the strength?

    You might need a separate span-id and replace call to get the Sx value updated - the update can go in the gadget as well.
  • I'm unsure if I understand what you're trying to do, however, I think you're trying to display a specific message for each tier of stat?

    If so, and if that's all you're attempting to do, then you probably do not need the $S# variables at all. I'd suggest placing the tier messages for each stat in their own passages (e.g. Strength Tiers), then simply have the stat blocks replace the message display area with that passage. For example:
    ''Stat Points:'' <<set $Skills to 150>><span id="skills">$Skills</span>
    
    ''Strength:''  \ 
    <span id="stats-str-minus">\
    <<button "-">>
    	<<if $Str gt 20>>
    		<<if $Str eq 150>>
    			<<run $("#stats-str-plus button").prop("disabled", false)>>
    		<</if>>    
    		<<set $Str -=2, $Skills +=2>>
    		<<replace "#stats-str">>$Str<</replace>>
    		<<replace "#skills">>$Skills<</replace>>
    		<<replace "#stats-str-desc">><<display "Strength Tiers">><</replace>>
    		<<if $Str eq 20>>
    			<<run $("#stats-str-minus button").prop("disabled", true)>>
    		<</if>>
    	<</if>>
    <</button>> \
    </span>\
    <span id="stats-str">$Str</span> \
    <span id="stats-str-plus">\
    <<button "+">>
    	<<if $Str lt 150 and $Skills gt 0>>
    		<<if $Str eq 20>>
    			<<run $("#stats-str-minus button").prop("disabled", false)>>
    		<</if>>
    		<<set $Str +=2, $Skills -=2>>
    		<<replace "#stats-str">>$Str<</replace>>
    		<<replace "#skills">>$Skills<</replace>>
    		<<replace "#stats-str-desc">><<display "Strength Tiers">><</replace>>
    		<<if $Str eq 150>>
    			<<run $("#stats-str-plus button").prop("disabled", true)>>
    		<</if>>
    	<</if>>
    <</button>>
    </span>
    <span id="stats-str-desc"><<display "Strength Tiers">></span>
    
    ''Dexterity:''  \ 
    <span id="stats-dex-minus">\
    <<button "-">>
    	<<if $Dex gt 20>>
    		<<if $Dex eq 150>>
    			<<run $("#stats-dex-plus button").prop("disabled", false)>>
    		<</if>>    
    		<<set $Dex -=2, $Skills +=2>>
    		<<replace "#stats-dex">>$Dex<</replace>>
    		<<replace "#skills">>$Skills<</replace>>
    		<<replace "#stats-dex-desc">><<display "Dexterity Tiers">><</replace>>
    		<<if $Dex eq 20>>
    			<<run $("#stats-dex-minus button").prop("disabled", true)>>
    		<</if>>
    	<</if>>
    <</button>> \
    </span>\
    <span id="stats-dex">$Dex</span> \
    <span id="stats-dex-plus">\
    <<button "+">>
    	<<if $Dex lt 150 and $Skills gt 0>>
    		<<if $Dex eq 20>>
    			<<run $("#stats-dex-minus button").prop("disabled", false)>>
    		<</if>>
    		<<set $Dex +=2, $Skills -=2>>
    		<<replace "#stats-dex">>$Dex<</replace>>
    		<<replace "#skills">>$Skills<</replace>>
    		<<replace "#stats-dex-desc">><<display "Dexterity Tiers">><</replace>>
    		<<if $Dex eq 150>>
    			<<run $("#stats-dex-plus button").prop("disabled", true)>>
    		<</if>>
    	<</if>>
    <</button>>
    </span>
    <span id="stats-dex-desc"><<display "Dexterity Tiers">></span>
    
    Notice that at the tail of each stat block is a new element to hold the tier descriptions. Each tier description passage is displayed initially and then redisplayed each time the associated stat is changed.

    Each tier description passage (e.g. Strength Tiers) would look something like the following:
    <<if $Str lt 40>>\
    Tier 1 Strength Message
    <<elseif $Str lt 70>>\
    Tier 2 Strength Message
    <<elseif $Str lt 90>>\
    Tier 3 Strength Message
    <<elseif $Str lt 115>>\
    Tier 4 Strength Message
    <<elseif $Str lt 135>>\
    Tier 5 Strength Message
    <<else>>\
    Tier 6 Strength Message
    <</if>>\
    
  • I'm unsure if I understand what you're trying to do, however, I think you're trying to display a specific message for each tier of stat?

    If so, and if that's all you're attempting to do, then you probably do not need the $S# variables at all. I'd suggest placing the tier messages for each stat in their own passages (e.g. Strength Tiers), then simply have the stat blocks replace the message display area with that passage. For example:
    ''Stat Points:'' <<set $Skills to 150>><span id="skills">$Skills</span>
    
    ''Strength:''  \ 
    <span id="stats-str-minus">\
    <<button "-">>
    	<<if $Str gt 20>>
    		<<if $Str eq 150>>
    			<<run $("#stats-str-plus button").prop("disabled", false)>>
    		<</if>>    
    		<<set $Str -=2, $Skills +=2>>
    		<<replace "#stats-str">>$Str<</replace>>
    		<<replace "#skills">>$Skills<</replace>>
    		<<replace "#stats-str-desc">><<display "Strength Tiers">><</replace>>
    		<<if $Str eq 20>>
    			<<run $("#stats-str-minus button").prop("disabled", true)>>
    		<</if>>
    	<</if>>
    <</button>> \
    </span>\
    <span id="stats-str">$Str</span> \
    <span id="stats-str-plus">\
    <<button "+">>
    	<<if $Str lt 150 and $Skills gt 0>>
    		<<if $Str eq 20>>
    			<<run $("#stats-str-minus button").prop("disabled", false)>>
    		<</if>>
    		<<set $Str +=2, $Skills -=2>>
    		<<replace "#stats-str">>$Str<</replace>>
    		<<replace "#skills">>$Skills<</replace>>
    		<<replace "#stats-str-desc">><<display "Strength Tiers">><</replace>>
    		<<if $Str eq 150>>
    			<<run $("#stats-str-plus button").prop("disabled", true)>>
    		<</if>>
    	<</if>>
    <</button>>
    </span>
    <span id="stats-str-desc"><<display "Strength Tiers">></span>
    
    ''Dexterity:''  \ 
    <span id="stats-dex-minus">\
    <<button "-">>
    	<<if $Dex gt 20>>
    		<<if $Dex eq 150>>
    			<<run $("#stats-dex-plus button").prop("disabled", false)>>
    		<</if>>    
    		<<set $Dex -=2, $Skills +=2>>
    		<<replace "#stats-dex">>$Dex<</replace>>
    		<<replace "#skills">>$Skills<</replace>>
    		<<replace "#stats-dex-desc">><<display "Dexterity Tiers">><</replace>>
    		<<if $Dex eq 20>>
    			<<run $("#stats-dex-minus button").prop("disabled", true)>>
    		<</if>>
    	<</if>>
    <</button>> \
    </span>\
    <span id="stats-dex">$Dex</span> \
    <span id="stats-dex-plus">\
    <<button "+">>
    	<<if $Dex lt 150 and $Skills gt 0>>
    		<<if $Dex eq 20>>
    			<<run $("#stats-dex-minus button").prop("disabled", false)>>
    		<</if>>
    		<<set $Dex +=2, $Skills -=2>>
    		<<replace "#stats-dex">>$Dex<</replace>>
    		<<replace "#skills">>$Skills<</replace>>
    		<<replace "#stats-dex-desc">><<display "Dexterity Tiers">><</replace>>
    		<<if $Dex eq 150>>
    			<<run $("#stats-dex-plus button").prop("disabled", true)>>
    		<</if>>
    	<</if>>
    <</button>>
    </span>
    <span id="stats-dex-desc"><<display "Dexterity Tiers">></span>
    
    Notice that at the tail of each stat block is a new element to hold the tier descriptions. Each tier description passage is displayed initially and then redisplayed each time the associated stat is changed.

    Each tier description passage (e.g. Strength Tiers) would look something like the following:
    <<if $Str lt 40>>\
    Tier 1 Strength Message
    <<elseif $Str lt 70>>\
    Tier 2 Strength Message
    <<elseif $Str lt 90>>\
    Tier 3 Strength Message
    <<elseif $Str lt 115>>\
    Tier 4 Strength Message
    <<elseif $Str lt 135>>\
    Tier 5 Strength Message
    <<else>>\
    Tier 6 Strength Message
    <</if>>\
    

    Yes!! That worked perfectly, thank you mad exile! I wasn't aware that displaying different passages worked in that fashion? Makes me wonder why a single passage can't do that without needing to have that secondary passage involved to call upon.
    mykael wrote: »
    Tried putting the logic to work out the Sx values into a gadget and invoking it from inside the if after you've changed the strength?

    You might need a separate span-id and replace call to get the Sx value updated - the update can go in the gadget as well.

    Yea I was thinking about the necessity for a seperate span-id and whatnot. Unfortunately the macro wiki is fairly sparse on information about the variety of use for the span-id integer, and I generally found that people were using that sort of thing in Harlowe rather than sugarcube when I checked other questions regarding the <<replace>> macro and <<span-id>>. Makes me wonder if I'm using the right story format x)

    I assume you're referring to the problem TheMadExile had answered by the way and not the idea whereby stat values are replaced on the go in this system? Because that sounds like it would be more trouble than it's worth right now in all honesty x)

  • RaddersHQ wrote: »
    Yes!! That worked perfectly, thank you mad exile! I wasn't aware that displaying different passages worked in that fashion? Makes me wonder why a single passage can't do that without needing to have that secondary passage involved to call upon.
    You could do it all with just the one passage, however, you'd have to repeat the code from the tier passages three times, since each is used three times within the stat blocks passage, thereby bloating the stat blocks passage and making it harder to read.
  • Span-is is a string and it needs to match the value specified on a <span id="span-id">...</span> tag somewhere in the displayed passage. Basically a way of uniquely identifying a section of the display html so you can, for example, replace it.
  • Ahh, sorry guys - was away from my computer/twine for a while there :S excellent job again, much obliged to the both of you :)
    mykael wrote: »
    Span-is is a string and it needs to match the value specified on a <span id="span-id">...</span> tag somewhere in the displayed passage. Basically a way of uniquely identifying a section of the display html so you can, for example, replace it.

    Yes, I found that out briefly after posting that last message! It's always good to learn new things such as these :')

    You could do it all with just the one passage, however, you'd have to repeat the code from the tier passages three times, since each is used three times within the stat blocks passage, thereby bloating the stat blocks passage and making it harder to read.

    Crikey I wouldn't have even realised! Also, I have noticed that sometimes *would-be-code* can sometimes create a large chasm between written dialogue/paragraphs of text.

    Is this normal or abnormal - if so, is there a way to minimise that? I believe it would assist in the immersion of the player into the game-world.

  • RaddersHQ wrote: »
    Is this normal or abnormal - if so, is there a way to minimise that? I believe it would assist in the immersion of the player into the game-world.
    Each line-break you add to the contents of a Passage are displayed when that passage is shown to the Reader.

    eg. The following passage code:
    The first line of text
    <<if $var is "value">>The true second line of text
    <<else>>the false second line of text
    <</if>>
    The third line of text
    
    ... appears with a blank line between the second and third lines of text:
    The first line of text
    the false second line of text

    The third line of text
    ... because of the line-break after the <</if>> end macro.

    There are a couple of ways to remove unwanted line-breaks:

    1. Using a backslash as explained in the Line Continuations section of the manual. Note the backslash added after the <</if>> macro:
    The first line of text
    <<if $var is "value">>The true second line of text
    <<else>>the false second line of text
    <</if>>\
    The third line of text
    
    2. Use the <<nobr>> macro or the nobr special tag.

    3. Remove the line-break(s):
    The first line of text
    <<if $var is "value">>The true second line of text<<else>>the false second line of text<</if>>
    The third line of text
    
  • 1. Using a backslash as explained in the Line Continuations section of the manual. Note the backslash added after the <</if>> macro:
    The first line of text
    <<if $var is "value">>The true second line of text
    <<else>>the false second line of text
    <</if>>\
    The third line of text
    
    2. Use the <<nobr>> macro or the nobr special tag.

    3. Remove the line-break(s):
    The first line of text
    <<if $var is "value">>The true second line of text<<else>>the false second line of text<</if>>
    The third line of text
    

    Ahh. Much obliged greyelf, only just seen this :)

Sign In or Register to comment.