sirrNaDE Posted September 19, 2021 Share Posted September 19, 2021 hey there. there is a problem im having. im trying to implement a widget, but it just doesnt want to show. it doesnt do any errors, or crashes, so best bet would be to ask professionals. local Widget = require "widgets/widget" Assets = { Asset( "IMAGE", "images/blind.tex" ), Asset( "ATLAS", "images/blind.xml" ), } local blind = Class(Widget, function(self, owner) self.owner = owner Widget._ctor(self, "InkOver") self:SetClickable(false) self:IsDeepestFocus() self.anim:SetHAnchor(ANCHOR_MIDDLE) self.anim:SetVAnchor(ANCHOR_MIDDLE) self.anim:SetScaleMode(SCALEMODE_FIXEDSCREEN_NONDYNAMIC) self.anim:GetAnimState():SetBank("blind") self.anim:GetAnimState():SetBuild("blind") print "it works" end) return blind this is how the file of my widget looks like. i have the "print "it works"" just so i can tell it works, but it doesnt even print that into the console, so im definitely doing something wrong here the section in the modmain looks like this if it helps in any way (there are also included lines, that delete the map, and it would be a bad idea to rewrite all of the ifs, so i just stuck it in... the main part is "if inst.HUD then" upto its end): local _G = GLOBAL AddPlayerPostInit(function(inst) if _G.TheNet:GetIsClient() or not _G.TheNet:GetServerIsDedicated() then if inst.prefab == "waverly" then _G.TheWorld.minimap.MiniMap:ContinuouslyClearRevealedAreas(true) if inst.HUD then inst.HUD.blind = inst.HUD.overlayroot:AddChild(blind(inst)) end else _G.TheWorld.minimap.MiniMap:ContinuouslyClearRevealedAreas(false) end end end) Link to comment https://forums.kleientertainment.com/forums/topic/133772-add%C3%ADng-a-screenwidget/ Share on other sites More sharing options...
Monti18 Posted September 20, 2021 Share Posted September 20, 2021 (edited) If you implement widgets, you need to add them to widgets/controls to have a way to call them. This means: local function AddWidgetBlind(self) if self.owner and self.owner.prefab == "waverly" then local Blind = require "widgets/blind" self.BlindHUD = self:AddChild(Blind(self.owner)) end end AddClassPostConstruct("widgets/controls", AddWidgetBlind) Then you need to change your modmain section this way: local _G = GLOBAL AddPlayerPostInit(function(inst) if _G.TheNet:GetIsClient() or not _G.TheNet:GetServerIsDedicated() then _G.TheWorld.minimap.MiniMap:ContinuouslyClearRevealedAreas(true) else _G.TheWorld.minimap.MiniMap:ContinuouslyClearRevealedAreas(false) end end end) As you already activated the widget for all characters that are waverly, you don't need to activate it a second time. If you want to access it, you need to use: inst.HUD.controls.BlindHUD which is the name as you saved it before. Edited September 27, 2021 by Monti18 changed to self.owner.prefab 1 Link to comment https://forums.kleientertainment.com/forums/topic/133772-add%C3%ADng-a-screenwidget/#findComment-1496640 Share on other sites More sharing options...
sirrNaDE Posted September 20, 2021 Author Share Posted September 20, 2021 (im really sorry im writing this late after you posted it) so, i got a few things: i had the "if inst == "waverly" then" because of the map deleting thing, so it works just for the character waverly... so is the line with "self.owner" really necceceary? another question is, that "BlindHUD" is the name of the construct file? Link to comment https://forums.kleientertainment.com/forums/topic/133772-add%C3%ADng-a-screenwidget/#findComment-1496809 Share on other sites More sharing options...
Monti18 Posted September 20, 2021 Share Posted September 20, 2021 (edited) Oh sorry I forgot that you need the inst.prefab == "waverly" for the minimap, so leave it in there! But you will still need the self.owner line as you add it in classpostconstruct which is takes place in a different location than playerpostinit. You could theoretically not use it and then hide the widget for all players and in the playerpostinit only show it for waverly, but that would not make much sense as then the other characters would have it too just hidden. BlindHUD is just a name I came up with, you can change it to what you want. local Blind = require "widgets/you_widget_name" local function AddWidgetBlind(self) if self.owner and self.owner.prefab == "waverly" then local Blind = require "widgets/blind" self.whatever_you_want = self:AddChild(Blind(self.owner)) end end AddClassPostConstruct("widgets/controls", AddWidgetBlind) I just took the name blind from the code you showed, but you can also call it what you want as long as you define it properly beforehand and always use the same variable for it. Edited September 27, 2021 by Monti18 changed to self.owner.prefab 1 Link to comment https://forums.kleientertainment.com/forums/topic/133772-add%C3%ADng-a-screenwidget/#findComment-1496811 Share on other sites More sharing options...
sirrNaDE Posted September 20, 2021 Author Share Posted September 20, 2021 (edited) oh i see what you mean. anyways, i put it in like this: local _G = GLOBAL AddPlayerPostInit(function(inst) if _G.TheNet:GetIsClient() or not _G.TheNet:GetServerIsDedicated() then if inst.prefab == "waverly" then _G.TheWorld.minimap.MiniMap:ContinuouslyClearRevealedAreas(true) inst.HUD.controls.BlindHUD = inst.HUD.overlayroot:AddChild(blind(inst)) else _G.TheWorld.minimap.MiniMap:ContinuouslyClearRevealedAreas(false) end end end) the HUD is somehow making a problem, where it thinks its a nil value.. so im definitely missing some "local HUD = require .." another thing is, i dont think im doing the AddChind(blind(inst)) right, since its already explained in the widgets/construct file? Edited September 20, 2021 by sirrNaDE (edited the blind to BlindHUD, so it wont get confused Link to comment https://forums.kleientertainment.com/forums/topic/133772-add%C3%ADng-a-screenwidget/#findComment-1496818 Share on other sites More sharing options...
Monti18 Posted September 20, 2021 Share Posted September 20, 2021 (edited) I think the problem here is that the HUD is not initialzed when you addplayerpostinit is called, so HUD is nil. Do it the way I showed you in my first answer: --modmain local Blind = require "widgets/construct" --if you named your widget in the widgets folder construct, leave it like this otherwise change it the name of your file local function AddWidgetBlind(self) if self.owner and self.owner.prefab == "waverly" then local Blind = require "widgets/blind" self.BlindHUD = self:AddChild(Blind(self.owner)) end end AddClassPostConstruct("widgets/controls", AddWidgetBlind) This adds your widget to the HUD of only your character. I don't think this will work with AddPlayerPostInit. --modmain local _G = GLOBAL AddPlayerPostInit(function(inst) if _G.TheNet:GetIsClient() or not _G.TheNet:GetServerIsDedicated() then if inst.prefab == "waverly" then _G.TheWorld.minimap.MiniMap:ContinuouslyClearRevealedAreas(true) else _G.TheWorld.minimap.MiniMap:ContinuouslyClearRevealedAreas(false) end end end) And this for your minimap. Edited September 27, 2021 by Monti18 changed to self.owner.prefab 2 Link to comment https://forums.kleientertainment.com/forums/topic/133772-add%C3%ADng-a-screenwidget/#findComment-1496826 Share on other sites More sharing options...
sirrNaDE Posted September 20, 2021 Author Share Posted September 20, 2021 alright, i think it might work now, but my dumb ass didnt include a path to the images in the "blind" widget function, so im gonna find a way tommorow. thanks alot so far, you are definitely doing god's work 1 Link to comment https://forums.kleientertainment.com/forums/topic/133772-add%C3%ADng-a-screenwidget/#findComment-1496834 Share on other sites More sharing options...
sirrNaDE Posted September 27, 2021 Author Share Posted September 27, 2021 hey there, sorry that im reviving an old post, but is this still the command that i need to use to enable the widget? inst.HUD.controls.BlindHUD because it says that "HUD" and "controls" is a nil value. the way i'm putting it in is into the AddPlayerPostInit like this: AddPlayerPostInit(function(inst) if _G.TheNet:GetIsClient() or not _G.TheNet:GetServerIsDedicated() then if inst.prefab == "waverly" then inst.HUD.controls.BlindHUD() _G.TheWorld.minimap.MiniMap:ContinuouslyClearRevealedAreas(true) else _G.TheWorld.minimap.MiniMap:ContinuouslyClearRevealedAreas(false) end end end) so it gets the inst. property, and gets used instantly, as my character loads in i did try to require "widgets/controls", since it seems that it is from over there, but it still manages to stay a nil value hope you can take a look at it Link to comment https://forums.kleientertainment.com/forums/topic/133772-add%C3%ADng-a-screenwidget/#findComment-1498860 Share on other sites More sharing options...
Monti18 Posted September 27, 2021 Share Posted September 27, 2021 The widget will be enabled by default if you do it the way I showed you in my previous post. As I also said before, when calling AddPlayerPostInit, the HUD of the player is not yet initialized, so it doesn't exist. Link to comment https://forums.kleientertainment.com/forums/topic/133772-add%C3%ADng-a-screenwidget/#findComment-1499050 Share on other sites More sharing options...
sirrNaDE Posted September 27, 2021 Author Share Posted September 27, 2021 so, this is how the thing in modmain looks like: --modmain local Blind = require "widgets/blind" --if you named your widget in the widgets folder construct, leave it like this otherwise change it the name of your file local function AddWidgetBlind(self) if self.owner and self.owner == "waverly" then local Blind = require "widgets/blind" self.Blind = self:AddChild(Blind(self.owner)) print "this one works" end end AddClassPostConstruct("widgets/controls", AddWidgetBlind) pretty much exactly the same, except i renamed the file to be more... remote. this is how the widgets/blind file looks like: local Widget = require "widgets/widget" Assets = { Asset( "IMAGE", "images/blind.tex" ), Asset( "ATLAS", "images/blind.xml" ), } local blind = Class(Widget, function(self, owner) self.owner = owner Widget._ctor(self, "Blind") self.blind = self:AddChild(Image("images/blind.xml", "images/blind.tex")) self:SetClickable(false) self:IsDeepestFocus() self.blind:SetVRegPoint(ANCHOR_MIDDLE) self.blind:SetHRegPoint(ANCHOR_MIDDLE) self.blind:SetHAnchor(ANCHOR_MIDDLE) self.blind:SetVAnchor(ANCHOR_MIDDLE) self.blind:SetScaleMode(SCALEMODE_FILLSCREEN) self:Show() end) return blind yet it still manages to not show any widgets i was pretty much mashing stuff that i could, to get at least some kind of reactions from that game at that point. thanks for correcting it, and my bad for literally doing the same thing twice at that point Link to comment https://forums.kleientertainment.com/forums/topic/133772-add%C3%ADng-a-screenwidget/#findComment-1499073 Share on other sites More sharing options...
Monti18 Posted September 27, 2021 Share Posted September 27, 2021 The print "this one works" is printed right? Does the client log shows something? You also didn't forget to load the image in the modmain? If not, you can upload or DM me the mod and I will have a look. Link to comment https://forums.kleientertainment.com/forums/topic/133772-add%C3%ADng-a-screenwidget/#findComment-1499076 Share on other sites More sharing options...
sirrNaDE Posted September 27, 2021 Author Share Posted September 27, 2021 the "this one works" doesnt really print anything, and i load the images through the "Assets" function, which i hope is the correct way? gonna dm you i think, or i can just give you my whole modmain, since thats pretty much all thats changed from the basic character template Link to comment https://forums.kleientertainment.com/forums/topic/133772-add%C3%ADng-a-screenwidget/#findComment-1499087 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