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!
You actually don't want to put nCard inside Card (by the way, self
inside your new
function is actually a reference to Card
)
When you call Card:new()
, you are given the playing card's table as a return value, which you can then put into a table for the Player's Hand. You don't want to mess with the Card table you've created.
Locked by Spongocardo, BlackJPI, and adark
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?