• 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 Math.max number requiered

Hokku

Member
Joined
Jul 25, 2013
Messages
95
Reaction score
18
Location
Extremadura, Spain
Hello!
Im getting in troubles with this:
Code:
math.max(0, Game.getStorageValue(bossStorage)) + 1

It's say in console that math.max requiere a number, then i though +1 was not interacting with this and tried to edited to (based on line of another working script):
Code:
math.max(0,Game.getStorageValue(bossStorage)+1))
And it crashed my server. (lua thug life)

Out of ideas, someone? TFS 1.1 using, its creaturescript

Related script, it working all fine except the error mentioned:

Code:
local bosses = {

    ['ushuriel'] = 200,

    ['zugurosh'] = 201,

    ['madareth'] = 202,

    ['latrivan'] = 203,

    ['annihilon'] = 204,

    ['hellgorak'] = 205
}


function onKill(player, target)

    local targetMonster = target:getMonster()

    if not targetMonster then

        return true

    end


    local targetName = targetMonster:getName():lower()

    local bossStorage = bosses[targetName]

    if not bossStorage then

        return true

    end


    local newValue = 2

    if targetName == 'latrivan' or targetName == 'golgordan' then

        newValue = math.max(0,Game.getStorageValue(bossStorage)+1))
    end

    Game.setStorageValue(bossStorage, newValue)

    if newValue == 2 then

        player:say('You now have 3 minutes to exit this room through the teleporter. It will bring you to the next room.', TALKTYPE_MONSTER_SAY)
        addEvent(Game.setStorageValue, 3 * 60 * 1000, bossStorage, 0)

    end

    return
true

end
 
Game.getStorageValue(bossStorage) is probably a nil value (script is unable to receive it at the moment)
you can do this to see that value in the console:
Code:
print(Game.getStorageValue(bossStorage))
 
Game.getStorageValue(bossStorage) is probably a nil value (script is unable to receive it at the moment)
you can do this to see that value in the console:
Code:
print(Game.getStorageValue(bossStorage))
To see which number cannot be set? I think its the +1 on the storage, because when u kill one of them it dont display nothing, then when kill the second, it tries to set the storage to+1 but it cant, then the error appear, so if it was the boss storagon the fist kill it should display an error, i think, really dont know because im learning about lua/xml atm, so newbie. I'm pretty sure it can be fixed just rewriting,
Code:
math.max(0, Game.getStorageValue(bossStorage)) + 1

Can someone tell me what math.max excatly do? 2 storages need to set value?

Offtopic: zbizu ur item stat system is so awesome, it made me started to learn scripting. ;)
 
Last edited:
@Hokku
math.max returns the maximum of all parameters that it was given.
As you already mentioned
Code:
math.max(0, Game.getStorageValue(bossStorage)) + 1
fixes the problem.

@samco Not if the other value is negative.
 
tried in another ways and nothing, console error with default function:

Code:
  local newValue = 2
    if targetName == 'latrivan' or targetName == 'golgordan' then
        newValue = math.max(0, Game.getStorageValue(bossStorage)) + 1
    end

error.png


default script:

Code:
local bosses = {
    ['ushuriel'] = 200,
    ['zugurosh'] = 201,
    ['madareth'] = 202,
    ['latrivan'] = 203,
    ['golgordan'] = 203,
    ['annihilon'] = 204,
    ['hellgorak'] = 205
}

function onKill(player, target)
    local targetMonster = target:getMonster()
    if not targetMonster then
        return true
    end

    local targetName = targetMonster:getName():lower()
    local bossStorage = bosses[targetName]
    if not bossStorage then
        return true
    end

    local newValue = 2
    if targetName == 'latrivan' or targetName == 'golgordan' then
        newValue = math.max(0, Game.getStorageValue(bossStorage)) + 1
    end
    Game.setStorageValue(bossStorage, newValue)

    if newValue == 2 then
        player:say('You now have 3 minutes to exit this room through the teleporter. It will bring you to the next room.', TALKTYPE_MONSTER_SAY)
        addEvent(Game.setStorageValue, 3 * 60 * 1000, bossStorage, 0)
    end
    return true
end
[/SPOILER
 
Weird, normally math.max(0) should return 0.

Try
Code:
newValue = math.max(0, Game.getStorageValue(bossStorage) or 0) + 1
 
Back
Top