ID:1865346
 
Code:


Problem description: Okay lets say im creating a mob.

var/mob/m=new(loc) like so. But i want it equal to a specific path with its variables. i could go var/mob/newpath/m=new(loc) however the path is kinda variable so it could be a number of things. I currently have the values of the correct paths but im having a hard time making var/mob/m have the values of that path. Is there a way to do this? thanks! I think ive even done it before i just forgot


current code
            for(var/mob/enemy/dungeon/e in locate(x,y,copyZ))
world<<e.type
e=new();e.loc=locate(x,y,newZ)


this will make a mob of the incorrect type however from that mobs location. It seems to just make the type of mob/enemy/dungeon even though world<<e.type prints out the correct type
nvm i found a method, though i still wouldnt mind experts showing me a method to see if mine is as good
If you look up the "new" operator, you'll see that it can take a specified type. Of course, the type doesn't have to match the declared type of the variable.
// e.g.
var enemy_types[] = list(
/mob/enemy/slime,
/mob/enemy/rat,
/mob/enemy/skeleton)

var random_enemy_type = pick(enemy_types)

var mob/enemy/random_enemy = new random_enemy_type (locate(x, y, newZ))
There is also a way to do this with text2path(), but Kaiochao's method would be prefered. Me personally, I would create an associated list with the /mob name with the value of the /mob path. But that's my own personal preference because I could then pick from the list based on a simple name.

var/list/enemy_types = list(
"slime" = /mob/enemy/slime,
"rat" = /mob/enemy/rat,
"skeleton" = /mob/enemy/skeleton,
)
In response to Kaiochao
hmmm thats an interesting way to do it. Thank you i appreciate it