• 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+ Tfs 1.3 attempt to index local 'spell' (a boolean value)

roriscrave

Advanced OT User
Joined
Dec 7, 2011
Messages
1,188
Solutions
34
Reaction score
200
Hi, i made this script to get spell info in tfs 1.3. To check a name of spells.
Whats the problem with the script?


Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)

    for index = 0, getPlayerInstantSpellCount(player) do
        local spell = getPlayerInstantSpellInfo(player, index)
        print(spell.name)
    end
    
    return true
end

error:

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/test.lua:onUse
data/actions/scripts/test.lua:5: attempt to index local 'spell' (a boolean value)
stack traceback:
        [C]: in function '__index'
        data/actions/scripts/test.lua:5: in function <data/actions/scripts/test.lua:1>
 
You're not handling the case where it returns false due to the player being unable to cast the spell it's referring to, you must use if spell then before doing anything with it.
 
this is how it works in spellbooks:
Code:
local count = getPlayerInstantSpellCount(player)
    for i = 0, count - 1 do
        local spell = getPlayerInstantSpellInfo(player, i)
        print(spell.name)
    end
 
You're not handling the case where it returns false due to the player being unable to cast the spell it's referring to, you must use if spell then before doing anything with it.
this is how it works in spellbooks:
Code:
local count = getPlayerInstantSpellCount(player)
    for i = 0, count - 1 do
        local spell = getPlayerInstantSpellInfo(player, i)
        print(spell.name)
    end
@Sarah Wesker , the same error in console
@Stigma tested with GM and with a normal Player too. (dont print anything in any case)
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local count = getPlayerInstantSpellCount(player)
    for i = 0, count - 1 do
        local spell = getPlayerInstantSpellInfo(player, i)
        if spell then
            print(spell.name)
        end
    end
    return true
end
 
this might be useful:

Lua:
function getPlayerInstantSpellInfo(cid, spellId)
    local player = Player(cid)
    if not player then
        return false
    end

    local spell = Spell(spellId)
    if not spell or not player:canCast(spell) then
        return false
    end

    return spell
end
 
Back
Top