Hey there,
I'm trying to set up a table in a way that i can pass it as an object. Essentially i want to be able to use obj:function() features.
I'm currently trying to create a room that hold tiles (table serverside) and players steamids for checks. However when i try to create a room upon GM:PlayerInitialSpawn() I get a nil value. And i dont know why.
include( 'sRoom.lua' )
concommand.Add("create_room", function(ply, cmd, args )
local room = Room(ply:SteamID()) -- this is where i get the error
room:setName("Hello world")
print( room:getOwner() .." has joined " .. room:getName() )
end)
This is my room metatable
local Room = {}
Room.__index = Room
function Room:new(owner, name, public, players, tiles, items, banned)
local EmptyRoom = {
owner = owner or "",
name = name or "",
public = public or false,
players = players or {},
tiles = tiles or {},
items = items or {},
banned = banned or {}
}
return setmetatable(EmptyRoom, Room)
end
Ive just been going off of this: Object Oriented Lua
So if anyone has any idea what im doing wrong, I would love to hear from ya.
Thanks again
You're calling the function like
Room()
when you have defined it to be
Room:new()
Sorry, you need to Log In to post a reply to this thread.