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