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

Lua How to combine this array with a function?

waqmaz

Member
Joined
Jun 17, 2015
Messages
203
Reaction score
11
File1.lua:
Code:
sorcerer_spells = {
    [1] = {spell = 'Death Strike'},
    [2] = {spell = 'Flame Strike'},
    [3] = {spell = 'Energy Strike'},
    [4] = {spell = 'Fire Wave'},
    [5] = {spell = 'Energy Beam'},
    [6] = {spell = 'Great Energy Beam'},
    [7] = {spell = 'Energy Wave'},
    [8] = {spell = 'Rage of the Skies'},
    [9] = {spell = 'Hells Core'}
}
File2.lua:
Code:
require "data.config.player_spells_config.playerSpellsConfig"
local function unlearnSpells(vocation_unlearn, cid)
        for i=1, #vocation_unlearn do
            doPlayerUnlearnInstantSpell(cid, vocation_unlearn[i].spell)
        end
        return true
    end

I do it like this:
Code:
unlearnSpells(sorcerer_spells, cid)
An error in console:
data/npc/scripts/file2.lua:85: attempt to get length of local 'vocation_unlearn' (a nil value)
stack traceback:
data/npc/scripts/file2.lua:85: in function 'unlearnSpells'
 
Code:
require "data.config.player_spells_config.playerSpellsConfig"
Are you sure this line is working as intended?
 
The table (associative array) you are passing to the unlearnSpells() function is nil. Add the script with the spell data to the script with this function:
Code:
dofile('e.g.,data/script/lua1.lua')
 
Back
Top