Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

help to convert pawn enum to lua
Started by rh2d Nov 26 2019 07:51 AM

- - - - -
3 replies to this topic
enum convert
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

rh2d

[GLOBAL: userInfoPane.html]
rh2d
  • Observer

  • 1 posts
  • Corona SDK

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

 



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,393 posts
  • Enterprise

Hi @rh2d.

 

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

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


[TOPIC: post.html]
#3

GrahamRanson

[GLOBAL: userInfoPane.html]
GrahamRanson
  • Contributor

  • 108 posts
  • Corona SDK

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


[TOPIC: post.html]
#4

Quantumwave

[GLOBAL: userInfoPane.html]
Quantumwave
  • Contributor

  • 113 posts
  • Corona SDK

You could also try something like this:

 

-- 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)

 

HTH,

Dave

 




[topic_controls]
[/topic_controls]