Howdy, Stranger!

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

How do I restart a stopped macro? Trying to make an active time battle system.

Hello everyone.

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 :D.

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:

<<widget "next_enemy_attack">>
<<repeat 100ms>>
<<set $enemy_cd to $enemy_cd - 0.1>>
<<if $enemy_cd > 0>>
<<replace "#enemy_cd">>
Next attack: <<print Number($enemy_cd).toFixed(1)>>s
<<replace "#enemy_cd">>
Next attack: 0s
<<timed 0s>>
<<set $enemy_damage to random(10,20)
<<play attack.mp3>>
<<next 500ms>>
<<set $player_hp to $player_hp - $enemy_damage>>
<<replace #player-hp>><<print $player_hp>><</replace>>
<<timed 2s>>
<<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? :(
Sign In or Register to comment.