Ok I coded a skill handling system and was wondering if there was an eaiser way to create new instances of typesof() procedure.
test = typesof(/skills/Air)
for(var/A in test)
test -= A
test += new A
ID:147366
Jun 20 2004, 5:54 pm
|
|
Jun 20 2004, 6:02 pm
|
|
I'm assuming you meant "Is there an easier way to use typesof to make instances." You could do this:
|
In response to Loduwijk
|
|
Loduwijk wrote:
I'm assuming you meant "Is there an easier way to use typesof to make instances." You could do this: for(var/type in typesof(/skills/Air))new type But this is an altogether rotten choice of var names, as type is a built-in var. Make it t instead. Lummox JR |
In response to Loduwijk
|
|
Thanks but I do believe my way is better for what I am doing right now. I was wondering if there was a way to make new instances from what the typesof returned directly into a list. Such as.
var/list/AirSkills = new typesof(/skills/Air)-/skills/Air Instead of using the for procedure to remove the old instance and add a new one. |
In response to Lummox JR
|
|
Lummox JR wrote:
But this is an altogether rotten choice of var names, as type is a built-in var. Make it t instead. I would have to disagree there. The type variable is never changed and not all that often accessed (The istype function is used more often) for one, so there shouldn't be much confusion. For another, type describes the variable in this for loop perfectly. Lastly, if the type of the src is needed then src.type can be used; so you still have access to it anyway. I would rather use type than t. Even if I didn't use type though, I would probably not use t; skill since that is the type of object. I suppose this is purely a matter of oppinion, whether you like having your implied src so much that you cannot type src.type. I have been trying to get in the habbit lately of not relying on anything implied. If you were in that habbit then there would be no reason whatsoever to avoid using variable names that are allready owned by the src. |
In response to DoOmBringer
|
|
DoOmBringer wrote:
Thanks but I do believe my way is better for what I am doing right now. Then why did you ask for a better way? Or do you just mean that yours is better than mine, but still could be improved upon and you would like to know how? I was wondering if there was a way to make new instances from what the typesof returned directly into a list. Such as. Yes, and I showed you that way. If mean something else entirely, please specify better. The line I showed would make a new skill of that base type and one for every subtype of it, and that appears to be what you want. |
In response to Loduwijk
|
|
I want the new instance to belong to a list. Using your way I realized I was using an extra line that was not needed. So all in all I ended up with this.
var/list/skillselection = new for(var/skill in typesof(/skills/Air)-/skills/Air) skillselection += new skill thanks for the help. =) |