help to convert pawn enum to lua

hello everyone. i khow this is embarrassing but can you help me to convert this enum code to lua

enum playerInfo{
    logged,
    score,
    level
    

}
new sInfo[MAX_PLAYERS][playerInfo];

//exxample
public OnPlayerConnect(playerid)
{    //after someone logged in
    sInfo[playerid][logged]=1;

}

thank you

Hi @rh2d.

Lua doesn’t have enums. You can do something like:

local logged, score, level = 1, 2, 3

You can do something like this as well:

local PlayerInfo = {} PlayerInfo.Logged = "logged" PlayerInfo.Score = "score" PlayerInfo.Level = "level" local info = {} local OnPlayerConnect = function( playerID )     info[playerID] = info[playerID] or {}     info[playerID][PlayerInfo.Logged] = 1 end

You could also try something like this:

[lua]

– Player “class”
local Player = {
    new = function(id)
        print("Creating new player "…id)
        return { logged=false, score=0, level=1, id=id }
    end
}

local players = {} – this is your sInfo

– create a new player with ID ‘playerID’
local function newPlayer(playerID)
    players[playerID] = Player.new(playerID)
    return players[playerID]
end

local function onPlayerConnect(playerID)
    local player = players[playerID]
    --assert(player.id==playerID)
    player.logged = true
    print(“Player “…playerID…” connected. Score=”…player.score…", Level="…player.level)
end

– test player creation:
local p1 = newPlayer(#players+1)
local p2 = newPlayer(#players+1)

– change some player properties
p1.score = 100
p1.level = 42

– test player connection (every 2 secs):
local id = 0

timer.performWithDelay(2000, function()
        id = id + 1
        onPlayerConnect(id)
    end, 2)

[/lua]

HTH,

Dave