It looks like you're new here. If you want to get involved, click one of these buttons!
::StoryInit <<set $energyTotal to 100>> <<set $energy to $energyTotal>> <<set $energyLoss to 0>>
::StoryCaption <<button "">> <<set $gameDate.setHours($gameDate.getHours() + 1)>> <<set $energyLoss to 6>> <<display "Sleepy">> <</button>>
::Sleepy <<script>> var hBar = $('.energy-bar .stats-bar'), bar = hBar.find('.bar'), hit = hBar.find('.hit'); var total = State.variables.energyTotal, value = State.variables.energy, damage = State.variables.energyLoss, hitWidth = 0, barWidth = (value / total) * 100, delayReset = false; if (damage != 0) { hitWidth = (damage / value) * 100; value -= damage; barWidth = (value / total) * 100; State.variables.energy = value; State.variables.energyLoss = 0; delayReset = true; } hBar.data('total', total); hBar.data('value', value); /*hit.css('width', hitWidth + "%");*/ bar.css('width', barWidth + "%"); if (delayReset) { setTimeout(function(){ /*hit.css({'width': '0'});*/ bar.css('width', (State.variables.energy / State.variables.energyTotal) * 100 + "%"); }, 500); } <</script>>
::PassageHeader <div class="stats-wrapper energy-bar"> <span>Energi</span> <div class="stats-bar"> <div class="bar"> <div class="hit"></div> </div> </div> </div>
Comments
In the Health bar in right side... thread you linked to you will notice that the Javascript code in 2c is contained within a postrender["Update Health Bar"] event handler, which is called after each passage is shown to the reader.
That event is one way to do as @TheMadExile suggested, another is to use a PassageDone special passage like the following to invoke your Sleepy passage.