-
December 14th, 2022, 07:11 #1
Is there ANY way I get the global lua value from a template?
I do not want to have to copy the entire template function (tried with super but can't get global value) here but after experimenting all over I can't find out how to not have to copy the entire CoreRPG\common\scripts\toolbar.lua as I need access to the global aButtons at the top of the file. This all comes down to the way the map toolbar buttons for Target all friends and target all foes were grouped with the clear target button. As those buttons are evil for a player (can see things they should never see) I want to turn them off and on optionally. I can turn the entire toolbar_targeting group off with very little override footprint. But to do just the two I'm not seeing a way to do it short of overrding the entire toolbar.lua file which of course means stomping anyone else using it. Even tried breaking up the crazy toolbar 30 stuff but was just as bad of an impact.
Here is what I've currently got - what I'd like to do is accomplish this exact same thing without having to override a bunch of code some other extension might be overriding... RED BOLD is code that I added... the following all works perfectly - just STOMPS the whole file.
CoreRPG\common\scripts\toolbar.lua
Code:local nButtons = 0; local aButtons = {}; local nButtonSize = 20; local nButtonHorzMargin = 1; local nButtonVertMargin = 2; function onInit() if parameters then if parameters[1].horzmargin then nButtonHorzMargin = tonumber(parameters[1].horzmargin[1]) or nButtonHorzMargin; end if parameters[1].vertmargin then nButtonVertMargin = tonumber(parameters[1].vertmargin[1]) or nButtonVertMargin; end if parameters[1].buttonsize then nButtonSize = tonumber(parameters[1].buttonsize[1]) or nButtonSize; end end if button and type(button[1]) == "table" then for k, v in ipairs(button) do if v.id and v.icon then local sID = v.id[1]; local sIcon = v.icon[1]; local sTooltip = ""; if v.tooltipres then sTooltip = Interface.getString(v.tooltipres[1]); elseif v.tooltip then sTooltip = v.tooltip[1]; end addButton(sID, sIcon, sTooltip); end end end if self.onValueChanged then self.onValueChanged(); end OptionsManager.registerCallback("NO_MAP_TARGETING", noMapToolbarTargeting); end function onClose() OptionsManager.unregisterCallback("NO_MAP_TARGETING", noMapToolbarTargeting); end function addButton(sID, sIcon, sTooltip) local bToggle = false; if toggle then bToggle = true; end local button = window.createControl("toolbar_button", ""); if button then local x = nButtonHorzMargin + (nButtons * (nButtonSize + nButtonHorzMargin)); nButtons = nButtons + 1; local nBarWidth = x + nButtonSize + nButtonHorzMargin; setAnchoredWidth(nBarWidth); setAnchoredHeight(nButtonSize + (2 * nButtonVertMargin)); local w,h = getSize(); button.setAnchor("left", getName(), "left", "absolute", x); button.setAnchor("top", getName(), "top", "absolute", nButtonVertMargin); button.setAnchoredWidth(nButtonSize); button.setAnchoredHeight(nButtonSize); button.configure(self, sID, sIcon, sTooltip, bToggle); aButtons[sID] = button; if isVisible() then button.setVisible(true); end end end function setActive(target) for id, button in pairs(aButtons) do if id == target then button.setValue(1); else button.setValue(0); end end end function highlightAll() for id, button in pairs(aButtons) do button.setValue(1); end end function setVisibility(bVisible) if Session then setVisible(bVisible); for id, button in pairs(aButtons) do if not Session.IsHost and (id == "foe" or id == "friend") and OptionsManager.isOption("NO_MAP_TARGETING", "on") then button.setVisible(false); else button.setVisible(bVisible); end end end end function noMapToolbarTargeting() if Session then for id, button in pairs(aButtons) do if not Session.IsHost and (id == "foe" or id == "friend") then if OptionsManager.isOption("NO_MAP_TARGETING", "on") then button.setVisible(false); else button.setVisible(true); end end end end end
Code:<root> <template name="toolbar_30" merge="join"> <genericcontrol merge="join"> <script file="common/scripts/toolbar.lua" /> </genericcontrol> </template> </root>
Free(Forums/Forge) Extension(FGU 5E):
Paid (Forge) Extension(FGU 5E):
-
December 14th, 2022, 15:20 #2
Still would like to know how to access a global in template lua override - but I've rewritten this much simpler and just made myself a image_toolbar_targeting_lite to switch out between image_toolbar_targeting template.
Free(Forums/Forge) Extension(FGU 5E):
Paid (Forge) Extension(FGU 5E):
-
December 14th, 2022, 15:51 #3
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,541
They are explicitly defined as local by design; and are not meant to be overriden. They can not be accessed externally.
Regards,
JPG
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks