ID:1743548
 
(See the best response by Mightymo.)
Code:
//There is more code above this. Just using the end as example
if(M.health<=0)
del(M)

mob/someone
icon = 'monster.dmi'
health = 50
strength = 5
New()
start
for(var/mob/M in get_step(src,src.dir))
walk_rand(src,5)
sleep(10)
goto start


Problem description: I'm trying to get my mob to respawn after it is defeated. I could just give the mob its 50 health and move its location to a random location but I want it to run the New() proc again so I can make any mob regardless of its skills refresh. I can't call the New() proc.

I dont want the straight answer as I want to learn from my mistakes. Any advice you can give will be greatly appreciated. Thank you

P.S. If something in my code is "seriously" bad/wrong let me know so I can work on learning how to correct it. Thanks


Best response
Realistically, its probably better to create an initialization proc that you call from New(), and then can also call later. This would allow you to reuse the mob without directly calling New().

Also, you probably shouldn't be using goto in that case, since a normal loop would work just fine. Your New() will actually never return, so you should probably place the AI into a separate function and spawn it.
Thanks, I'm working on implementing your suggestions now. How do I call a proc in a different area? My attack command is under mob/player/attack() after it confirms the mob has 0 health I try to call my new proc Renew() which is under mob/someone. I get the complied error Renew: undefined proc. How do I get it to look for the Renew proc under the mob/someone?
Assuming that you have the mob called m, m.Renew() would cause mob m to use Renew().
mob
var/level
var/strength
var/health
icon = 'me.dmi'
icon_state = "normal"
var board = 0
player
Bump(atom/O)
if(istype(O,/obj/board))
Training(src)
for(var/mob/M in get_step(usr,usr.dir))
if(M==src)return
world << "test [M]"
M.health-=strength
health -= M.strength
src << "You hit [M.name] for [src.strength]!"
src << "[src.name] hits you for [M.strength]!"
if(M.health<=0)
del(M)
M.RenewSomeone()// Calling proc from here
if(src.health<=0)
src.Move(locate(1,1,1))
world << "you died"
src.health = 50

mob
someone
icon = 'monster.dmi'
New()
RenewSomeone()
proc
RenewSomeone() // But its not finding it here.
health = 50
strength = 5
for(var/mob/M in get_step(src,src.dir))


Do you see what I mean from the above code? I use the M.RenewSomeone() but it can't find the proc. I'm going to try it globally but I'm not sure how im going to set that up yet. I'll play around with it and check back here for something someone might reply. Thanks again
for(var/mob/M in get_step(usr,usr.dir))


mob
someone
icon = 'monster.dmi'
New()
RenewSomeone()
proc
RenewSomeone() // But its not finding it here.
...


Look at both of those snippets and you'll find your problem.
On top of what FKI said, there's another issue in your code here:

                if(M.health<=0)
del(M)
M.RenewSomeone()// Calling proc from here

When M.RenewSomeone() is called, M will be null (since it was deleted).
You guys are awesome. What I figured out from your comments is that I needed to change the for command from this to this.
for(var/mob/M in get_step(usr,usr.dir))
for(var/mob/someone/M in get_step(src,src.dir))


I'm not sure what the second issue you referenced FKI. I did change some stuff within the RenewSomeone() but the stuff you posted above I didn't change.

As far as what you said LordAndrew. I removed the del(M) all together. When I ran the game with the del(M) after the M.RenewSomeone() I got an error during the game. Without the del it calls the proc and in the proc I added a random x,y,z location and it restores its health.

Thanks all for helping me figure the answers out without having you write the codes. :)
In response to DaveHere
I was showing you that you used the wrong type haha. I'm glad you got it, good stuff.
lol, got ya. Thanks