• 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 Lua scripting errors/tutorial

aalqaq2

Trying to help, but I'm not too good at it.
Joined
Apr 10, 2017
Messages
112
Solutions
3
Reaction score
8
I've got an error in CBRM's Casino script. I'm attempting to make it work on 1.3. I've edited a bit already but if anyone has a better way to make it work I'd appreciate it. Everything is working except I can't make the fruits appear on the tiles. I get the animations, item is removed, and loss/win message is posted and reward is given:

Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/actions/scripts/slot.lua:289: attempt to index local 'newfruit' (a nil value)
stack traceback:
[C]: in function '__index'
data/actions/scripts/slot.lua:289: in function <data/actions/scripts/slot.lua:251>



Lua:
--[[
.::1-Row Slot Machine::.
        For TFS 1.2
by Cybermaster (cbrm)
]]--
--local cost_item = 2157
--local cost_count = 1

--    1. FRUITS
--local FRUITS = {2674,2675,2676,2679,2680,2682,2683,5097,8841}
--, FRUITS
TEMP, FRUITS = {
    ['APPLE']=2674,-- APPLE
    ['BANANA']=2676,-- BANANA
    ['BERRY']=2680,-- BERRY
    ['CHERRY']=2679,-- CHERRY
    ['LEMON']=8841,-- LEMON
    ['MANGO']=5097,--MANGO
    ['MELON']=2682,--MELON
    ['ORANGE']=2675,--ORANGE
    ['PUMPKIN']=2683--PUMPKIN
}, {}
for name, id in pairs(TEMP) do
    _G[name] = id
    table.insert(FRUITS, id)
end
--    2. CONFIGURATION
SETUP = {
    --cost_item, cost_count = 2157, 1 -- MONEY = 1000  --REQUIRED VIP TOKENS TO PLAY SLOT MACHINES
    TIME = 200,--MILLISECONDS TO SWITCH FRUITS
    LIMIT = 20, --COUNTER TO STOP CHANGING FRUIT IF PLAYER DOESN'T (decreases each SETUP.TIME)
    LEVER = {1945,1946},
    WIN={
        [{PUMPKIN,PUMPKIN,PUMPKIN}]={2157,30},
        [{BERRY,BERRY,BERRY}]={2157,30},
        [{MANGO,MANGO,MANGO}]={2157,20},
        [{MELON,MELON,MELON}]={2157,15},
        [{BANANA,BANANA,BANANA}]={2157,10},
        [{LEMON,LEMON,LEMON}]={2157,5},
        [{CHERRY,CHERRY,CHERRY}]={2157,5},
        [{ORANGE,ORANGE,ORANGE}]={2157,5},
        [{APPLE,APPLE,APPLE}]={2157,4},

        [{PUMPKIN,PUMPKIN,ANY}]={2157,3},
        [{PUMPKIN,ANY,PUMPKIN}]={2157,3},
        [{ANY,PUMPKIN,PUMPKIN}]={2157,3},

        [{CHERRY,PUMPKIN,CHERRY}]={2157,2},
        [{CHERRY,CHERRY,PUMPKIN}]={2157,2},
        [{PUMPKIN,CHERRY,CHERRY}]={2157,2},

        [{LEMON,MELON,LEMON}]={2157,2},
        [{LEMON,LEMON,MELON}]={2157,2},
        [{MELON,LEMON,LEMON}]={2157,2},

        [{CHERRY,CHERRY,ANY}]={2157,2},
        [{CHERRY,ANY,CHERRY}]={2157,2},
        [{ANY,CHERRY,CHERRY}]={2157,2},

        [{ORANGE,ORANGE,ANY}]={2157,1},
        [{ORANGE,ANY,ORANGE}]={2157,1},
        [{ANY,ORANGE,ORANGE}]={2157,1},

        [{BANANA,BANANA,ANY}]={2157,1},
        [{BANANA,ANY,BANANA}]={2157,1},
        [{ANY,BANANA,BANANA}]={2157,1},

        [{MELON,MELON,ANY}]={2157,1},
        [{MELON,ANY,MELON}]={2157,1},
        [{ANY,MELON,MELON}]={2157,1},

        [{MANGO,MANGO,ANY}]={2157,1},
        [{MANGO,ANY,MANGO}]={2157,1},
        [{ANY,MANGO,MANGO}]={2157,1},

        [{BERRY,BERRY,ANY}]={2157,1},
        [{BERRY,ANY,BERRY}]={2157,1},
        [{ANY,BERRY,BERRY}]={2157,1},

        [{APPLE,APPLE,ANY}]={2157,1},
        [{APPLE,ANY,APPLE}]={2157,1},
        [{ANY,APPLE,APPLE}]={2157,1},

        [{APPLE,BANANA,ANY}]={2157,1},
        [{APPLE,ANY,BANANA}]={2157,1},
        [{ANY,APPLE,BANANA}]={2157,1},
        [{BANANA,APPLE,ANY}]={2157,1},
        [{BANANA,ANY,APPLE}]={2157,1},
        [{ANY,BANANA,APPLE}]={2157,1},
        [{PUMPKIN,MELON,ANY}]={2157,1},
        [{PUMPKIN,ANY,MELON}]={2157,1},
        [{ANY,PUMPKIN,MELON}]={2157,1},
        [{MELON,PUMPKIN,ANY}]={2157,1},
        [{MELON,ANY,PUMPKIN}]={2157,1},
        [{ANY,MELON,PUMPKIN}]={2157,1},
        [{LEMON,LEMON,ANY}]={2157,1},
        [{LEMON,ANY,LEMON}]={2157,1},
        [{ANY,LEMON,LEMON}]={2157,1},
    },
    MSG = {'Bingo!','Lucky!','Jackpot!','Win!'},
    POS = {
        [6297] = {direction = SOUTH, distance = 2, pos = Position(32251, 32191, 7)},
        [6298] = {direction = SOUTH, distance = 2, pos = Position(32255, 32191, 7)},
        [6299] = {direction = SOUTH, distance = 2, pos = Position(32259, 32191, 7)},
        [6300] = {direction = SOUTH, distance = 2, pos = Position(32263, 32191, 7)},
        [6301] = {direction = SOUTH, distance = 2, pos = Position(32251, 32199, 7)},
        [6302] = {direction = SOUTH, distance = 2, pos = Position(32255, 32199, 7)},
        [6303] = {direction = SOUTH, distance = 2, pos = Position(32259, 32199, 7)},
        [6304] = {direction = SOUTH, distance = 2, pos = Position(32263, 32199, 7)},
        [6305] = {direction = SOUTH, distance = 2, pos = Position(32251, 32207, 7)},
        [6306] = {direction = SOUTH, distance = 2, pos = Position(32255, 32207, 7)},
        [6307] = {direction = SOUTH, distance = 2, pos = Position(32259, 32207, 7)},
        [6308] = {direction = SOUTH, distance = 2, pos = Position(32263, 32207, 7)},
        [6309] = {direction = SOUTH, distance = 2, pos = Position(32247, 32215, 7)},
        [6310] = {direction = SOUTH, distance = 2, pos = Position(32251, 32215, 7)},
        [6311] = {direction = SOUTH, distance = 2, pos = Position(32255, 32215, 7)},
        [6312] = {direction = SOUTH, distance = 2, pos = Position(32259, 32215, 7)},
        [6313] = {direction = SOUTH, distance = 2, pos = Position(32263, 32215, 7)},
        [6314] = {direction = SOUTH, distance = 2, pos = Position(32267, 32215, 7)},
    },
}
for lever, row in pairs(SETUP.POS) do
    local position = row.pos:getNextPosition(row.direction, row.distance)
 
    for tile = 0, 2 do
        if row.direction % 2 == 0 then
            SETUP.POS[lever][tile+101] = Position(position.x+tile, position.y, position.z, 1)
        else
            SETUP.POS[lever][tile+101] = Position(position.x, position.y+tile, position.z, 1)
        end
    end
end

function choose(...)
    local arg, ret = {...}

    if type(arg[1]) == 'table' then
        ret = arg[1][math.random(#arg[1])]
    else
        ret = arg[math.random(#arg)]
    end

    return ret
end

local function switchLever(lev)
    return doTransformItem(lev.uid, lev.itemid == SETUP.LEVER[1] and SETUP.LEVER[2] or SETUP.LEVER[1])
end

local function verifyRow(cid, pos)
    local result = false

    for combo, profit in pairs(SETUP.WIN) do
        if (getTileItemById(pos[101], combo[1]).uid > 0) or (combo[1] == ANY) then
            if (getTileItemById(pos[102], combo[2]).uid > 0) or (combo[2] == ANY) then
                if (getTileItemById(pos[103], combo[3]).uid > 0) or (combo[3] == ANY) then
                    result = true
                    doPlayerAddItem(cid, profit[1], profit[2] or 1, true)
                    doCreatureSay(cid, choose(SETUP.MSG), TALKTYPE_ORANGE_1)
                    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Congratulations!! You won ' .. profit[2] .. ' ' .. getItemDescriptions(profit[1]).plural ..'!')
                    break
                end
            end
        end
    end

    for tile = 101, 103 do
        doRemoveItem(getTileThingByPos(pos[tile]).uid)
        doSendMagicEffect(pos[tile], result and CONST_ME_GIFT_WRAPS or CONST_ME_EXPLOSIONHIT)
    end

    return not result and doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'Aww, you lost. Better luck next time! :( Try again')
end

local function getDirectionTo(pos1, pos2)
    local dir = SOUTH

    if(pos1.x > pos2.x) then
        dir = WEST
        if(pos1.y > pos2.y) then
            dir = NORTHWEST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHWEST
        end

    elseif(pos1.x < pos2.x) then
        dir = EAST
        if(pos1.y > pos2.y) then
            dir = NORTHEAST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHEAST
        end

    elseif(pos1.y > pos2.y) then
        dir = NORTH
    elseif(pos1.y < pos2.y) then
        dir = SOUTH
    end
    return dir
end

--4.SCRIPT
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if getDirectionTo(player:getPosition(), fromPosition) > 3 then
        return true
    end

    local pid = player:getId()

    local function getLever()
        for _, id in ipairs(SETUP.LEVER) do
            local lever = getTileItemById(fromPosition, id)
            if lever.uid > 0 then
                return lever
            end
        end
    end -- getLever function

    if item.actionid == 0 then
        doSetItemActionId(item.uid, 100)
    end

    local function doFruit(pos, id, limit)

        if not player:isPlayer() then
            doSetItemActionId(item.uid, 100)
            for tile = 100, 103 do
                if getTileThingByPos(pos[tile]).uid > 0 then
                    doRemoveItem(getTileThingByPos(pos[tile]).uid)
                end
            end
            return true
        end

        if getTileThingByPos(pos[id]).itemid < 1 then
            doSendMagicEffect(pos[id], CONST_ME_SMALLCLOUDS)
            Game.createItem(choose(FRUITS),1,pos[id]):setActionId(100)
            --Tile(pos[id]):addItem(choose(FRUITS)):setActionId(100)
            local fruit = Game.createItem(choose(FRUITS))--HERE
            --local fruit = doCreateItemEx(choose(FRUITS))--HERE
            doSetItemActionId(fruit, 100)
            --Tile:addItem(pos[id], fruit)
            --doTileAddItemEx(pos[id], fruit)
        else
            doTransformItem(getTileThingByPos(pos[id]).uid, choose(FRUITS))
            local newfruit = Tile(pos[id]):getItems()[0]
            newfruit:transform(choose(FRUITS))
        end

        if limit < 1 then
            doSendMagicEffect(pos[id], math.random(28, 30))
            doTransformItem(getTileThingByPos(pos[id]).uid, choose(FRUITS))
            local newfruit = Tile(pos[id]):getItems()[0]
            newfruit:transform(choose(FRUITS))
            switchLever(getLever())
            doSetItemActionId(getLever().uid, getLever().actionid+1)
        elseif getLever().actionid > id then
            doSendMagicEffect(pos[id], math.random(28, 30))
            doTransformItem(getTileThingByPos(pos[id]).uid, choose(FRUITS))
            local newfruit = Tile(pos[id]):getItems()[0]
            newfruit:transform(choose(FRUITS))
        else
            addEvent(doFruit, SETUP.TIME, pos, id, limit-1)
        end
    end -- doFruit function

    if item.actionid == 100 then

        if not player:removeItem(2157, 1) then --cid
            --if not player:removeMoney(SETUP.MONEY) then --CHANGE THIS TO ITEM
            return player:sendTextMessage(MESSAGE_EVENT_ORANGE, 'You need 1 VIP Token to play the Slot Machines.') --cid
        end

        doSetItemActionId(item.uid, 101)
        --mayNotMove(pid, true)
        switchLever(item)
        --player:say('- 1 VIP Token...', TALKTYPE_ORANGE_1) --MAYBE COMMENT OUT?

        for tile = 101, 103 do
            doFruit(SETUP.POS[item.uid], tile, (tile-100)*SETUP.LIMIT)-- HERE
        end
    
    elseif isInArray({101,102,103}, item.actionid) then
        switchLever(item)
        doSetItemActionId(item.uid, item.actionid+1)
    elseif item.actionid == 104 then
        switchLever(item)
        --mayNotMove(pid, false)
        verifyRow(pid, SETUP.POS[item.uid])
        doSetItemActionId(item.uid, 100)
    end

    return true
end
 
Last edited:
Try this:

Lua:
--[[
.::1-Row Slot Machine::.
        For TFS 1.2
by Cybermaster (cbrm)
]]--
--local cost_item = 2157
--local cost_count = 1

--    1. FRUITS
--local FRUITS = {2674,2675,2676,2679,2680,2682,2683,5097,8841}
--, FRUITS
TEMP, FRUITS = {
    ['APPLE']=2674,-- APPLE
    ['BANANA']=2676,-- BANANA
    ['BERRY']=2680,-- BERRY
    ['CHERRY']=2679,-- CHERRY
    ['LEMON']=8841,-- LEMON
    ['MANGO']=5097,--MANGO
    ['MELON']=2682,--MELON
    ['ORANGE']=2675,--ORANGE
    ['PUMPKIN']=2683--PUMPKIN
}, {}
for name, id in pairs(TEMP) do
    _G[name] = id
    table.insert(FRUITS, id)
end
--    2. CONFIGURATION
SETUP = {
    --cost_item, cost_count = 2157, 1 -- MONEY = 1000  --REQUIRED VIP TOKENS TO PLAY SLOT MACHINES
    TIME = 200,--MILLISECONDS TO SWITCH FRUITS
    LIMIT = 20, --COUNTER TO STOP CHANGING FRUIT IF PLAYER DOESN'T (decreases each SETUP.TIME)
    LEVER = {1945,1946},
    WIN={
        [{PUMPKIN,PUMPKIN,PUMPKIN}]={2157,30},
        [{BERRY,BERRY,BERRY}]={2157,30},
        [{MANGO,MANGO,MANGO}]={2157,20},
        [{MELON,MELON,MELON}]={2157,15},
        [{BANANA,BANANA,BANANA}]={2157,10},
        [{LEMON,LEMON,LEMON}]={2157,5},
        [{CHERRY,CHERRY,CHERRY}]={2157,5},
        [{ORANGE,ORANGE,ORANGE}]={2157,5},
        [{APPLE,APPLE,APPLE}]={2157,4},

        [{PUMPKIN,PUMPKIN,ANY}]={2157,3},
        [{PUMPKIN,ANY,PUMPKIN}]={2157,3},
        [{ANY,PUMPKIN,PUMPKIN}]={2157,3},

        [{CHERRY,PUMPKIN,CHERRY}]={2157,2},
        [{CHERRY,CHERRY,PUMPKIN}]={2157,2},
        [{PUMPKIN,CHERRY,CHERRY}]={2157,2},

        [{LEMON,MELON,LEMON}]={2157,2},
        [{LEMON,LEMON,MELON}]={2157,2},
        [{MELON,LEMON,LEMON}]={2157,2},

        [{CHERRY,CHERRY,ANY}]={2157,2},
        [{CHERRY,ANY,CHERRY}]={2157,2},
        [{ANY,CHERRY,CHERRY}]={2157,2},

        [{ORANGE,ORANGE,ANY}]={2157,1},
        [{ORANGE,ANY,ORANGE}]={2157,1},
        [{ANY,ORANGE,ORANGE}]={2157,1},

        [{BANANA,BANANA,ANY}]={2157,1},
        [{BANANA,ANY,BANANA}]={2157,1},
        [{ANY,BANANA,BANANA}]={2157,1},

        [{MELON,MELON,ANY}]={2157,1},
        [{MELON,ANY,MELON}]={2157,1},
        [{ANY,MELON,MELON}]={2157,1},

        [{MANGO,MANGO,ANY}]={2157,1},
        [{MANGO,ANY,MANGO}]={2157,1},
        [{ANY,MANGO,MANGO}]={2157,1},

        [{BERRY,BERRY,ANY}]={2157,1},
        [{BERRY,ANY,BERRY}]={2157,1},
        [{ANY,BERRY,BERRY}]={2157,1},

        [{APPLE,APPLE,ANY}]={2157,1},
        [{APPLE,ANY,APPLE}]={2157,1},
        [{ANY,APPLE,APPLE}]={2157,1},

        [{APPLE,BANANA,ANY}]={2157,1},
        [{APPLE,ANY,BANANA}]={2157,1},
        [{ANY,APPLE,BANANA}]={2157,1},
        [{BANANA,APPLE,ANY}]={2157,1},
        [{BANANA,ANY,APPLE}]={2157,1},
        [{ANY,BANANA,APPLE}]={2157,1},
        [{PUMPKIN,MELON,ANY}]={2157,1},
        [{PUMPKIN,ANY,MELON}]={2157,1},
        [{ANY,PUMPKIN,MELON}]={2157,1},
        [{MELON,PUMPKIN,ANY}]={2157,1},
        [{MELON,ANY,PUMPKIN}]={2157,1},
        [{ANY,MELON,PUMPKIN}]={2157,1},
        [{LEMON,LEMON,ANY}]={2157,1},
        [{LEMON,ANY,LEMON}]={2157,1},
        [{ANY,LEMON,LEMON}]={2157,1},
    },
    MSG = {'Bingo!','Lucky!','Jackpot!','Win!'},
    POS = {
        [6297] = {direction = SOUTH, distance = 2, pos = Position(32251, 32191, 7)},
        [6298] = {direction = SOUTH, distance = 2, pos = Position(32255, 32191, 7)},
        [6299] = {direction = SOUTH, distance = 2, pos = Position(32259, 32191, 7)},
        [6300] = {direction = SOUTH, distance = 2, pos = Position(32263, 32191, 7)},
        [6301] = {direction = SOUTH, distance = 2, pos = Position(32251, 32199, 7)},
        [6302] = {direction = SOUTH, distance = 2, pos = Position(32255, 32199, 7)},
        [6303] = {direction = SOUTH, distance = 2, pos = Position(32259, 32199, 7)},
        [6304] = {direction = SOUTH, distance = 2, pos = Position(32263, 32199, 7)},
        [6305] = {direction = SOUTH, distance = 2, pos = Position(32251, 32207, 7)},
        [6306] = {direction = SOUTH, distance = 2, pos = Position(32255, 32207, 7)},
        [6307] = {direction = SOUTH, distance = 2, pos = Position(32259, 32207, 7)},
        [6308] = {direction = SOUTH, distance = 2, pos = Position(32263, 32207, 7)},
        [6309] = {direction = SOUTH, distance = 2, pos = Position(32247, 32215, 7)},
        [6310] = {direction = SOUTH, distance = 2, pos = Position(32251, 32215, 7)},
        [6311] = {direction = SOUTH, distance = 2, pos = Position(32255, 32215, 7)},
        [6312] = {direction = SOUTH, distance = 2, pos = Position(32259, 32215, 7)},
        [6313] = {direction = SOUTH, distance = 2, pos = Position(32263, 32215, 7)},
        [6314] = {direction = SOUTH, distance = 2, pos = Position(32267, 32215, 7)},
    },
}
for lever, row in pairs(SETUP.POS) do
    local position = row.pos:getNextPosition(row.direction, row.distance)

    for tile = 0, 2 do
        if row.direction % 2 == 0 then
            SETUP.POS[lever][tile+101] = Position(position.x+tile, position.y, position.z, 1)
        else
            SETUP.POS[lever][tile+101] = Position(position.x, position.y+tile, position.z, 1)
        end
    end
end

function choose(...)
    local arg, ret = {...}

    if type(arg[1]) == 'table' then
        ret = arg[1][math.random(#arg[1])]
    else
        ret = arg[math.random(#arg)]
    end

    return ret
end

local function switchLever(lev)
    return doTransformItem(lev.uid, lev.itemid == SETUP.LEVER[1] and SETUP.LEVER[2] or SETUP.LEVER[1])
end

local function verifyRow(cid, pos)
    local result = false

    for combo, profit in pairs(SETUP.WIN) do
        if (getTileItemById(pos[101], combo[1]).uid > 0) or (combo[1] == ANY) then
            if (getTileItemById(pos[102], combo[2]).uid > 0) or (combo[2] == ANY) then
                if (getTileItemById(pos[103], combo[3]).uid > 0) or (combo[3] == ANY) then
                    result = true
                    doPlayerAddItem(cid, profit[1], profit[2] or 1, true)
                    doCreatureSay(cid, choose(SETUP.MSG), TALKTYPE_ORANGE_1)
                    doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, 'Congratulations!! You won ' .. profit[2] .. ' ' .. getItemDescriptions(profit[1]).plural ..'!')
                    break
                end
            end
        end
    end

    for tile = 101, 103 do
        doRemoveItem(getTileThingByPos(pos[tile]).uid)
        doSendMagicEffect(pos[tile], result and CONST_ME_GIFT_WRAPS or CONST_ME_EXPLOSIONHIT)
    end

    return not result and doPlayerSendTextMessage(cid, MESSAGE_EVENT_ORANGE, 'Aww, you lost. Better luck next time! :( Try again')
end

local function getDirectionTo(pos1, pos2)
    local dir = SOUTH

    if(pos1.x > pos2.x) then
        dir = WEST
        if(pos1.y > pos2.y) then
            dir = NORTHWEST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHWEST
        end

    elseif(pos1.x < pos2.x) then
        dir = EAST
        if(pos1.y > pos2.y) then
            dir = NORTHEAST
        elseif(pos1.y < pos2.y) then
            dir = SOUTHEAST
        end

    elseif(pos1.y > pos2.y) then
        dir = NORTH
    elseif(pos1.y < pos2.y) then
        dir = SOUTH
    end
    return dir
end

--4.SCRIPT
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if getDirectionTo(player:getPosition(), fromPosition) > 3 then
        return true
    end

    local pid = player:getId()

    local function getLever()
        for _, id in ipairs(SETUP.LEVER) do
            local lever = getTileItemById(fromPosition, id)
            if lever.uid > 0 then
                return lever
            end
        end
    end -- getLever function

    if item.actionid == 0 then
        doSetItemActionId(item.uid, 100)
    end

    local function doFruit(pos, id, limit)

        if not player:isPlayer() then
            doSetItemActionId(item.uid, 100)
            for tile = 100, 103 do
                if getTileThingByPos(pos[tile]).uid > 0 then
                    doRemoveItem(getTileThingByPos(pos[tile]).uid)
                end
            end
            return true
        end

        if getTileThingByPos(pos[id]).itemid < 1 then
            doSendMagicEffect(pos[id], CONST_ME_SMALLCLOUDS)
            Game.createItem(choose(FRUITS),1,pos[id]):setActionId(100)
            --Tile(pos[id]):addItem(choose(FRUITS)):setActionId(100)
            local fruit = Game.createItem(choose(FRUITS))--HERE
            --local fruit = doCreateItemEx(choose(FRUITS))--HERE
            doSetItemActionId(fruit, 100)
            --Tile:addItem(pos[id], fruit)
            --doTileAddItemEx(pos[id], fruit)
        else
            doTransformItem(getTileThingByPos(pos[id]).uid, choose(FRUITS))
            print ("STEP: newfruit 1")
            local newfruit = Tile(pos[id]):getItems()[0]
            newfruit:transform(choose(FRUITS))
        end

        if limit < 1 then
            doSendMagicEffect(pos[id], math.random(28, 30))
            doTransformItem(getTileThingByPos(pos[id]).uid, choose(FRUITS))
            print ("STEP: newfruit 2")
            local newfruit = Tile(pos[id]):getItems()[0]
            newfruit:transform(choose(FRUITS))
            switchLever(getLever())
            doSetItemActionId(getLever().uid, getLever().actionid+1)
        elseif getLever().actionid > id then
            doSendMagicEffect(pos[id], math.random(28, 30))
            doTransformItem(getTileThingByPos(pos[id]).uid, choose(FRUITS))
            print ("STEP: newfruit 3")
            local newfruit = Tile(pos[id]):getItems()[0]
            newfruit:transform(choose(FRUITS))
        else
            addEvent(doFruit, SETUP.TIME, pos, id, limit-1)
        end
    end -- doFruit function

    if item.actionid == 100 then

        if not player:removeItem(2157, 1) then --cid
            --if not player:removeMoney(SETUP.MONEY) then --CHANGE THIS TO ITEM
            return player:sendTextMessage(MESSAGE_EVENT_ORANGE, 'You need 1 VIP Token to play the Slot Machines.') --cid
        end

        doSetItemActionId(item.uid, 101)
        --mayNotMove(pid, true)
        switchLever(item)
        --player:say('- 1 VIP Token...', TALKTYPE_ORANGE_1) --MAYBE COMMENT OUT?

        for tile = 101, 103 do
            doFruit(SETUP.POS[item.uid], tile, (tile-100)*SETUP.LIMIT)-- HERE
        end
     
    elseif isInArray({101,102,103}, item.actionid) then
        switchLever(item)
        doSetItemActionId(item.uid, item.actionid+1)
    elseif item.actionid == 104 then
        switchLever(item)
        --mayNotMove(pid, false)
        verifyRow(pid, SETUP.POS[item.uid])
        doSetItemActionId(item.uid, 100)
    end

    return true
end
 
STEP: newfruit 3
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/actions/scripts/slot.lua:255: attempt to index local 'newfruit' (a nil value)
stack traceback:
[C]: in function '__index'
data/actions/scripts/slot.lua:255: in function <data/actions/scripts/slot.lua:218>
 
It fails to initialize newfruit here:
Lua:
            print ("STEP: newfruit 3")
            local newfruit = Tile(pos[id]):getItems()[0]
so it cannot transform it into another fruit.

Could it be you need to use an Item object instead of Tile?
 
Turns out I had to use a SPECIFIC tile, not just any tile. Thanks!
 
Solution
Back
Top