• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Why is my opacityPanel a nil value?

Heon

Advanced OT User
Joined
Jul 29, 2012
Messages
320
Solutions
2
Reaction score
217
Location
Croatia
Final EDIT: Fixed! function setOption() was called before init so I initialized panel there and my .otui was wrong aswell fixed it too and everything is working now.

EDIT #1: Okay so function setOption() is being called before init() so thats why its uninitialized, however does anyone know where it can be called? Or suggest a method to find out.

So first of all I'm trying to add option to change opacity to game panels (skills, battle list, etc.), so now I'm trying to configure a new panel for Opacity in Options which I succeeded to do:
ss1.png

Now I was trying to add a scrollbar there just like for example Turn delay or Hotkey delay just for opacity and I'm getting an error that the opacityPanel is a nil value:
Code:
ERROR: lua function callback failed: LUA ERROR:
/client_options/options.lua:248: attempt to index upvalue 'opacityPanel' (a nil value)
stack traceback:
    [C]: in function '__index'
    /client_options/options.lua:248: in function 'setOption'
    /client_options/options.lua:142: in function 'setup'
    /client_options/options.lua:123: in function </client_options/options.lua:123>

in options.lua I added in default options table at the end
Lua:
skillsOpacity = 100,

in options.lua I added in where rest of the locals are:
Lua:
local opacityPanel

in options.lua->init() i added:
Lua:
opacityPanel = g_ui.loadUI('opacity.otui')
optionsTabBar:addTab(tr('Opacity'), opacityPanel, '/images/optionstab/audio')

in options.lua->setoption() i added:

Lua:
elseif key == 'skillsOpacity' then
  opacityPanel:getChildById('skillsOpacityLabel'):setText(tr('Opacity: %s', value))

my opacity.otui looks like this:
Code:
Panel
  Label
    id: skillsOpacityLabel
    !text: tr('Opacity: %s', 100)
    @onSetup: |
       local val = modules.client_options.getOption('skillsOpacity')
       self:setText(tr('Opacity: %s', val))
  
  OptionScrollBar
    id: skillsOpacity
    anchors.left: parent.left
    anchors.right: parent.right
    anchors.top: prev.bottom
    minimum: 0
    maximum: 100

full options.lua here: hastebin (https://hastebin.com/cepumezija.rb)

What I'm confused about is that in init() after the call of this line:
Lua:
opacityPanel = g_ui.loadUI('opacity.otui')
opacityPanel is NOT set to nil (I checked in output) but when the function:
Lua:
setOption('skillsOpacity')
is called my opacityPanel is set to nil?
Am I missing something here, did I do something wrong or did I forgot to register something else?
In advance, I apologize for my ignorance I have just this week started learning OTC. Theres a high chance I missed something trivial.
 
Last edited:
Back
Top