Howdy, Stranger!

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

Going to a passage automatically/refreshing current passage? (Harlowe)

edited September 2016 in Help! with 2.0
So I'm making a combat system, but currently I can't figure out how to automatically refresh the current passage to display updates to player and enemy health without using a (goto: "Combat Scene") to reopen the passage.

I decided to try and use a $currentpassage vareiable to help me change the target passage when necessary, but I can't get that to work in anything but a link, but I don't want it as a link, I want it to automatically go to the Passage matching the name of the string I saved in $currentpassage

Here is what I have written in the combat scene so far:
(set: $currentpassage to "Combat Scene")
(link-goto: "$currentpassage")
(print: $enemystats's Name)
HP: (print: $enemystats's Health)
(print: $enemystats's Description)


Player damage dealt last turn: $totalplayerdamagedealt

Enemy damage dealt last turn: $totalenemydamagedealt

[Attack]<Attack|

(click: ?Attack)[ 
(set: $totalplayerdamagedealt to 0)
(set: $totalplayerdamagedealt to it + (random: $playerstats's weaponmindamage, $playerstats's weaponmaxdamage) + $playerstats's Strength/2) 
(set: $enemystats's Health to it - $totalplayerdamagedealt - $enemystats's defense)
(goto: "$currentpassage")]

Comments

  • edited September 2016
    Instead of answering your question I am going to suggest you use a combination of named hooks and (replace: ) macros to implement the user-interface of your fight scene. That way you don't need to keep reloading/visiting the same passage repeatably for a single fight.

    1. Setup the required variables (in a passage) before the Fight Scene passage, an idea place to do this is in your story's startup tagged passage which is processed before the story starts.

    note: Because you did not provided an example of the initial values of your variables I had to make a guess what those values may be.
    {
    (set: $enemyStats to (datamap: "Name", "Hogger", "Health", 100, "Description", "Big and ugly", "Defense", 4))
    
    (set: $playerStats to (datamap: "Strength", 18, "WeaponMinDamage", 1, "WeaponMaxDamage", 6))
    
    (set: $totalPlayerDamageDealt to 0)
    (set: $totalEnemyDamageDealt to 0)
    
    }[[Start Fight->Fight Scene]]
    

    2. The Fight Scene passage, or a brief example of a starting point of one.

    You would need to add things like: the enemy's attack logic; what happens when someone dies; and a link to exit the passage.
    (print: $enemyStats's Name)
    HP: [(print: $enemyStats's Health)]<enemyHP|
    (print: $enemyStats's Description)
    
    Player damage dealt last turn: [$totalPlayerDamageDealt]<playerDamage|
    
    Enemy damage dealt last turn: [$totalEnemyDamageDealt]<enemyDamage|
    
    (link-repeat: "Attack")[{
    	<!-- Calculate what damage was done.  -->
    	(set: $totalPlayerDamageDealt to it +
    		((random: $playerStats's WeaponMinDamage, $playerStats's WeaponMaxDamage) + ($playerStats's Strength / 2)))
    
    	(set: $enemyStats's Health to it - ($totalPlayerDamageDealt - $enemyStats's Defense))
    
    	<!-- Update the user interface. -->
    	(replace: ?enemyHP)[(print: $enemyStats's Health)]
    	(replace: ?playerDamage)[$totalPlayerDamageDealt]
    	(replace: ?enemyDamage)[$totalEnemyDamageDealt]
    }]
    
  • Thanks! That actually helps a lot, it is much smoother now!

    Now all I need to do is keep researching how to add a GUI of some sort
Sign In or Register to comment.