• 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!

UIButton

Samuel Bili

New Member
Joined
Oct 3, 2021
Messages
8
Reaction score
0
I created a button, but when I call the function
Lua:
mymodule:recursiveGetChildById('test')
, it returns a nil value.

teste.lua
Lua:
function init()
    mainWindow = nil
    mainButton = nil

    mainWindow = g_ui.displayUI('teste.otui')
    
    
    mainWindow:hide()
    
    connect(g_game, { onGameStart = show,
                  onGameEnd = hide })

end

function terminate()
    g_keyboard.unbindKeyDown('Shift+F12')
    mainWindow:hide()
    
    disconnect(g_game, { onGameStart = show,
                     onGameEnd = hide })
end

function hide()
  mainWindow:hide()
end

function show()
  mainWindow:show()
end

function image()
    button = mymodule:recursiveGetChildById('test')
    b.setImageSource('/images/test2')
end

teste.otui

CSS:
UIButton
  id: test
  anchors.left: parent.left
  anchors.top: parent.top
  margin-top: 50
  margin-left: 50
  width: 78
  height: 71
  image-source: /images/test
  @onClick: print('test')
  @isPressed: modules.game_teste.image()
 
First of all, you're not even calling function image() anywhere so idk how it returns anything to u.
Secondable, you're trying to get child of "mymodule" which doesn't exist anywhere.

Do it like this:
1. Create mainWindow in otui
2. Make UIBUTTON a child of mainWindow
3. In lua do local button = mainWindow:recursiveGetChildById('test')
 
I fixed it but now this error appears

error.png

teste.lua

Lua:
function init()
    mainWindow = nil
    mainButton = nil

    mainWindow = g_ui.displayUI('teste.otui')
    
    
    mainWindow:hide()
    
    connect(g_game, { onGameStart = show,
                  onGameEnd = hide })

end

function terminate()
    g_keyboard.unbindKeyDown('Shift+F12')
    mainWindow:hide()
    
    disconnect(g_game, { onGameStart = show,
                     onGameEnd = hide })
end

function hide()
  mainWindow:hide()
end

function show()
  mainWindow:show()
end

function image()
    button = mainWindow:recursiveGetChildById('test')
    button.setImageSource('/images/test2')
end

teste.otui

CSS:
MainWindow
  id: mainWindow
  width: 100
  height: 100

  UIButton
    id: test
    anchors.left: parent.left
    anchors.top: parent.top
    margin-top: 50
    margin-left: 50
    width: 78
    height: 71
    image-source: /images/test
    @onClick: print('test')
    @isPressed: modules.game_teste.image()
Post automatically merged:

First of all, you're not even calling function image() anywhere so idk how it returns anything to u.
Secondable, you're trying to get child of "mymodule" which doesn't exist anywhere.

Do it like this:
1. Create mainWindow in otui
2. Make UIBUTTON a child of mainWindow
3. In lua do local button = mainWindow:recursiveGetChildById('test')

Thank you, i solved
 
Last edited:
which files? sorry I'm new to otclient
Pretty much all files in otclient.
There is no documentation I believe so you have to look how things are done.
What I did was search for certain keywords that are likely to be used in what I need to be done.
I recommend using some program with search in all opened/directory files option. I used visual studio code for example.
 
Back
Top