[Bug] SetUnitHasEnergyBar doesn't seem to work properly

Started by Stickman, January 30, 2017, 02:58:23 PM

Previous topic - Next topic

Stickman

Steam version 1.1.3

Simple scripts used in the test maps is basically this:


# --EnergyBarAwake-- 1/29/2017 6:17:45 PM
once
self "main" "NONE" setimage
self 100 setunitmaxenergy
self 80 setunitenergy
self 1 setunithasenergybar
endonce

:awake
(self 1 setunithasenergybar) - one script has this line, one has not
"" ->Msg
<-Msg "Bar:" concat self getunithasenergybar concat LF concat ->Msg
<-Msg "E:" concat self getunitenergy concat LF concat ->Msg
<-Msg "MaxE:" concat self getunitmaxenergy concat LF concat ->Msg
<-Msg settext


Bug 1: SetUnitHasEnergyBar doesn't create permanent change. Variable seems to revert to 0 on map loading.
Pic1: (cores to the left don't have SetUnitHasEnergyBar in the :awake part; cores to the right have)
Spoiler
[close]

Bug 2: Sometimes, energy bar persists through map loading even if GetUnitHasEnergyBar returns 0 for that core. I cannot reliably replicate the bug, but once bar "gets stuck" it will load consistently on that save, even with full game restart.
Pic2: (core to the left doesn't have SetUnitHasEnergyBar in the :awake part; core to the right has)
Spoiler
[close]

Bug seems to be related to this thread TODO - Short Term only mentions health bars

Attached: two testmaps
=====> This is a moderately pointy stick. You need to poke me with it once in three days if you need PRPL from me

knucracker

SetUnitHasEnergy/HealthBar isn't persisted.  I know this isn't the most convenient, but I opted to leave it out since it wasn't a variable I could default and hence leave out of the save game files.  Since persisting it would require me to persist it for every "unit", I left it out to make the saves a bit smaller and quicker to load (every shot, every missile is a unit for instance).

That means that if you want to make the energy bar be visible you must always do it in :Awake.  So that explains Bug 1.  Not convenient I know, but by design.

Bug 2 is more subtle.  You set the unit to have an energy bar in a once clause.  That happens exactly once. The :Awake routine runs before the once clause, though.  That's why when I first load your mission I see a bar on the left unit but "Bar:0" appears.  Now, if you save and load the mission the once clause won't run again.  The state of the energy bar also doesn't persist.  So you won't get an energy bar on subsequent save/loads.  The remedy is to set whether you want an energy bar in awake, first thing.

Stickman

=====> This is a moderately pointy stick. You need to poke me with it once in three days if you need PRPL from me