Jump to content

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...