Howdy, Stranger!

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

How to create consumables in an rpg twine 2.0 harlowe game

Basically it's as the title says I want to create ...., I can easily create a health potion that can be used in-battle but it gets more complex with an attack potion, xp potion or coin bonus as they should have a timer and I don't how to implement one correctly say I want it 10 secs (btw I have already created a simple inventory system so don't worry about that here's a guide if you don't know how) try to keep it simple because I'm relatively new to twine and coding

Comments

  • You could use the live macro. For example, if you wanted a temporary attack bonus for ten seconds you could do this:
    (link: "Use Attack Bonus Potion")[(set: $attackMultiplier to 2)
    (live: 10s)[(set: $attackMultiplier to 1)]]
    

    And then the code for the multiplier (if the opponent's health was a variable named $opponent and you dealt ten damage):
    (set: $opponent to $opponent - (10 * $multiplier))
    

    So if someone presses the link to use the potion, it activates a multiplier, which increases the damage you deal to enemies. But in ten seconds, the multiplier goes back to one, so ten times one is still just ten. Tell me if you don't understand or anything.
  • Note that the code within a (live:) macro's associated hook will be executed repeatedly until either the Reader navigates to another passage or a related (stop:) macro is executed.

    If you want the contents of the associated hook to only occur a limited number of times then you need to use a (stop:) macro.

    a. Occur only once:
    (live: 10s)[
    	(set: $attackMultiplier to 1)
    	(stop:)
    ]
    
    b. Occur a limited number of times (eg twice):
    (set: $counter to 0)
    (live: 10s)[
    	(set: $counter to it + 1)
    	(set: $var to it + 1)
    	(if: $counter is 2)[
    		(stop:)
    	]
    ]
    
  • greyelf wrote: »
    Note that the code within a (live:) macro's associated hook will be executed repeatedly until either the Reader navigates to another passage or a related (stop:) macro is executed.

    If you want the contents of the associated hook to only occur a limited number of times then you need to use a (stop:) macro.

    a. Occur only once:
    (live: 10s)[
    	(set: $attackMultiplier to 1)
    	(stop:)
    ]
    
    b. Occur a limited number of times (eg twice):
    (set: $counter to 0)
    (live: 10s)[
    	(set: $counter to it + 1)
    	(set: $var to it + 1)
    	(if: $counter is 2)[
    		(stop:)
    	]
    ]
    
    thanks I can use that to limit the amount of potions they can hold at a time (probably 3)
  • Deadshot wrote: »
    You could use the live macro. For example, if you wanted a temporary attack bonus for ten seconds you could do this:
    (link: "Use Attack Bonus Potion")[(set: $attackMultiplier to 2)
    (live: 10s)[(set: $attackMultiplier to 1)]]
    

    And then the code for the multiplier (if the opponent's health was a variable named $opponent and you dealt ten damage):
    (set: $opponent to $opponent - (10 * $multiplier))
    

    So if someone presses the link to use the potion, it activates a multiplier, which increases the damage you deal to enemies. But in ten seconds, the multiplier goes back to one, so ten times one is still just ten. Tell me if you don't understand or anything.
    thanks I will try that
  • edited August 2016
    Deadshot wrote: »
    You could use the live macro. For example, if you wanted a temporary attack bonus for ten seconds you could do this:
    (link: "Use Attack Bonus Potion")[(set: $attackMultiplier to 2)
    (live: 10s)[(set: $attackMultiplier to 1)]]
    

    And then the code for the multiplier (if the opponent's health was a variable named $opponent and you dealt ten damage):
    (set: $opponent to $opponent - (10 * $multiplier))
    

    So if someone presses the link to use the potion, it activates a multiplier, which increases the damage you deal to enemies. But in ten seconds, the multiplier goes back to one, so ten times one is still just ten. Tell me if you don't understand or anything.
    I created a situation where the fight would last way more than 10s to test it and it sadly didn't work, it just stayed boosted it still is it's been 5 mins now and it's still boosted, my code is a bit more complicated so I narrowed it down to its core, so to easily identify the problem:
    (set: $WD= 5* $attackmultiplier)
    (print: $WD)
    (if: (either: 0, 1) is 0)[  
     (set: $hp to $hp - $damage1) (set: $damage1 to (either:0,0.25,1,2,3,4,5,25)*5)
      (if: $hp < 1)[ [[uh-oh did you die->You barely escape]]]  
      (else:)[ Your health is $hp. 
        (live: 1s)[(goto: "fight")] 
        [[Leave that bitch alone and report to the mayor->main]]]  
    (link: "Use Attack Bonus Potion")[(set: $attackmultiplier to 2)
    (live: 10s)[(set: $attackmultiplier to 1)]]] 
        
    (else:)[(set:$ghoul_hp = $ghoul_hp - $damageh)(set: $damageh to (either:0,0.25,1,2,3,4,5,25)*$WD) 
      (if: $ghoul_hp < 1)[ [[What..What the hell are you]]]  
      (else:)[    
        Its health is $ghoul_hp.
        (live: 1s)[(goto: "fight")] 
        [[Leave that bitch alone and report to the mayor->main]]]  
    (link: "Use Attack Bonus Potion")[(set: $attackMultiplier to 2)
    (live: 10s)[(set: $attackMultiplier to 1)]]]
    
  • Khaloodxp wrote: »
    Deadshot wrote: »
    You could use the live macro. For example, if you wanted a temporary attack bonus for ten seconds you could do this:
    (link: "Use Attack Bonus Potion")[(set: $attackMultiplier to 2)
    (live: 10s)[(set: $attackMultiplier to 1)]]
    

    And then the code for the multiplier (if the opponent's health was a variable named $opponent and you dealt ten damage):
    (set: $opponent to $opponent - (10 * $multiplier))
    

    So if someone presses the link to use the potion, it activates a multiplier, which increases the damage you deal to enemies. But in ten seconds, the multiplier goes back to one, so ten times one is still just ten. Tell me if you don't understand or anything.
    I created a situation where the fight would last way more than 10s to test it and it sadly didn't work, it just stayed boosted it still is it's been 5 mins now and it's still boosted, my code is a bit more complicated so I narrowed it down to its core, so to easily identify the problem:
    (set: $WD= 5* $attackmultiplier)
    (print: $WD)
    (if: (either: 0, 1) is 0)[  
     (set: $hp to $hp - $damage1) (set: $damage1 to (either:0,0.25,1,2,3,4,5,25)*5)
      (if: $hp < 1)[ [[uh-oh did you die->You barely escape]]]  
      (else:)[ Your health is $hp. 
        (live: 1s)[(goto: "fight")] 
        [[Leave that bitch alone and report to the mayor->main]]]  
    (link: "Use Attack Bonus Potion")[(set: $attackmultiplier to 2)
    (live: 10s)[(set: $attackmultiplier to 1)]]] 
        
    (else:)[(set:$ghoul_hp = $ghoul_hp - $damageh)(set: $damageh to (either:0,0.25,1,2,3,4,5,25)*$WD) 
      (if: $ghoul_hp < 1)[ [[What..What the hell are you]]]  
      (else:)[    
        Its health is $ghoul_hp.
        (live: 1s)[(goto: "fight")] 
        [[Leave that bitch alone and report to the mayor->main]]]  
    (link: "Use Attack Bonus Potion")[(set: $attackMultiplier to 2)
    (live: 10s)[(set: $attackMultiplier to 1)]]]
    

    As greyelf said, you need to use the stop macro. Try this. I've changed the code a bit:
    (set: $WD= 5* $attackmultiplier)
    (print: $WD)
    (if: (either: 0, 1) is 0)[  
     (set: $hp to $hp - $damage1) (set: $damage1 to (either:0,0.25,1,2,3,4,5,25)*5)
      (if: $hp < 1)[ [[uh-oh did you die->You barely escape]]]  
      (else:)[ Your health is $hp. 
        (live: 1s)[(goto: "fight")] 
        [[Leave that bitch alone and report to the mayor->main]]]  
    (link: "Use Attack Bonus Potion")[(set: $attackmultiplier to 2)
    (live: 10s)[(set: $attackmultiplier to 1)(stop:)]]] 
        
    (else:)[(set:$ghoul_hp = $ghoul_hp - $damageh)(set: $damageh to (either:0,0.25,1,2,3,4,5,25)*$WD) 
      (if: $ghoul_hp < 1)[ [[What..What the hell are you]]]  
      (else:)[    
        Its health is $ghoul_hp.
        (live: 1s)[(goto: "fight")] 
        [[Leave that bitch alone and report to the mayor->main]]]  
    (link: "Use Attack Bonus Potion")[(set: $attackMultiplier to 2)
    (live: 10s)[(set: $attackMultiplier to 1)(stop:)]]]
    
  • Deadshot wrote: »
    Khaloodxp wrote: »
    Deadshot wrote: »
    You could use the live macro. For example, if you wanted a temporary attack bonus for ten seconds you could do this:
    (link: "Use Attack Bonus Potion")[(set: $attackMultiplier to 2)
    (live: 10s)[(set: $attackMultiplier to 1)]]
    

    And then the code for the multiplier (if the opponent's health was a variable named $opponent and you dealt ten damage):
    (set: $opponent to $opponent - (10 * $multiplier))
    

    So if someone presses the link to use the potion, it activates a multiplier, which increases the damage you deal to enemies. But in ten seconds, the multiplier goes back to one, so ten times one is still just ten. Tell me if you don't understand or anything.
    I created a situation where the fight would last way more than 10s to test it and it sadly didn't work, it just stayed boosted it still is it's been 5 mins now and it's still boosted, my code is a bit more complicated so I narrowed it down to its core, so to easily identify the problem:
    (set: $WD= 5* $attackmultiplier)
    (print: $WD)
    (if: (either: 0, 1) is 0)[  
     (set: $hp to $hp - $damage1) (set: $damage1 to (either:0,0.25,1,2,3,4,5,25)*5)
      (if: $hp < 1)[ [[uh-oh did you die->You barely escape]]]  
      (else:)[ Your health is $hp. 
        (live: 1s)[(goto: "fight")] 
        [[Leave that bitch alone and report to the mayor->main]]]  
    (link: "Use Attack Bonus Potion")[(set: $attackmultiplier to 2)
    (live: 10s)[(set: $attackmultiplier to 1)]]] 
        
    (else:)[(set:$ghoul_hp = $ghoul_hp - $damageh)(set: $damageh to (either:0,0.25,1,2,3,4,5,25)*$WD) 
      (if: $ghoul_hp < 1)[ [[What..What the hell are you]]]  
      (else:)[    
        Its health is $ghoul_hp.
        (live: 1s)[(goto: "fight")] 
        [[Leave that bitch alone and report to the mayor->main]]]  
    (link: "Use Attack Bonus Potion")[(set: $attackMultiplier to 2)
    (live: 10s)[(set: $attackMultiplier to 1)]]]
    

    As greyelf said, you need to use the stop macro. Try this. I've changed the code a bit:
    (set: $WD= 5* $attackmultiplier)
    (print: $WD)
    (if: (either: 0, 1) is 0)[  
     (set: $hp to $hp - $damage1) (set: $damage1 to (either:0,0.25,1,2,3,4,5,25)*5)
      (if: $hp < 1)[ [[uh-oh did you die->You barely escape]]]  
      (else:)[ Your health is $hp. 
        (live: 1s)[(goto: "fight")] 
        [[Leave that bitch alone and report to the mayor->main]]]  
    (link: "Use Attack Bonus Potion")[(set: $attackmultiplier to 2)
    (live: 10s)[(set: $attackmultiplier to 1)(stop:)]]] 
        
    (else:)[(set:$ghoul_hp = $ghoul_hp - $damageh)(set: $damageh to (either:0,0.25,1,2,3,4,5,25)*$WD) 
      (if: $ghoul_hp < 1)[ [[What..What the hell are you]]]  
      (else:)[    
        Its health is $ghoul_hp.
        (live: 1s)[(goto: "fight")] 
        [[Leave that bitch alone and report to the mayor->main]]]  
    (link: "Use Attack Bonus Potion")[(set: $attackMultiplier to 2)
    (live: 10s)[(set: $attackMultiplier to 1)(stop:)]]]
    
    pasted the code and tried it what happens is that for the first split second the attack bonus potion appears and then the button disappears (forever I think) if you don't click on it fast enough and if you do the boost remains forever
  • Hmm... Sorry, dunno what's wrong with that.
  • greyelf wrote: »
    Note that the code within a (live:) macro's associated hook will be executed repeatedly until either the Reader navigates to another passage or a related (stop:) macro is executed.

    If you want the contents of the associated hook to only occur a limited number of times then you need to use a (stop:) macro.

    a. Occur only once:
    (live: 10s)[
    	(set: $attackMultiplier to 1)
    	(stop:)
    ]
    
    b. Occur a limited number of times (eg twice):
    (set: $counter to 0)
    (live: 10s)[
    	(set: $counter to it + 1)
    	(set: $var to it + 1)
    	(if: $counter is 2)[
    		(stop:)
    	]
    ]
    
    Tried to implement it but the link would only show ONCE for a split-second and it has an a script er
    Deadshot wrote: »
    Hmm... Sorry, dunno what's wrong with that.
    don't worry dude I was able to fix it with the help of greyelf almost everything is done (I don't like to do this cause I think I will jinx myself) but I think the game will be ready in a day or two now all I have to fix is a couple of bugs that make it look bad add a few simple features and story mode and boom game done I will provide a link here once done I will also add it to the IFDB hopefully I can enter it to the best game of 2016 its not like my game is the most complex hell no I've seen open sorcery but I think it will be the most fun
  • Khaloodxp wrote: »
    greyelf wrote: »
    Note that the code within a (live:) macro's associated hook will be executed repeatedly until either the Reader navigates to another passage or a related (stop:) macro is executed.

    If you want the contents of the associated hook to only occur a limited number of times then you need to use a (stop:) macro.

    a. Occur only once:
    (live: 10s)[
    	(set: $attackMultiplier to 1)
    	(stop:)
    ]
    
    b. Occur a limited number of times (eg twice):
    (set: $counter to 0)
    (live: 10s)[
    	(set: $counter to it + 1)
    	(set: $var to it + 1)
    	(if: $counter is 2)[
    		(stop:)
    	]
    ]
    
    Tried to implement it but the link would only show ONCE for a split-second and it has an a script er
    Deadshot wrote: »
    Hmm... Sorry, dunno what's wrong with that.
    don't worry dude I was able to fix it with the help of greyelf almost everything is done (I don't like to do this cause I think I will jinx myself) but I think the game will be ready in a day or two now all I have to fix is a couple of bugs that make it look bad add a few simple features and story mode and boom game done I will provide a link here once done I will also add it to the IFDB hopefully I can enter it to the best game of 2016 its not like my game is the most complex hell no I've seen open sorcery but I think it will be the most fun

    Nice one! Good luck, and from the betas I'm looking forward to this game! And good luck with the best game of 2016 thing too! :smiley:
  • Deadshot wrote: »
    Khaloodxp wrote: »
    greyelf wrote: »
    Note that the code within a (live:) macro's associated hook will be executed repeatedly until either the Reader navigates to another passage or a related (stop:) macro is executed.

    If you want the contents of the associated hook to only occur a limited number of times then you need to use a (stop:) macro.

    a. Occur only once:
    (live: 10s)[
    	(set: $attackMultiplier to 1)
    	(stop:)
    ]
    
    b. Occur a limited number of times (eg twice):
    (set: $counter to 0)
    (live: 10s)[
    	(set: $counter to it + 1)
    	(set: $var to it + 1)
    	(if: $counter is 2)[
    		(stop:)
    	]
    ]
    
    Tried to implement it but the link would only show ONCE for a split-second and it has an a script er
    Deadshot wrote: »
    Hmm... Sorry, dunno what's wrong with that.
    don't worry dude I was able to fix it with the help of greyelf almost everything is done (I don't like to do this cause I think I will jinx myself) but I think the game will be ready in a day or two now all I have to fix is a couple of bugs that make it look bad add a few simple features and story mode and boom game done I will provide a link here once done I will also add it to the IFDB hopefully I can enter it to the best game of 2016 its not like my game is the most complex hell no I've seen open sorcery but I think it will be the most fun

    Nice one! Good luck, and from the betas I'm looking forward to this game! And good luck with the best game of 2016 thing too! :smiley:

    thx I'll try my best :smiley:
Sign In or Register to comment.