• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Solved Script Error

Matt17

New Member
Joined
Apr 24, 2010
Messages
52
Reaction score
0
Error when i try to use it:
[05/04/2016 01:53:11] [Error - Action Interface]
[05/04/2016 01:53:11] data/actions/scripts/items/Slithery.lua:eek:nUse
[05/04/2016 01:53:11] Description:
[05/04/2016 01:53:11] data/actions/scripts/items/Slithery.lua:13: attempt to index field '?' (a nil value)
[05/04/2016 01:53:11] stack traceback:
[05/04/2016 01:53:11] data/actions/scripts/items/Slithery.lua:13: in function <data/actions/scripts/items/Slithery.lua:12>

Script is :
local coin = 2143
local lever = {
[1000] = {25,10137},
[1001] = {25,5468},
[1002] = {25,5956},
[1003] = {25,11115},
[1004] = {25,12610},
[1005] = {25,12609},
[1006] = {25,12607},
[1007] = {25,12607}
}
function onUse(cid,item,fromPosition,itemEx,toPosition)
if doPlayerRemoveItem(cid,coin,lever[item.actionid][1]) == FALSE then
return doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "you need "..lever[item.actionid][1].." " ..getItemNameById(coin))
end
doPlayerAddItem(cid,lever[item.actionid][2])
doPlayerSendTextMessage(cid,22,"you bought one " .. getItemNameById(lever[item.actionid][2]))
doSendMagicEffect(getCreaturePosition(cid), math.random(28,30))
return true
end
anyone know whats wrong ?
 
Code:
local coin = 2143
local lever = {
[1000] = {25,10137},
[1001] = {25,5468},
[1002] = {25,5956},
[1003] = {25,11115},
[1004] = {25,12610},
[1005] = {25,12609},
[1006] = {25,12607},
[1007] = {25,12607}
}
function onUse(cid,item,fromPosition,itemEx,toPosition)
if doPlayerRemoveItem(cid,coin,lever[item.actionid][1]) == FALSE then
return doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "you need "..lever[item.actionid][1].." " ..getItemNameById(coin))
end
doPlayerAddItem(cid,lever[item.actionid][2])
doPlayerSendTextMessage(cid,22,"you bought one " .. getItemNameById(lever[item.actionid][2]))
doSendMagicEffect(getCreaturePosition(cid), math.random(28,30))
return true
end

Yes, the issue is on the 13th line. Explain what you want the script to do and I'll fix it for you
 
Error when i try to use it:
[05/04/2016 01:53:11] [Error - Action Interface]
[05/04/2016 01:53:11] data/actions/scripts/items/Slithery.lua:eek:nUse
[05/04/2016 01:53:11] Description:
[05/04/2016 01:53:11] data/actions/scripts/items/Slithery.lua:13: attempt to index field '?' (a nil value)
[05/04/2016 01:53:11] stack traceback:
[05/04/2016 01:53:11] data/actions/scripts/items/Slithery.lua:13: in function <data/actions/scripts/items/Slithery.lua:12>

Script is :
local coin = 2143
local lever = {
[1000] = {25,10137},
[1001] = {25,5468},
[1002] = {25,5956},
[1003] = {25,11115},
[1004] = {25,12610},
[1005] = {25,12609},
[1006] = {25,12607},
[1007] = {25,12607}
}
function onUse(cid,item,fromPosition,itemEx,toPosition)
if doPlayerRemoveItem(cid,coin,lever[item.actionid][1]) == FALSE then
return doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "you need "..lever[item.actionid][1].." " ..getItemNameById(coin))
end
doPlayerAddItem(cid,lever[item.actionid][2])
doPlayerSendTextMessage(cid,22,"you bought one " .. getItemNameById(lever[item.actionid][2]))
doSendMagicEffect(getCreaturePosition(cid), math.random(28,30))
return true
end
anyone know whats wrong ?
Try using aid instead of actionid

change
Code:
if doPlayerRemoveItem(cid,coin,lever[item.actionid][1]) == FALSE then
to this
Code:
if doPlayerRemoveItem(cid,coin,lever[item.aid][1]) == FALSE then
 
Try using aid instead of actionid

change
Code:
if doPlayerRemoveItem(cid,coin,lever[item.actionid][1]) == FALSE then
to this
Code:
if doPlayerRemoveItem(cid,coin,lever[item.aid][1]) == FALSE then
nope still doesnt work

Code:
local coin = 2143
local lever = {
[1000] = {25,10137},
[1001] = {25,5468},
[1002] = {25,5956},
[1003] = {25,11115},
[1004] = {25,12610},
[1005] = {25,12609},
[1006] = {25,12607},
[1007] = {25,12607}
}
function onUse(cid,item,fromPosition,itemEx,toPosition)
if doPlayerRemoveItem(cid,coin,lever[item.actionid][1]) == FALSE then
return doPlayerSendTextMessage(cid,MESSAGE_INFO_DESCR, "you need "..lever[item.actionid][1].." " ..getItemNameById(coin))
end
doPlayerAddItem(cid,lever[item.actionid][2])
doPlayerSendTextMessage(cid,22,"you bought one " .. getItemNameById(lever[item.actionid][2]))
doSendMagicEffect(getCreaturePosition(cid), math.random(28,30))
return true
end

Yes, the issue is on the 13th line. Explain what you want the script to do and I'll fix it for you
well its a lever to buy items you need xxxx item to buy xxxx item so like for a god set you need god gems but you need 25 gems per item
 
Well the problem is obviously an issue with accessing the table values.
I'm not sure if you need to add a dot inbetween the items?
lever[item.actionid][1]
lever[item.actionid].[1] -- this seems wrong though.

I'm sorry, I'll just re-script it how I'd make it for myself.
Side note, you currently don't have the lever 'flopping'.
Also note, [item.actionid] for me is usually referenced using [item.aid], but whichever works.
Code:
local coin = 2143
local lever = {
    [1000] = {coin_count = 25, item_to_give = 10137},
    [1001] = {coin_count = 25, item_to_give = 5468},
    [1002] = {coin_count = 25, item_to_give = 5956},
    [1003] = {coin_count = 25, item_to_give = 11115},
    [1004] = {coin_count = 25, item_to_give = 12610},
    [1005] = {coin_count = 25, item_to_give = 12609},
    [1006] = {coin_count = 25, item_to_give = 12607},
    [1007] = {coin_count = 25, item_to_give = 12607}
}

function onUse(cid,item,fromPosition,itemEx,toPosition)
    if doPlayerRemoveItem(cid, coin, lever[item.actionid].coin_count) == TRUE then
        doPlayerAddItem(cid, lever[item.actionid].item_to_give)
        doPlayerSendTextMessage(cid, 22, "You bought one " .. getItemNameById(lever[item.actionid].item_to_give) .. ".")
        doSendMagicEffect(getCreaturePosition(cid), math.random(28,30))
    else
        return doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You require " .. lever[item.actionid].coin_count .. " " .. getItemNameById(coin) .. ".")
    end
    return true
end

Could also add this in to test functionality.
Code:
if lever.aid == 1111 then
    print(1111)
elseif lever.actionid == 2222 then
    print(2222)
else
    print("cannot find aid")
end
 
Well the problem is obviously an issue with accessing the table values.
You seem to be aware of the issue, but you're not addressing it in your own script. Why?

lever[item.actionid] is obviously returning a nil value in this case (undefined table key), and you cannot access table variables with nil (e.g, nil.coin_count or nil.item_to_give). That's why, it's important to verify whether the table is defined or not before trying to access any of its values.

Code:
local leverConfig = lever[item.actionid]
if not leverConfig then
    return false
end

print(leverConfig.coin_count, leverConfig.item_to_give)
 
You seem to be aware of the issue, but you're not addressing it in your own script. Why?

lever[item.actionid] is obviously returning a nil value in this case (undefined table key), and you cannot access table variables with nil (e.g, nil.coin_count or nil.item_to_give). That's why, it's important to verify whether the table is defined or not before trying to access any of its values.

Code:
local leverConfig = lever[item.actionid]
if not leverConfig then
    return false
end

print(leverConfig.coin_count, leverConfig.item_to_give)
Because I'm stupid okay? :(
 
Back
Top