ID:2163317
 
(See the best response by Nadrew.)
Code:
    if(usr.Species=="Bulbasaur")
var/mob/N=new /mob/Pokemon/Kanto/Bulbasaur


Problem description:

As you can see, the path of the second line depends on usr.Species. Right now, I have the two lines of code repeated for 151 Pokemon.

I want to condense it, like this:

if(usr.Species=="Bulbasaur")
usr<<"Bulbasaur!"


can be condensed into this

usr<<"[usr.Species]!"


Is there any way I can accomplish this by substituting some expression into the end of the path name?

Best response
var/mob/N = new text2path("/mob/Pokemon/Kanto/[usr.Species]")
if(N)
usr << "You got a new [N.name]!"
This makes sense! Thank you so much!
I was messing around with text2path, and it seems the compiler doesn't like the syntax of:

var/mob/N = new text2path("/mob/Pokemon/Kanto/[usr.Species]")


but instead:

var/mob/N = new(text2path("/mob/Pokemon/Kanto/[usr.Species]"))
In response to Dr.DraX
DM doesn't let you use the return value of procs as types for the new keyword. This is because it's ambiguous between using a variable with arguments to the constructor vs calling a proc with arguments to the proc.

Solution:
var
new_type = text2path(...)
mob/N = new new_type
In response to Kaiochao
Yep. It needs to be two lines.

You actually don't even need text2path for this, technically. Since olden days, strings have been recognized just as well for new() as type paths. Internally, BYOND simply does text2path() for you.