TFS 1.X+ Modal Window

trunksagain

New Member
Joined
May 22, 2019
Messages
15
Best answers
0
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?
 

Evil Hero

Legacy Member
Joined
Dec 12, 2007
Messages
1,163
Best answers
13
Reaction score
535
Location
Germany
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?
 

Stigma

Veteran OT User
Joined
Feb 14, 2015
Messages
4,700
Best answers
414
Reaction score
2,261
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)
 
OP
T

trunksagain

New Member
Joined
May 22, 2019
Messages
15
Best answers
0
Reaction score
1
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.
 
OP
T

trunksagain

New Member
Joined
May 22, 2019
Messages
15
Best answers
0
Reaction score
1
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?
 
Top