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

Spell list module Error

Status
Not open for further replies.

Nokturno

Not a human
Joined
Aug 7, 2009
Messages
558
Solutions
2
Reaction score
400
sup ppl im traying to add some extra labels + labelvalues to the spell list module but im getting errors in the otui file
dont know if someone could give me a hand with this, I would appreciate it alot.

so this is my spelllist

my latest commits:
vitality
strenght
defence
dexterity

theres where the problem starts
everything was just working fine

Code:
SpellListLabel < Label
  font: verdana-11px-monochrome
  background-color: alpha
  text-offset: 42 3
  focusable: true
  height: 36
  image-clip: 0 0 32 32
  image-size: 32 32
  image-offset: 2 2
  image-source: /images/game/spells/defaultspells

  $focus:
    background-color: #ffffff22
    color: #ffffff

SpellInfoLabel < Label
  width: 70
  font: verdana-11px-monochrome
  text-align: right
  margin-left: 10
  margin-top: 5

SpellInfoValueLabel < Label
  text-align: left
  width: 190
  margin-left: 10
  margin-top: 5

FilterButton < Button
  width: 64
  anchors.left: prev.right
  anchors.top: spellList.bottom
  @onClick: toggleFilter(self)
  margin: 5 0 0 6
  color: #630000
  $on:
    color: green

MainWindow
  id: spelllistWindow
  !text: tr('Spell List')
  size: 550 550
  @onEscape: toggle()

  TextList
    id: spellList
    vertical-scrollbar: spellsScrollBar
    anchors.top: parent.top
    anchors.left: parent.left
    anchors.bottom: next.top
    margin-bottom: 10
    padding: 1
    width: 210
    focusable: false

  Button
    id: buttonCancel
    !text: tr('Close')
    width: 64
    anchors.right: parent.right
    anchors.bottom: parent.bottom
    @onClick: toggle()

  VerticalScrollBar
    id: spellsScrollBar
    anchors.top: spellList.top
    anchors.bottom: spellList.bottom
    anchors.right: spellList.right
    step: 50
    pixels-scroll: true

  SpellInfoLabel
    id: labelName
    anchors.left: spellList.right
    anchors.top: spellList.top
    !text: tr('Name') .. ':'

  Label
    anchors.left: parent.left
    anchors.top: spellList.bottom
    !text: tr('Filters') .. ':'
    margin-top: 8

  FilterButton
    id: buttonFilterIntelligence
    width: 80
    !text: tr('Intelligence')
    !tooltip: tr('Hide spells for higher intelligence')

  FilterButton
    id: buttonFilterFaith
    width: 64
    !text: tr('Faith')
    !tooltip: tr('Hide spells for higher faith')

  SpellInfoLabel
    id: labelFormula
    anchors.left: spellList.right
    anchors.top: labelName.bottom
    !text: tr('Formula') .. ':'

  SpellInfoLabel
    id: labelGroup
    anchors.left: spellList.right
    anchors.top: labelFormula.bottom
    !text: tr('Group') .. ':'

  SpellInfoLabel
    id: labelType
    anchors.left: spellList.right
    anchors.top: labelGroup.bottom
    !text: tr('Type') .. ':'

  SpellInfoLabel
    id: labelCooldown
    anchors.left: spellList.right
    anchors.top: labelType.bottom
    !text: tr('Cooldown') .. ':'

  SpellInfoLabel
    id: labelVitality
    anchors.left: spellList.right
    anchors.top: labelCooldown.bottom
    !text: tr('Vitality') .. ':'
   
  SpellInfoLabel
    id: labelStrenght
    anchors.left: spellList.right
    anchors.top: labelVitality.bottom
    !text: tr('Strenght') .. ':'
   
SpellInfoLabel
    id: labelDefence
    anchors.left: spellList.right
    anchors.top: labelStrenght.bottom
    !text: tr('Defence') .. ':'
   
SpellInfoLabel
    id: labelDexterity
    anchors.left: spellList.right
    anchors.top: labelDefence.bottom
    !text: tr('Dexterity') .. ':'
   
  SpellInfoLabel
    id: labelFaith
    anchors.left: spellList.right
    anchors.top: labelDexterity.bottom
    !text: tr('Faith') .. ':'

  SpellInfoLabel
    id: labelIntelligence
    anchors.left: spellList.right
    anchors.top: labelFaith.bottom
    !text: tr('Intelligence') .. ':'

  SpellInfoLabel
    id: labelMana
    anchors.left: spellList.right
    anchors.top: labelIntelligence.bottom
    !text: tr('Mana') .. ' / ' .. tr('Soul') .. ':'

  SpellInfoLabel
    id: labelDescription
    anchors.left: spellList.right
    anchors.top: labelMana.bottom
    !text: tr('Description') .. ':'

  SpellInfoValueLabel
    id: labelNameValue
    anchors.left: labelName.right
    anchors.top: spellList.top

  SpellInfoValueLabel
    id: labelFormulaValue
    anchors.left: labelFormula.right
    anchors.top: labelNameValue.bottom

  SpellInfoValueLabel
    id: labelGroupValue
    anchors.left: labelGroup.right
    anchors.top: labelFormulaValue.bottom

  SpellInfoValueLabel
    id: labelTypeValue
    anchors.left: labelType.right
    anchors.top: labelGroupValue.bottom

  SpellInfoValueLabel
    id: labelCooldownValue
    anchors.left: labelCooldown.right
    anchors.top: labelTypeValue.bottom
   
  SpellInfoValueLabel
    id: labelVitalityValue
    anchors.left: labelVitality.right
    anchors.top: labelCooldownValue.bottom
   
  SpellInfoValueLabel
    id: labelStrenghtValue
    anchors.left: labelStrenght.right
    anchors.top: labelVitalityValue.bottom
   
  SpellInfoValueLabel
    id: labelDefenceValue
    anchors.left: labelDefence.right
    anchors.top: labelStrenghtValue.bottom
   
  SpellInfoValueLabel
    id: labelDexterityValue
    anchors.left: labelDexterity.right
    anchors.top: labelDefenceValue.bottom

  SpellInfoValueLabel
    id: labelFaithValue
    anchors.left: labelFaith.right
    anchors.top: labelDexterityValue.bottom

  SpellInfoValueLabel
    id: labelIntelligenceValue
    anchors.left: labelIntelligence.right
    anchors.top: labelFaithValue.bottom

  SpellInfoValueLabel
    id: labelManaValue
    anchors.left: labelMana.right
    anchors.top: labelIntelligenceValue.bottom

  SpellInfoValueLabel
    id: labelDescriptionValue
    anchors.left: labelDescription.right
    anchors.top: labelManaValue.bottom

  Label
    id: labelGroupFilter
    anchors.top: labelManaValue.bottom
    anchors.left: spellsScrollBar.right
    width: 70
    font: verdana-11px-monochrome
    !text: tr('Group')
    margin-top: 30
    margin-left: 20

  CheckBox
    id: groupBoxAny
    anchors.left: prev.left
    anchors.top: prev.bottom
    margin-top: 3
    margin-left: 3
    !text: tr('Any')
    width: 75

  CheckBox
    id: groupBoxAttack
    anchors.left: prev.left
    anchors.top: prev.bottom
    margin-top: 3
    !text: tr('Attack')
    width: 75

  CheckBox
    id: groupBoxHealing
    anchors.left: prev.left
    anchors.top: prev.bottom
    margin-top: 3
    !text: tr('Healing')
    width: 75

  CheckBox
    id: groupBoxSupport
    anchors.left: prev.left
    anchors.top: prev.bottom
    margin-top: 3
    !text: tr('Support')
    width: 75

and this is my Lua

Lua:
local SpelllistProfile = 'Default'

spelllistWindow       = nil
spelllistButton       = nil
spellList             = nil
nameValueLabel        = nil
formulaValueLabel     = nil
groupValueLabel       = nil
typeValueLabel        = nil
cooldownValueLabel    = nil
vitalityValueLabel    = nil
strenghtValueLabel    = nil
defenceValueLabel     = nil
dexterityValueLabel   = nil
faithValueLabel       = nil
intelligenceValueLabel = nil
manaValueLabel        = nil
premiumValueLabel     = nil
descriptionValueLabel = nil

groupBoxAny           = nil
groupBoxAttack        = nil
groupBoxHealing       = nil
groupBoxSupport       = nil

groupRadioGroup       = nil

-- consts
FILTER_GROUP_ANY          = 0
FILTER_GROUP_ATTACK       = 1
FILTER_GROUP_HEALING      = 2
FILTER_GROUP_SUPPORT      = 3

-- Filter Settings
local filters = {
  intelligence = false,
  faith        = false,
  groupId      = FILTER_GROUP_ANY
}

function getSpelllistProfile()
  return SpelllistProfile
end

function setSpelllistProfile(name)
  if SpelllistProfile == name then return end

  if SpelllistSettings[name] and SpellInfo[name] then
    local oldProfile = SpelllistProfile
    SpelllistProfile = name
    changeSpelllistProfile(oldProfile)
  else
    perror('Spelllist profile \'' .. name .. '\' could not be set.')
  end
end

function online()
  if g_game.getFeature(GameSpellList) then
    spelllistButton:show()
  else
    spelllistButton:hide()
  end
end

function offline()
  resetWindow()
end

function init()
  connect(g_game, { onGameStart = online,
                    onGameEnd   = offline })

  spelllistWindow = g_ui.displayUI('spelllist', modules.game_interface.getRightPanel())
  spelllistWindow:hide()

  spelllistButton = modules.client_topmenu.addRightGameToggleButton('spelllistButton', tr('Spell List'), '/images/topbuttons/spelllist', toggle)
  spelllistButton:setOn(false)

  nameValueLabel        = spelllistWindow:getChildById('labelNameValue')
  formulaValueLabel     = spelllistWindow:getChildById('labelFormulaValue')
  groupValueLabel       = spelllistWindow:getChildById('labelGroupValue')
  typeValueLabel        = spelllistWindow:getChildById('labelTypeValue')
  cooldownValueLabel    = spelllistWindow:getChildById('labelCooldownValue')
  vitalityValueLabel    = spelllistWindow:getChildById('labelVitalityValue')
  strenghtValueLabel    = spelllistWindow:getChildById('labelStrenghtValue')
  defenceValueLabel     = spelllistWindow:getChildById('labelDefenceValue')
  dexterityValueLabel   = spelllistWindow:getChildById('labelDexterityValue')
  faithValueLabel       = spelllistWindow:getChildById('labelFaithValue')
  intelligenceValueLabel = spelllistWindow:getChildById('labelIntelligenceValue')
  manaValueLabel        = spelllistWindow:getChildById('labelManaValue')
  premiumValueLabel     = spelllistWindow:getChildById('labelPremiumValue')
  descriptionValueLabel = spelllistWindow:getChildById('labelDescriptionValue')

  groupBoxAny           = spelllistWindow:getChildById('groupBoxAny')
  groupBoxAttack        = spelllistWindow:getChildById('groupBoxAttack')
  groupBoxHealing       = spelllistWindow:getChildById('groupBoxHealing')
  groupBoxSupport       = spelllistWindow:getChildById('groupBoxSupport')

  groupRadioGroup = UIRadioGroup.create()
  groupRadioGroup:addWidget(groupBoxAny)
  groupRadioGroup:addWidget(groupBoxAttack)
  groupRadioGroup:addWidget(groupBoxHealing)
  groupRadioGroup:addWidget(groupBoxSupport)

  groupRadioGroup:selectWidget(groupBoxAny)

  groupRadioGroup.onSelectionChange     = toggleFilter

  spellList = spelllistWindow:getChildById('spellList')

  g_keyboard.bindKeyPress('Down', function() spellList:focusNextChild(KeyboardFocusReason) end, spelllistWindow)
  g_keyboard.bindKeyPress('Up', function() spellList:focusPreviousChild(KeyboardFocusReason) end, spelllistWindow)

  initializeSpelllist()
  resizeWindow()

  if g_game.isOnline() then
    online()
  end
end

function terminate()
  disconnect(g_game, { onGameStart = online,
                       onGameEnd   = offline })

  disconnect(spellList, { onChildFocusChange = function(self, focusedChild)
                          if focusedChild == nil then return end
                          updateSpellInformation(focusedChild)
                        end })

  spelllistWindow:destroy()
  spelllistButton:destroy()

  groupRadioGroup:destroy()
  --premiumRadioGroup:destroy()
end

function initializeSpelllist()
  for i = 1, #SpelllistSettings[SpelllistProfile].spellOrder do
    local spell = SpelllistSettings[SpelllistProfile].spellOrder[i]
    local info = SpellInfo[SpelllistProfile][spell]

    local tmpLabel = g_ui.createWidget('SpellListLabel', spellList)
    tmpLabel:setId(spell)
    tmpLabel:setText(spell .. '\n\'' .. info.words .. '\'')
    tmpLabel:setPhantom(false)

    local iconId = tonumber(info.icon)
    if not iconId and SpellIcons[info.icon] then
      iconId = SpellIcons[info.icon][1]
    end

    if not(iconId) then
      perror('Spell icon \'' .. info.icon .. '\' not found.')
    end

    tmpLabel:setHeight(SpelllistSettings[SpelllistProfile].iconSize.height + 4)
    tmpLabel:setTextOffset(topoint((SpelllistSettings[SpelllistProfile].iconSize.width + 10) .. ' ' .. (SpelllistSettings[SpelllistProfile].iconSize.height - 32)/2 + 3))
    tmpLabel:setImageSource(SpelllistSettings[SpelllistProfile].iconFile)
    tmpLabel:setImageClip(Spells.getImageClip(iconId, SpelllistProfile))
    tmpLabel:setImageSize(tosize(SpelllistSettings[SpelllistProfile].iconSize.width .. ' ' .. SpelllistSettings[SpelllistProfile].iconSize.height))
    tmpLabel.onClick = updateSpellInformation
  end

  connect(spellList, { onChildFocusChange = function(self, focusedChild)
                          if focusedChild == nil then return end
                          updateSpellInformation(focusedChild)
                        end })
end

function changeSpelllistProfile(oldProfile)
  -- Delete old labels
  for i = 1, #SpelllistSettings[oldProfile].spellOrder do
    local spell = SpelllistSettings[oldProfile].spellOrder[i]
    local tmpLabel = spellList:getChildById(spell)

    tmpLabel:destroy()
  end

  -- Create new spelllist and ajust window
  initializeSpelllist()
  resizeWindow()
  resetWindow()
end

function updateSpelllist()
  for i = 1, #SpelllistSettings[SpelllistProfile].spellOrder do
    local spell = SpelllistSettings[SpelllistProfile].spellOrder[i]
    local info = SpellInfo[SpelllistProfile][spell]
    local tmpLabel = spellList:getChildById(spell)

    local localPlayer = g_game.getLocalPlayer()
    if (not(filters.intelligence) or info.intelligence <= localPlayer:getSkillLevel(3)) and (not(filters.faith) or info.faith <= localPlayer:getSkillLevel(2)) and (filters.groupId == FILTER_GROUP_ANY or info.group[filters.groupId]) and (filters.premium == FILTER_PREMIUM_ANY or (info.premium and filters.premium == FILTER_PREMIUM_YES) or (not(info.premium) and filters.premium == FILTER_PREMIUM_NO)) then
      tmpLabel:setVisible(true)
    else
      tmpLabel:setVisible(false)
    end
  end
end

function updateSpellInformation(widget)
  local spell = widget:getId()

  local name        = ''
  local formula     = ''
  local group       = ''
  local type        = ''
  local cooldown    = ''
  local vitality    = ''
  local strenght    = ''
  local defence    = ''
  local dexterity    = ''
  local faith       = ''
  local intelligence = ''
  local mana        = ''
  local premium     = ''
  local description = ''

  if SpellInfo[SpelllistProfile][spell] then
    local info = SpellInfo[SpelllistProfile][spell]

    name    = spell
    formula = info.words

    cooldown = (info.exhaustion / 1000) .. 's'
    for groupId, groupName in ipairs(SpellGroups) do
      if info.group[groupId] then
        group    = group .. (group:len() == 0 and '' or ' / ') .. groupName
        cooldown = cooldown .. ' / ' .. (info.group[groupId] / 1000) .. 's'
      end
    end

    type    = info.type
    vitality = info.vitality or '-'
    strenght = info.strenght or '-'
    defence = info.defence or '-'
    dexterity = info.dexterity or '-'
    faith = info.faith or '-'
    intelligence = info.intelligence or '-'
    mana    = info.mana .. ' / ' .. info.soul
    premium = (info.premium and 'yes' or 'no')
    description = info.description or '-'
  end

  nameValueLabel:setText(name)
  formulaValueLabel:setText(formula)
  groupValueLabel:setText(group)
  typeValueLabel:setText(type)
  cooldownValueLabel:setText(cooldown)
  vitalityValueLabel:setText(vitality)
  strenghtValueLabel:setText(strenght)
  defenceValueLabel:setText(defence)
  dexterityValueLabel:setText(dexterity)
  faithValueLabel:setText(faith)
  intelligenceValueLabel:setText(intelligence)
  manaValueLabel:setText(mana)
  descriptionValueLabel:setText(description)
end

function toggle()
  if spelllistButton:isOn() then
    spelllistButton:setOn(false)
    spelllistWindow:hide()
    resetWindow()
  else
    spelllistButton:setOn(true)
    spelllistWindow:show()
    spelllistWindow:raise()
    spelllistWindow:focus()
  end
end

function toggleFilter(widget, selectedWidget)
  if widget == groupRadioGroup then
    local boxId = selectedWidget:getId()
    if boxId == 'groupBoxAny' then
      filters.groupId = FILTER_GROUP_ANY
    elseif boxId == 'groupBoxAttack' then
      filters.groupId = FILTER_GROUP_ATTACK
    elseif boxId == 'groupBoxHealing' then
      filters.groupId = FILTER_GROUP_HEALING
    elseif boxId == 'groupBoxSupport' then
      filters.groupId = FILTER_GROUP_SUPPORT
    end
  elseif widget == premiumRadioGroup then
    local boxId = selectedWidget:getId()
    if boxId == 'premiumBoxAny' then
      filters.premium = FILTER_PREMIUM_ANY
    elseif boxId == 'premiumBoxNo' then
      filters.premium = FILTER_PREMIUM_NO
    elseif boxId == 'premiumBoxYes' then
      filters.premium = FILTER_PREMIUM_YES
    end
  else
    local id = widget:getId()
    if id == 'buttonFilterIntelligence' then
      filters.intelligence = not(filters.intelligence)
      widget:setOn(filters.intelligence)
    end
    if id == 'buttonFilterFaith' then
      filters.faith = not(filters.faith)
      widget:setOn(filters.faith)
    end
  end

  updateSpelllist()
end

function resizeWindow()
  spelllistWindow:setWidth(SpelllistSettings['Default'].spellWindowWidth + SpelllistSettings[SpelllistProfile].iconSize.width - 32)
  spellList:setWidth(SpelllistSettings['Default'].spellListWidth + SpelllistSettings[SpelllistProfile].iconSize.width - 32)
end

function resetWindow()
  spelllistWindow:hide()
  spelllistButton:setOn(false)

  -- Resetting filters
  filters.intelligence = false
  filters.faith        = false

  local buttonFilterIntelligence = spelllistWindow:getChildById('buttonFilterIntelligence')
  buttonFilterIntelligence:setOn(filters.intelligence)

  local buttonFilterFaith = spelllistWindow:getChildById('buttonFilterFaith')
  buttonFilterFaith:setOn(filters.faith)

  groupRadioGroup:selectWidget(groupBoxAny)

  updateSpelllist()
end


this is the error that i get

id double check every single line i cant figure at where i mess it.
i dont know if there is someone here with the will of help me with this. TY
 
Last edited:
Status
Not open for further replies.
Back
Top