ID:146776
 
Code:
mob/proc/create_mob()

var/list/mobs=flist("./mobs/") // List of mob file names.
for(var/v in mobs)
world << v
v=copytext(v,1,length(v)-3) // Make mobs a list of ckeyed mob names.
world << v

//Name mob.
var/mob_name
do
mob_name=input(src,"") as text
while(ckey(mob_name) in mobs)
if(!mob_name) return
var/mob/enemy/E=new
E.name=mob_name

//Apply icon
E.icon_state=input(src,"") as null|anything in icon_states(E.icon)
if(!E.icon_state) return

//Edit variables
for(var/v in E.editable_vars)
E.vars[v]=max(1,input(src,"",,E.vars[v]) as num)

//Save mob template.
var/savefile/F=new()
F << E
F.ExportText("./", file("mobs/[ckey(E.name)].txt"))
world << "Mob saved."

//For testing.
mob/verb/Make_A_Mob()
create_mob()
mob/enemy
var/list/editable_vars=list("Attack")
var/Attack=1

I snipped the input text for the forum, I'm sure they'll miss you as much as you miss them. =P

Problem description:
The while() loop always returns false. If I create two mobs with the same name ("Ant" for my example) it should make me name it again. I have debug messages in there, the first one displays "ant.txt" and "ant" is the second. ckey("Ant") is obviously "ant" and we know it's in the list, so there must be something I'm missing. Any guesses?


*Edit
Added some stuff to make it easier to test.
Your loop is not actually changing the contents of the list. Try this test verb out to see what I mean.
client/verb/test()
var/list/L=list("test1")
for(var/T in L)
src<<"T was [T]"
T="test"
src<<"T is now [T]"
for(var/T in L)
src<<"T is still [T]"

You will want to do something more like the following.
mob/proc/create_mob()

var/list/mobs=flist("./mobs/") // List of mob file names.
for(var/v = 1 to mobs.len)
world << mobs[v]
mobs[v]=copytext(mobs[v],1,length(mobs[v])-3) // Make mobs a list of ckeyed mob names.
world << mobs[v]
In response to Loduwijk
Aww darnit. I just wrote up a post about when variables are referenced not too long ago. I should have caught this. Thanks, Loduwijk. =)