NetImmerse Posted March 29, 2020 Share Posted March 29, 2020 Hello DST community. I need help with some questions regarding modmain.lua and prefabs. I have a global variable stored in prefab and i want to initialize it in modmain for a widget which shows the value of this variable. But the value always returns nil. local valuecounter = GLOBAL.require "widgets/valuecounter" AddClassPostConstruct("widgets/statusdisplays", function(self) if self.owner.prefab == "char" then self.myvalue = self:AddChild(valuecounter(self.owner)) self.myvalue:SetPosition(-60, -120, 0) self.owner:ListenForEvent("scountdirty", function(inst) self.myvalue:Update(inst._scount:value()) end) end end) local myvalue = GLOBAL.require "prefabs/char" local function updatescount(inst) inst._scount:set(myvalue.X_value) end AddPrefabPostInit("char", function(inst) inst._scount = GLOBAL.net_ushortint(inst.GUID, "p._scount", "scountdirty") if GLOBAL.TheWorld.ismastersim then inst._scount:set_local(0) inst._scount:set(0) inst:ListenForEvent("valupdate", updatescount) end end) How do i do it properly? Also i've read that PushEvent can push events with tables. Can i push an event with a variable stored in this table? If so, how can i access this variable? Thanks in advance. Link to comment https://forums.kleientertainment.com/forums/topic/116883-prefab-variable-widget/ Share on other sites More sharing options...
rawii22 Posted May 8, 2020 Share Posted May 8, 2020 Does this variable apply to only one instance of the prefab in question? Just to review, so you want to make a variable's value appear in a widget that is possibly changed by some condition in the prefab? Link to comment https://forums.kleientertainment.com/forums/topic/116883-prefab-variable-widget/#findComment-1331878 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now