ID:273730
 
Card
parent_type = /obj
var
ATK
DEF
card_text
attribute
sub_type
level
set_name
rarity
code //<---Card Code
amount
quality
price
sell
st_icon
verb/AddCard()
var/list/cards = list()
for(var/C in typesof(/Card)-/Card)
var/Card/tmp_card = new C
cards += tmp_card
var/Card/X = type
X = new X
var/Card/Y=locate(X.type) in usr.deck.cards-X
if(Y)
if(Y.amount >= 3)
usr << "You cannot add any more copies of <i><b>[X.name]</b></i> to your deck (max is <font color=red>3</font>)."
return
else
amount -= X.amount
Y.amount+=X.amount
usr.deck.cards += X
usr.deck.code += X.code
else
amount -= X.amount
usr.deck.cards += X
usr.deck.code += X.code
.=1
usr << "[src.name] was added to your deck."

Card

machina_mayhem

effect_monsters

Machina_Fortress
layer = MOB_LAYER + 10
icon_state="Machina Fortress"
name = "Machina Fortress"
attribute = "EARTH"
sub_type = "Machine/Effect"
level = 7
ATK = 2500
DEF = 1600
code="05556499" //<----- Code
card_text = {"You can discard Machine-Type monster(s) whose total Levels equal 8 or more to Special Summon this card from your hand or Graveyard. When this card is destroyed by battle and sent to the Graveyard, select and destroy 1 card your opponent controls. When this face-up card you control is targeted by an opponent's Effect Monster's effect, look at your opponent's hand and discard 1 card from their hand."}
set_name = "SDMM-EN001"
rarity = "(UR)"
quality = "1st Edition"
amount=1


Alright so as you can see I have an obj (Card) that has a text stringed Card Code. When I add the card to a deck it also adds the card's code.

What I am asking here is, how would I create a deck using only the text strings? Is there a text2object or something? Please help x.x
Just for the sake of clarity, you're wanting to create a deck by just going through all of your /Cards and adding the text strings from them? Why not just create an instance of each /Card and add it to your deck with typesof() a la:


proc/compile_deck()
// Just an example
var/Deck/D = new
for(var/card_type in typesof(/Card) - /Card)
var/Card/C = new card_type
D.Add(C)


(P.S. I fixed your closing <dm> tag)
In response to Audeuro (#1)
No no what I mean is when I add a card to my deck, that card's code gets placed into the deck's code. The Deck has its own code which i can export fine.

I want to be able to create a deck by using only the text strings i added to it.
In response to Paul De La Torre (#2)
Ah, so ideally what you're looking for is a reverse lookup table so that you can serialize your Deck into strings and save yourself the overhead of saving entire datums? Here's a neat trick you could use, then. initial() takes a parameter, a var. The neat thing about this is you can pass it a var that doesn't actually have a valid instance attached to it, such as the following:

var/list/lookup_table = null
proc/build_reverse_table()
// Just an example
for(var/t in typesof(/Card))
var/Card/v = t
var/cardId = initial(v.code)
if(cardId)
if(!lookup_table) lookup_table = new
lookup_table[cardId] = t


The down-side is that your 'code' var is technically static const without actually BEING static const. You'll also want to go through and make sure that all /Card types (such as /Card itself or any categorization sub-types) that you do NOT want to be listed in the lookup table (potentially over-writing other, more valid cards?) have their code = null.