ID:165156
 
OK, well there's a part in my new project that needs a typesof proc. Yeah, thats alright, very easy to do. I need it to be a variable though. I had to look at something, but I knew what to do afterwards. But the problem begins when you define a new type in the code and you don't know how to call it properly.

Its for a card game I said I was making in a deleted "BYOND Central is not Accessible" turned discussion, and the type is /cards, and I have no clue how to do it myself.
I'm really very unsure of what you're asking there. Perhaps you could clarify?

I need it to be a variable though.

What is "it", and why does it need to be a variable?

I had to look at something, but I knew what to do afterwards.

Uh... what? I don't understand what you're even trying to say in this sentence, or why.

But the problem begins when you define a new type in the code and you don't know how to call it properly.

Again I have to ask, what is "it" here? A proc? A verb? If it's not a proc or a verb, did you perhaps mean something other than "call"? What are you trying to accomplish with the new type you've defined?

Its for a card game I said I was making in a deleted "BYOND Central is not Accessible" turned discussion...

Huh?

...and the type is /cards, and I have no clue how to do it myself.

The type of what? What are you trying to do with that type?

Defining the problem clearly is the first step of programming, but also the first step in asking for help. As it stands right now most of what you said came off as gibberish. I'm sure that happened mostly because you're confused, but any time you feel you're getting too vague, just step back and take a breath, and go through the problem in as much detail as you can muster. One thing that will help is a trick I learned from a former supervisor, who said in programming, never say "it"; always use the name of what you're actually working with. The reason is, programming is full of all kinds of things you can call "it", and once several its are interacting, it's impossible to tell which one you're referring to.

Lummox JR
In response to Lummox JR
... Fine. It was just a little background story until the last sentence in the paragraph.


I need to know how to do a typesof proc which uses a variable with a type defined in the code (/cards)
In response to RedlineM203
RedlineM203 wrote:
... Fine. It was just a little background story until the last sentence in the paragraph.

Background story is okay, as long as it's coherent, but here it really didn't make any sense; you only confused the issue.

I need to know how to do a typesof proc which uses a variable with a type defined in the code (/cards)

I'm not sure what you mean about using a variable here. The /cards type is not variable; it's a constant. What would you need a var for?

Lummox JR
In response to RedlineM203
var/sometype = text2path("/cards/[stuff]")

for(var/i in typesof(sometype))
DoSomethingWith(i)


I'm unsure if you can just put a variable in there, but it should probably work.
In response to Jon88
I'm unsure on that, I don't think it fits what I mean.
In response to Lummox JR
OK, I'll take it down another notch.

mob
New()//Because there is AI too
..()
var/list/dec
for(var/cards/D as obj in typesof(/cards)) //Here we go, problem time
if(D.name!="")/*Someone told me about a way to stop parts of the tree from being
in this sort of thing, but I forgot and now I'm taking the easy way out*/

world << "[D]" //Debug which don't pick up anything
dec+=D //So there are no possible cards to add to the deck
else
world << "null" //This don't pick up anything either
spawn(5) //Make sure the cards come through
if(dec) //So if something happens to the cards there will be no errors
for(var/i,i<5,i++) //5 for testing
var/cards/C = pick(dec)//Random card to deck time
C.owner = src//Make it their own
deck+=C//I wish


I want that to work.
In response to RedlineM203
typesof() returns types. ie:

/card/apple
/card/banana

They aren't actual objs you can do something with. You'd need to actually make new ones.

for(var/i in typesof(/card))
var/card/C = new i()
world << C.desc
In response to Jon88
With a little mess around as you proberly wanted, it works. Cheers.
In response to RedlineM203
You should take the "as obj" bit out of your for() loop. It has no business there.

Lummox JR
In response to RedlineM203
I found out later that the cards I get in the deck are just clones and do whatever the first one does, if I have them in my hand or not, and the AI's cards might even copy mine.

The solution to that is <s>ofcourse</s> most likely a new proc. The problem is, that the cards don't like to be created again...

                for(var/i,i<5,i++)
var/cards/D = pick(dec)
var/cards/C = new D //I would of thought that was enough
C.owner = src
deck+=C


<font color = red>runtime error: Cannot create objects of type /cards/monster/guy.
proc name: New (/mob/New)
source file: Main.dm,34
usr: RedlineM203 (/mob)
src: RedlineM203 (/mob)
call stack:
RedlineM203 (/mob): New()</font color>
In response to RedlineM203
RedlineM203 wrote:
>                   var/cards/D = pick(dec)
> var/cards/C = new D //I would of thought that was enough


Uhh.. So 'D' contains an object reference? If you go and look up 'new' before you use it, it accepts a type path there. You can't use an object. You could look up the 'type' var and use 'new D.type' to create a new object of the same type as D, or if you really want the card to be a duplicate, use a proc to Copy() it.
In response to Kaioken
Ah, cheers. Don't say I didn't look at New() though.
In response to RedlineM203
Perhaps you have, but you need to look up new(), which is what you're using there and is different (but related to) than New(), and it's entry specifies the first "argument" has to be a type path.