Hi everyone, someone on the Scripting Helpers sub-forum on ROBLOX helped me with a card class script for my card game and this is what I have from modifying it so far:
cardTypes = {
["0"] = {0,0},
["1"] = {1,0},
["2"] = {2,0},
["3"] = {3,0},
["4"] = {0,1},
["5"] = {1,1},
["6"] = {2,1},
["7"] = {3,1},
["8"] = {0,2},
["9"] = {1,2},
["DrawTwo"] = {2,2},
["Reverse"] = {3,2},
["Skip"] = {4,0},
["Wild"] = {0,0},
["DrawFourWild"] = {1,0}
}
cardColours = {
["Red"] = "rbxassetid://184598259",
["Blue"] = "rbxassetid://184598232",
["Green"] = "rbxassetid://184598240",
["Yellow"] = "rbxassetid://184598224",
["Wild"] = "rbxassetid://184598210"
}
Card = {};
function Card:new()
local nCard = {colour = "rbxassetid://184598259", offsetX = 0, offsetY = 0, player = nil}
self.__index = self
return setmetatable(nCard, self);
end;
function Card:SetColour(Colour)
Colour = Colour or "Red";
self.colour = cardColours[Colour]
end
function Card:SetType(Type)
Type = tostring(Type) or "1"
self.offsetX = (cardTypes[Type][1]*174)
self.offsetY = (cardTypes[Type][2]*236)
end
function Card:SetPlayer(Plr)
Plr = Plr or nil
self.player = Plr
end
I would like to know how I would insert the data from the Card:new() function into the Card table so I can use it for setting values when creating a hand for the player in a later part of the script. I was thinking of doing the following, but I'm not sure whether or not to put in self or nCard.
function Card:new()
local nCard = {colour = "rbxassetid://184598259", offsetX = 0, offsetY = 0, player = nil}
self.__index = self
table.insert(Card,self)
return setmetatable(nCard, self);
end;
Any help is appreciated, thanks!

3 comments
Oh right, thanks. Additional question: How would I go about making it so that when a new card is inserted into the player's hand table, an ImageButton is copied to the player's hand frame with data from that new card?
You could try using a proxy table with metamethod hackery. http://www.lua.org/pil/13.4.4.html Otherwise, try copying the image in in the code that inserts the PlayerCard table into the PlayerHand table. If you're got Filtering enabled, use a RemoteEvent.
Alright, I'm going to look into it myself again. Thank you.