Howdy, Stranger!

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

Harlowe 1.2.2 | Unable to "block" or "replace" if not enough $mana

This is currently the code I have for the "battle system" ;
<div id="you">You: $currenthp/$maxhp
You have $mana energy left
{(if: $turn is "you")[

(link: "Report")[
(set: $ehp to it - $weapondamage)
(set: $atk to "Punch")
(set: $atkdmg to $weapondamage)
(set: $turn to "enemy")
(set: $log to "atk")
(goto: "Combat")]

(link: "Repfuck")[
(if: $mana <5)(replace: ?Repfuck)[
No Energy]
(set: $ehp to it - $mdmg)
(set: $matk to "Repfuck")
(set: $mana to $mana -15)
(set: $turn to "enemy")
(set: $log to "magic")
(goto: "Combat")]
]


(elseif: $turn is "enemy")[
(link: "Continue")[
(set: $log to "enemy")
(set: $turn to "you")
(set: $currenthp to it - $eatk)
(goto: "Combat")]
]
(if: $currenthp <1)[(goto: "Lose")]
(if: $ehp <1)[(goto: "Win")]
</div>}

The thing is, when the player have less than 5 mana, he can still cast the "special" ability


I'm new to Twine so sorry if it's basic, it's my first attempt at making a game ._.

Comments

  • The (if: $mana < 5) statement in your code has no associated hook, I am guessing that that section of the code was meant to look something like the following:
    (link: "Repfuck")[
    	(if: $mana < 5)[
    		(replace: ?Repfuck)[No Energy]
    	](else:)[
    		(set: $ehp to it - $mdmg)
    		(set: $matk to "Repfuck")
    		(set: $mana to $mana -15)
    		(set: $turn to "enemy")
    		(set: $log to "magic")
    	]
    	(goto: "Combat")
    ]
    

    warning:
    Based on the structure of your code example I am assuming that it's passage name is Combat and that the passage recursively calls itself (via the (goto: "Combat") statement) until the the fight is over. I also assume you are doing this because you want the section that displays the current values of your $currenthp, $maxhp, and $mana to update as the fight progresses.

    The issue with using recursion like this is that every time the story engine traverses between passages it makes a copy of the current value all known variables (known as state)and makes that copy available to the passage about to be shown, it does this as part of the History system so that when the Reader uses the Undo link to go backwards the game engine can reset all the known variables back to their previous value. The copying process is expensive in both processing time and more importantly memory, because the History system currently needs to remember the state of every passage visited for each time it was visited.

    A better option is to use a combination of named hooks and one of the revision macros like (replace: ), something like the following:
    {<!-- The following variable setting should happen in a previous passage, only doing it here so this example works. -->
    (set: $currenthp to 100, $maxhp to 100, $mana to 50)
    
    }
    You: [$currenthp/$maxhp]<hpmp|
    You have [$mana]<mana| energy left
    
    (link-repeat: "Do something")[
    	<!-- some combat related code, this example uses d6 rolls. -->
    	(set: $currenthp to it - (random: 1, 6))
    	(set: $mana to it - (random: 1, 6))
    	(replace: ?hpmp)[$currenthp/$maxhp]
    	(replace: ?mana)[$mana]
    ]
    
Sign In or Register to comment.