Modifying GUI Values without Globals

Dalin SeivewrightDalin Seivewright 0x0000221E Join Date: 2007-10-20 Member: 62685Members, Constellation
edited August 2015 in Modding
I have replaced the GUIWelderDisplay with some custom code using Class_ReplaceMethod. The code changes involve some variables that will change over time. The NS2 code base is riddled with Global variables (which incidentally, makes me want to throw monitors) and they seem necessary to update the GUI state.

For example, the Welder class uses the following to update its default WelderDisplay:
    if self.ammoDisplayUI then
        local progress = PlayerUI_GetUnitStatusPercentage()
        self.ammoDisplayUI:SetGlobal("weldPercentage", progress)
    end

I cannot use the same as I don't think there is a way to add global variables to a particular class file... because... well.. they're Globals.
So my question is this: Aside from just using a custom GUI Class and overwriting the relevant parts in Welder, is there any other way I can go about updating the GUI class?

Note: I do define Setters for my custom code in the form of:
function  GUIWelderDisplay:MySetterFunction
However, calling Class_Reload nets me a lovely Assert failure on Line 84 of Class.lua. I'm assuming that Class_Reload is only needed when making changes to existing functions, not simply adding them but please correct me if I'm wrong. Assuming I am correct, using:
self.ammoDisplayUI:MySetterFunction
fails as it cannot find this function, so I'm assuming self.ammoDisplayUI is not a GUIWelderDisplay instance directly.

What am I doing horrible wrong?

Comments

  • xDragonxDragon Join Date: 2012-04-04 Member: 149948Members, NS2 Playtester, Squad Five Gold, NS2 Map Tester, Reinforced - Shadow
    You would probably have an easier time making your own custom GUIWelderDisplay and just changing the code in the welder/yourweapon to load that instead. The weapon ammo counters display in their own VMs which is why those global variables are used. Its also what makes modding them with hooks a lot harder.
  • Dalin SeivewrightDalin Seivewright 0x0000221E Join Date: 2007-10-20 Member: 62685Members, Constellation
    xDragon wrote: »
    You would probably have an easier time making your own custom GUIWelderDisplay and just changing the code in the welder/yourweapon to load that instead. The weapon ammo counters display in their own VMs which is why those global variables are used. Its also what makes modding them with hooks a lot harder.

    Thanks. I had a feeling a custom GUI class was going to be needed.
Sign In or Register to comment.