TFS 1.X+ Tfs 1.3 attempt to index local 'spell' (a boolean value)

roriscrave

Well-Known Member
Joined
Dec 7, 2011
Messages
742
Best answers
19
Reaction score
89
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>
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,235
Best answers
511
Reaction score
2,861
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.
 

Sarah Wesker

ค∂vαηcε รүηтαx ❤
Joined
Mar 16, 2017
Messages
457
Best answers
41
Reaction score
273
Location
London
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
 
OP
R

roriscrave

Well-Known Member
Joined
Dec 7, 2011
Messages
742
Best answers
19
Reaction score
89
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
 

Evil Puncker

I'd rather kiss a rattlesnake
Joined
May 30, 2009
Messages
5,799
Best answers
26
Reaction score
1,788
Location
160,54,7
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
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,235
Best answers
511
Reaction score
2,861
Lua:
for _, spell in ipairs(player:getInstantSpells()) do
    print(spell.name)
end
 
OP
R

roriscrave

Well-Known Member
Joined
Dec 7, 2011
Messages
742
Best answers
19
Reaction score
89
@Stigma do u have time to do a job?
I cant send u a private message, dont know why.
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,235
Best answers
511
Reaction score
2,861
If you pay by bitcoin, sure.
 
Top