Frikx
Computer Science
Hey!!
I'm getting an error using modal windows. The first window is working just fine but then the second one's choiceId is constant and is always 0, which causes an error to happen with the third one because it uses the choiceId to reference the value you are looking for in an array.
This is the code... I see no error
I'm getting an error using modal windows. The first window is working just fine but then the second one's choiceId is constant and is always 0, which causes an error to happen with the third one because it uses the choiceId to reference the value you are looking for in an array.
This is the code... I see no error
Lua:
function onModalWindow(player, modalWindowId, buttonId, choiceId)
if modalWindowId == 4444 then
if buttonId == 1 then
sendGroupSpellWindow(player, choiceId)
elseif buttonId == 255 then
sendSpellWindow(player)
end
elseif modalWindowId >= 4445 and modalWindowId <= 4448 then
if buttonId == 1 then
sendInfoWindow(player, choiceId, modalWindowId - 4444)
elseif buttonId == 2 then
sendSpellWindow(player)
elseif buttonId == 255 then
sendInfoWindow(player, choiceId, modalWindowId - 4444)
end
elseif modalWindowId >= 4449 and modalWindowId <= 4452 then
if buttonId == 1 or buttonId == 255 then
sendGroupSpellWindow(player, modalWindowId - 4448)
end
end
return true
end
Lua:
function sendSpellWindow(player)
local title = getVocationName(player:getVocation():getId()) .. 'Spells'
spellWindow = ModalWindow(4444, title, 'Select group:')
if spellWindow:getId() == 4444 then
spellWindow:addButton(1, 'Show')
spellWindow:setDefaultEnterButton(1)
spellWindow:addButton(2, 'Cancel')
spellWindow:setDefaultEscapeButton(2)
for i = 1, 4 do
spellWindow:addChoice(i, intToGroup(i))
end
end
spellWindow:sendToPlayer(player)
end
function sendGroupSpellWindow(player, group)
local count = getPlayerInstantSpellCount(player)
local spells = {}
for i = 0, count - 1 do
local spell = getPlayerInstantSpellInfo(player, i)
if spell.level ~= 0 then
if group ~= 4 then
if _spells[spell.name].group == intToGroup(group):lower() then
spells[#spells + 1] = spell
end
else
if _spells[spell.name].secondarygroup == intToGroup(group):lower() then
spells[#spells + 1] = spell
end
end
end
end
local function sortFunction(a, b)
return a.level < b.level
end
table.sort(spells, sortFunction)
local text = 'Select spell:'
if #spells == 0 then
text = 'No '..intToGroup(group):lower()..' spells for your vocation.'
end
groupSpellWindow = ModalWindow(4444 + group, intToGroup(group)..' Spells', text)
if groupSpellWindow:getId() == (4444 + group) then
if #spells > 0 then
groupSpellWindow:addButton(1, 'Info')
groupSpellWindow:setDefaultEnterButton(1)
end
groupSpellWindow:addButton(2, 'Back')
if #spells == 0 then
groupSpellWindow:setDefaultEnterButton(2)
groupSpellWindow:setDefaultEscapeButton(2)
else
groupSpellWindow:setDefaultEscapeButton(2)
end
for choice, spell in ipairs(spells) do
groupSpellWindow:addChoice(i, spell.name)
end
end
groupSpellWindow:sendToPlayer(player)
end
function sendInfoWindow(player, choice, group)
local count = getPlayerInstantSpellCount(player)
local spells = {}
for i = 0, count - 1 do
local spell = getPlayerInstantSpellInfo(player, i)
if spell.level ~= 0 then
if group ~= 4 then
if _spells[spell.name].group == intToGroup(group):lower() then
spells[#spells + 1] = spell
end
else
if _spells[spell.name].secondarygroup == intToGroup(group):lower() then
spells[#spells + 1] = spell
end
end
end
end
local function sortFunction(a, b)
return a.level < b.level
end
table.sort(spells, sortFunction)
local text = 'Words: ' .. spells[choice].words .. '\n' .. 'Level: ' .. spells[choice].level .. '\n' .. 'Mana: ' .. spells[choice].mana .. '\n' .. 'Cooldown: ' .. _spells[spells[choice].name].cooldown
infoWindow = ModalWindow(4448 + group, spells[choice].name, text)
if infoWindow:getId() == (4448 + group) then
infoWindow:addButton(1, 'Back')
infoWindow:setDefaultEnterButton(1)
infoWindow:setDefaultEscapeButton(1)
end
infoWindow:sendToPlayer(player)
end