Lately, I've switched over to sugarcube 2 and I'm loving the "timed" and "repeat" macros. In combination with some <<replace>> macros, I've managed to build up a battle system that relies on just ONE passage
Here's what I'm trying to achieve: An enemy creature attacks the player every 4 seconds, and the repeat macro restarts itself.
The Problem: I want to play a sound effect once that occurs, and I want to delay the restarting of the "enemy_attack_cd" macro for a few milliseconds. So I try to <<stop>> the repeat macro that counts down the seconds remaining to the next attack, and I've not been able to restart it. Sorry if this explanation is terrible, but here's the code:
<<set $enemy_cd to $enemy_cd - 0.1>>
<<if $enemy_cd > 0>>
Next attack: <<print Number($enemy_cd).toFixed(1)>>s
Next attack: 0s
<<set $enemy_damage to random(10,20)
<<set $player_hp to $player_hp - $enemy_damage>>
<<replace #player-hp>><<print $player_hp>><</replace>>
<<set $enemy_cd to 5s>>
Basically what I tried
to do was put the widget within itself, hoping that that would restart it after a <<timed>> delay, but I guess I'm going about this the wrong way. Does anyone have a better idea of going about this?