Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Card creation and preventing card duplicates?

Asked by 9 years ago

Hi everyone, this is a follow up from my last question about fitting cards into a Frame.

I am using the global table (_G) to keep a record of all the player's cards. I have set up my player's card table like so:

_G.PlayerCards = {
    ["Wild"] = {};
    ["Red"] = {};
    ["Blue"] = {};
    ["Green"] = {};
    ["Yellow"] = {};
}

I have another table in another script that contains information on all the cards in the game:

_G.Cards = {
    ["Wild"] = {
        ["Normal"] = {"",0,0,"Normal","Wild"};
        ["Draw Four"] = {"",0,0,"Draw Four","Wild"};
    };
    ["Red"] = {
        ["0"] = {};
        ["1"] = {};
        ["2"] = {};
        ["3"] = {};
        ["4"] = {};
        ["5"] = {};
        ["6"] = {};
        ["7"] = {};
        ["8"] = {};
        ["9"] = {};
        ["Skip"] = {};
        ["Reverse"] = {};
        ["Draw Two"] = {};
    };
    ["Blue"] = {
        ["0"] = {};
        ["1"] = {};
        ["2"] = {};
        ["3"] = {};
        ["4"] = {};
        ["5"] = {};
        ["6"] = {};
        ["7"] = {};
        ["8"] = {};
        ["9"] = {};
        ["Skip"] = {};
        ["Reverse"] = {};
        ["Draw Two"] = {};
    };
    ["Green"] = {
        ["0"] = {};
        ["1"] = {};
        ["2"] = {};
        ["3"] = {};
        ["4"] = {};
        ["5"] = {};
        ["6"] = {};
        ["7"] = {};
        ["8"] = {};
        ["9"] = {};
        ["Skip"] = {};
        ["Reverse"] = {};
        ["Draw Two"] = {};
    };
    ["Yellow"] = {
        ["0"] = {};
        ["1"] = {};
        ["2"] = {};
        ["3"] = {};
        ["4"] = {};
        ["5"] = {};
        ["6"] = {};
        ["7"] = {};
        ["8"] = {};
        ["9"] = {};
        ["Skip"] = {};
        ["Reverse"] = {};
        ["Draw Two"] = {};
    };
}

Now, I want to be able to use these tables together and use the player's cards table to copy a base ImageLabel (card) from inside the script and set it's values accordingly using the values in the table.

Firstly, I would like to ask if the way I'm going about this is efficient. Is there any easier way of doing this, and if so, how would I go about incorporating it?

Secondly, how could I avoid the script making duplicate cards? I was looking to put in a unique identifier for each card and compare it to the cards already in the players but I don't know where I'd put the unique identifier.

Any help is appreciated, thanks.

0
Second question: I don't know what you have set up but couldn't you simply do something like 'repeat [get new card] until [ not deck:FindFirstChild(card)]' (with everything inside the brackets signifying what to do)? Perci1 4988 — 9y
0
I want to have more of the same cards, but I don't want the whole hand to be created twice. I was using a for loop to get the items in my multidimensional array and clone a base ImageLabel and set values in it using the data in the array. I feel like I'm over-complicating it, though. Spongocardo 1991 — 9y

Answer this question