Howdy, Stranger!

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

Can I use click macro and passagedone or something else other than replace to update variables?

So I have question about updating variables with click and making new text appear without having to do replace. So I have a decently sized game right now and many passages have multiple choices that lead to different outcomes and different text on the same passage. So far I have been doing this by using replace to make new text appear, but i was kinda hoping i could skip that and just have a click that updates a variable making an if statement true and showing the text under that if statement without having to leave the passage and come back. Or replacing.

Sorry if this is unreable i'm on an ipad right now. Also i'm writing in the newest version of sugarcube 2.

Comments

  • edited April 2016
    Tried to edit this and it gave me page not found, so I'm posting here.
    At my computer now and adding an example to try and clarify my problem.
    And I'm not using the newest sugarcube 2, but 2.5.

    This is part of my store system. It only shows items as buyable if you enter the store with enough money. Now when you buy something the money amount changes, but there is no immediate visual change if you can't afford the other items. I did a workaround with displaying a "You can't afford this text" When clicking on buy, but this requires extra clicks from the user.

    I would like it to cut out this extra click and just update what items the player can afford when they buy something. I know I could put the entire passage into every replace, but this scales very badly with multiple items.
    ''Dungeon Diving Emporium''
    [[Leave->Merchant Quarters]]
    
    
    
    <<nobr>>
    <<if $AnkleKnifeOwned is 0>>
    <<if $PlayerMoney < 70>>
    You see an interesting knife on display, but it costs more than you can afford (70g)
    <<elseif $PlayerMoney >= 70>>
    ''Ankle Knife''
    <<=$AnkleKnifeDescription>>
    <span id="buy-ankleknife"><<click "Buy for seventy gold.">><<replace "#buy-ankleknife">><<if $PlayerMoney >= 70>> You take the knife from its display and procede to pay for it, you now own a new piece of equipment!<<set $AnkleKnifeOwned to 1, $PlayerMoney -=70>>
    <<else>>
    After counting your coins again you discover you can't actually afford the knife.
    <</if>>
    <</replace>><</click>></span>
    <</if>>
    <<elseif $AnkleKnifeOwned is 1>>
    You already bought the Ankle knife that was here.
    <</if>>
    <</nobr>>
    
    <<nobr>>
    <<if $TrustyHelmOwned is 0>>
    <<if $PlayerMoney < 80>>
    You see a metal helm on display and the note next to it calls it a "Trusty Helm". You think it might be a bit on the cheap side. Though you can't actually afford this low price right now. (80g)
    <<elseif $PlayerMoney >= 80>>
    ''Trusty Helm''
    <<=$TrustyHelmDescription>>
    <span id="buy-trustyhelm"><<click "Buy for eighty gold.">><<replace "#buy-trustyhelm">><<if $PlayerMoney >= 80>> you take the helm to Fredrick and pay for it, you now own a new piece of equipment!<<set $TrustyHelmOwned to 1, $PlayerMoney -= 80>>
    <<else>>
    After counting your money again you find out you can't actually afford the helm, maybe you bought something else first?
    <</if>>
    <</replace>><</click>></span>
    <</if>>
    <<elseif $TrustyHelmOwned is 1>>
    You already bought the helm that was here, maybe you need to be happy with the one you have, it is so trustworthy after all.
    <</if>>
    <</nobr>>
    
    <<nobr>>
    <<if $ArrowShieldOwned is 0>>
    <<if $PlayerMoney < 120>>
    You see an interesting Shield of Arrow Attraction on display, but it costs more than what you can afford. (120g)
    <<elseif $PlayerMoney >= 120>>
    ''Shield of Arrow Attraction''
    <<=$ArrowShieldDescription>>
    <span id="buy-arrowshield"><<click "Buy for a hundred and twenty gold.">><<replace "#buy-arrowshield">><<if $PlayerMoney >= 120>> You decide you want the shield and buy it, you now own a new piece of equipment!<<set $ArrowShieldOwned to 1, $PlayerMoney -= 120>>
    <<else>>
    After counting your money again you find out you can't actually afford the shield, what a pity.
    <</if>>
    <</replace>><</click>></span>
    <</if>>
    <<elseif $ArrowShieldOwned is 1>>
    You already bought the Shield of Arrow Attraction that was here.
    <</if>>
    <</nobr>>
    
  • I want to touch on a few things before I have a go at your question.

    Several of your conditionals are redundant. For example:
    <<if $PlayerMoney < 70>>
    …
    <<elseif $PlayerMoney >= 70>>
    …
    <</if>>
    
    There's no need to check if $PlayerMoney is greater than or equal to 70 in the <<elseif>> conditional. You only get to that point if the <<if>> conditional has failed—meaning that you already know that $PlayerMoney is greater than or equal to 70, by virtue of it not being less than 70.

    You seem to be using integers (0 and 1) as booleans. Use real booleans (false and true) instead. For example, instead of:
    <<if $AnkleKnifeOwned is 0>>
    	/* $AnkleKnifeOwned is 0, player doesn't own an ankle knife. */
    <<elseif $AnkleKnifeOwned is 1>>
    	/* $AnkleKnifeOwned is 1, player owns an ankle knife. */
    <</if>>
    
    Do something like the following:
    <<if $AnkleKnifeOwned>>
    	/* $AnkleKnifeOwned is true, player owns an ankle knife. */
    <<else>>
    	/* $AnkleKnifeOwned is false, player doesn't own an ankle knife. */
    <</if>>
    
    Or for the inverted case:
    <<if not $AnkleKnifeOwned>>
    	/* $AnkleKnifeOwned is false, player doesn't own an ankle knife. */
    <<else>>
    	/* $AnkleKnifeOwned is true, player owns an ankle knife. */
    <</if>>
    

    Oh. You also misspelled proceed as procede in the ankle knife purchase message.


    Now, as to your question. You could set it up so that purchasing an item replays the passage via Engine.play(passage()). And for that to work correctly, you'll need another variable, only temporarily, so that you know to display the purchase message. For example:
    ''Dungeon Diving Emporium''
    [[Leave->Merchant Quarters]]
    
    
    ''Ankle Knife''
    <<nobr>>
    <<if $AnkleKnifeBought>>
    <<unset $AnkleKnifeBought>>
    You take the knife from its display and proceed to pay for it, you now own a new piece of equipment!
    <<elseif not $AnkleKnifeOwned>>
    <<if $PlayerMoney < 70>>
    You see an interesting knife on display, but it costs more than you can afford (70g)
    <<else>>
    $AnkleKnifeDescription
    <<click "Buy for seventy gold.">>
    <<set $AnkleKnifeBought to true, $AnkleKnifeOwned to true, $PlayerMoney -= 70>>
    <<script>>Engine.play(passage())<</script>>
    <</click>>
    <</if>>
    <<else>>
    You already bought the Ankle knife that was here.
    <</if>>
    <</nobr>>
    
    ''Trusty Helm''
    <<nobr>>
    <<if $TrustyHelmBought>>
    <<unset $TrustyHelmBought>>
    You take the helm to Fredrick and pay for it, you now own a new piece of equipment!
    <<elseif not $TrustyHelmOwned>>
    <<if $PlayerMoney < 80>>
    You see a metal helm on display and the note next to it calls it a "Trusty Helm". You think it might be a bit on the cheap side. Though you can't actually afford this low price right now. (80g)
    <<else>>
    $TrustyHelmDescription
    <<click "Buy for eighty gold.">>
    <<set $TrustyHelmBought to true, $TrustyHelmOwned to true, $PlayerMoney -= 80>>
    <<script>>Engine.play(passage())<</script>>
    <</click>>
    <</if>>
    <<else>>
    You already bought the helm that was here, maybe you need to be happy with the one you have, it is so trustworthy after all.
    <</if>>
    <</nobr>>
    
    ''Shield of Arrow Attraction''
    <<nobr>>
    <<if $ArrowShieldBought>>
    <<unset $ArrowShieldBought>>
    You decide you want the shield and buy it, you now own a new piece of equipment!
    <<elseif not $ArrowShieldOwned>>
    <<if $PlayerMoney < 120>>
    You see an interesting Shield of Arrow Attraction on display, but it costs more than what you can afford. (120g)
    <<else>>
    $ArrowShieldDescription
    <<click "Buy for a hundred and twenty gold.">>
    <<set $ArrowShieldBought to true, $ArrowShieldOwned to true, $PlayerMoney -= 120>>
    <<script>>Engine.play(passage())<</script>>
    <</click>>
    <</if>>
    <<else>>
    You already bought the Shield of Arrow Attraction that was here.
    <</if>>
    <</nobr>>
    
  • Thanks a lot! that worked nicely. Now to replicate everywhere else and get the same result.
    I want to touch on a few things before I have a go at your question.

    Several of your conditionals are redundant. For example:
    <<if $PlayerMoney < 70>>
    …
    <<elseif $PlayerMoney >= 70>>
    …
    <</if>>
    
    There's no need to check if $PlayerMoney is greater than or equal to 70 in the <<elseif>> conditional. You only get to that point if the <<if>> conditional has failed—meaning that you already know that $PlayerMoney is greater than or equal to 70, by virtue of it not being less than 70.

    You seem to be using integers (0 and 1) as booleans. Use real booleans (false and true) instead. For example, instead of:
    <<if $AnkleKnifeOwned is 0>>
    	/* $AnkleKnifeOwned is 0, player doesn't own an ankle knife. */
    <<elseif $AnkleKnifeOwned is 1>>
    	/* $AnkleKnifeOwned is 1, player owns an ankle knife. */
    <</if>>
    
    Do something like the following:
    <<if $AnkleKnifeOwned>>
    	/* $AnkleKnifeOwned is true, player owns an ankle knife. */
    <<else>>
    	/* $AnkleKnifeOwned is false, player doesn't own an ankle knife. */
    <</if>>
    
    Or for the inverted case:
    <<if not $AnkleKnifeOwned>>
    	/* $AnkleKnifeOwned is false, player doesn't own an ankle knife. */
    <<else>>
    	/* $AnkleKnifeOwned is true, player owns an ankle knife. */
    <</if>>
    

    Oh. You also misspelled proceed as procede in the ankle knife purchase message.


    Now, as to your question. You could set it up so that purchasing an item replays the passage via Engine.play(passage()). And for that to work correctly, you'll need another variable, only temporarily, so that you know to display the purchase message. For example:
    ''Dungeon Diving Emporium''
    [[Leave->Merchant Quarters]]
    
    
    ''Ankle Knife''
    <<nobr>>
    <<if $AnkleKnifeBought>>
    <<unset $AnkleKnifeBought>>
    You take the knife from its display and proceed to pay for it, you now own a new piece of equipment!
    <<elseif not $AnkleKnifeOwned>>
    <<if $PlayerMoney < 70>>
    You see an interesting knife on display, but it costs more than you can afford (70g)
    <<else>>
    $AnkleKnifeDescription
    <<click "Buy for seventy gold.">>
    <<set $AnkleKnifeBought to true, $AnkleKnifeOwned to true, $PlayerMoney -= 70>>
    <<script>>Engine.play(passage())<</script>>
    <</click>>
    <</if>>
    <<else>>
    You already bought the Ankle knife that was here.
    <</if>>
    <</nobr>>
    
    ''Trusty Helm''
    <<nobr>>
    <<if $TrustyHelmBought>>
    <<unset $TrustyHelmBought>>
    You take the helm to Fredrick and pay for it, you now own a new piece of equipment!
    <<elseif not $TrustyHelmOwned>>
    <<if $PlayerMoney < 80>>
    You see a metal helm on display and the note next to it calls it a "Trusty Helm". You think it might be a bit on the cheap side. Though you can't actually afford this low price right now. (80g)
    <<else>>
    $TrustyHelmDescription
    <<click "Buy for eighty gold.">>
    <<set $TrustyHelmBought to true, $TrustyHelmOwned to true, $PlayerMoney -= 80>>
    <<script>>Engine.play(passage())<</script>>
    <</click>>
    <</if>>
    <<else>>
    You already bought the helm that was here, maybe you need to be happy with the one you have, it is so trustworthy after all.
    <</if>>
    <</nobr>>
    
    ''Shield of Arrow Attraction''
    <<nobr>>
    <<if $ArrowShieldBought>>
    <<unset $ArrowShieldBought>>
    You decide you want the shield and buy it, you now own a new piece of equipment!
    <<elseif not $ArrowShieldOwned>>
    <<if $PlayerMoney < 120>>
    You see an interesting Shield of Arrow Attraction on display, but it costs more than what you can afford. (120g)
    <<else>>
    $ArrowShieldDescription
    <<click "Buy for a hundred and twenty gold.">>
    <<set $ArrowShieldBought to true, $ArrowShieldOwned to true, $PlayerMoney -= 120>>
    <<script>>Engine.play(passage())<</script>>
    <</click>>
    <</if>>
    <<else>>
    You already bought the Shield of Arrow Attraction that was here.
    <</if>>
    <</nobr>>
    

Sign In or Register to comment.