Quick (i hope) problem, I want to make a copy of a set of 'Cards' into a global list called 'Deck' and i thought this may work:
world
New()
..()
for (var/Atype in typesof(/obj/Cards))
var/TIMES = Atype:times
while(TIMES != 0)
Deck.Add(Atype)
TIMES -= 1
Atype:times is the number of that kind of card in the deck, when i compile and run i get the following runtime error:
runtime error: Cannot read /obj/Cards/Machine_Gun/Front (/obj/Cards/Machine_Gun/Front).times
proc name: New (/world/New)
usr: null
src:
call stack:
: New()
Now I understand how it means it cant read the obj's times var but how should I go about making it work?, Any pointers would be great..
Thanks in advance..
-Thorg
ID:173338
Jan 16 2004, 6:44 am
|
|
Hehe, pointers is your problem exactly! I had typed out a huge description, but this will be easier:
world If you're just wanting to add the type to the list, that will work, otherwise, relplace "Deck.Add(Atype)" with "Deck.Add(new Atype())". Hopefully that does it for you! |
Thorg wrote:
Quick (i hope) problem, I want to make a copy of a set of 'Cards' into a global list called 'Deck' and i thought this may work: Since Atype is a type path (since you're looping through typesof()), not an actual object, this will fail spectacularly in exactly the way you've seen. Type paths don't have variables; the objects they instantiate do. Hence, you can't use path.var or (much worse) path:var. while(TIMES != 0) Addendum: This time of loop is a lot safer with > instead of != just in case (for any weird reason) the number ends up with a small fractional component and thus skips over 0 entirely. Atype:times is the number of that kind of card in the deck, when i compile and run i get the following runtime error: See? You can't access a var belonging to a type path because a type path is not an object. This makes about as much sense as trying to access "Hi".len or 3.is_odd. Now I understand how it means it cant read the obj's times var but how should I go about making it work? It can't read the var because there's no object to read from. A type path is not an object. Now the way to deal with this properly is one of the following:
var/list/defaultdeck = list(\
for(var/Atype in typesof(/obj/Cards)-/obj/Cards) // I doubt you want /obj/Cards included Now in Incursion, I use a method similar to the first because my deck is full of type paths that don't get instantiated until the card is drawn. And for reference, here's a little of the code I use for cards. var/list/deck Lummox JR |
In response to Lummox JR
|
|
Thanks, that fixed the problem.
-Thorg |
var/decklist = list()
world/new
tab>for(var/obj/cards/C in world)
tab>tab>if(C.ATYPE == whateva)
tab>tab>tab>decklist += list("[C.name]")
now I have know idea what the big pivture is so who knows if tyhats what you ment but that will check the world for cards and make a list of them and add em' to decklist..
But if you want a list of cards why not just make the list manually?