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

TFS 1.X+ Modal Window

trunksagain

New Member
Joined
May 22, 2019
Messages
17
Reaction score
1
Hello, guys. Any chance to get text from choiceId in my modal window? See:
The function is:
Code:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
I can access the choiceId, but what about the "choice name"? Is it possible?
 
As far as I can remember you cannot access it, you have to keep a reference somewhere before adding it as a choice, for what particular reason do you need it?
 
Use this. [TFS 1.2] Modal Window Helper Lib (https://otland.net/threads/tfs-1-2-modal-window-helper-lib.238773/)

You can use this example code here to see how to get the choice the user selects:
Lua:
local window = ModalWindow {title = 'abc'}

window:addChoice('a')
window:addChoice('b')
window:addChoice('c')

window:addButton('Quit')
window:setDefaultEscapeButton('Quit')

window:addButton('Select')
window:setDefaultEnterButton('Select', function(button, choice)
    print('Player chose '.. choice.text)
end)

window:sendToPlayer(player)
 
As far as I can remember you cannot access it, you have to keep a reference somewhere before adding it as a choice, for what particular reason do you need it?
Because I have a table with names into keys, and I want to access the values from my table with the choice value from modal. For example:

Code:
table = {
    ['crystal coin'] = {
        msg = 'My message'
    }
}
My table isn't possible to get index value because it isn't a sequence, so... If I wanna access the value from my key 'crystal coin', I need to pass table['crystal coin'], right? So, if 'crystal coin' is into my modal, I can't access him because I only have choiceId value, not a name.
 
Use this. [TFS 1.2] Modal Window Helper Lib (https://otland.net/threads/tfs-1-2-modal-window-helper-lib.238773/)

You can use this example code here to see how to get the choice the user selects:
Lua:
local window = ModalWindow {title = 'abc'}

window:addChoice('a')
window:addChoice('b')
window:addChoice('c')

window:addButton('Quit')
window:setDefaultEscapeButton('Quit')

window:addButton('Select')
window:setDefaultEnterButton('Select', function(button, choice)
    print('Player chose '.. choice.text)
end)

window:sendToPlayer(player)
Thank you. Is it works for 1.3?
 
Back
Top