ID:143633
 
Code:
mob
var
target = null



mob // does not make image appear over target. FIX.
proc
engage(image/T = new('target.dmi',src))
if(src.client)
return 0
if(usr.target != null)
return 0
if(usr.target == null)
usr.target = src
src << T
usr << "works"
return

mob
enemy
DblClick(M as mob in view())
src.engage(M)


Problem description:

Hey guys. Just brushing up on my coding again. Still shaking the rust off as you can tell. I'm having trouble with my engage proc.

The purpose of the engage proc is to merely make a mob the user's target and have a marker on it, which is only viewable by the user.

I've tried a bit of research in the forums and I can't quite tie all the input into a solution.
You need to realise a difference between verbs and procs - verbs create arguments and procs take arguments. If you do:

mob/proc/Myproc(n as num)
world << n

mob/verb/Myverb()
Myproc()


Then that will keep outputting 0 because n as num doesn't really do much. If you do

mob/verb/Myverb(n as num)
world << n


Then you will get to select what n is.

You're meant to SEND arguments into a proc like so:

mob/verb/Myverb(n as num)
Myproc(n) //send Myproc() the number we select in this verb

mob/proc/Myproc(number) //when you do Myproc(n), it sends n to this proc and makes the variable number = n
world << number


With that in mind:

mob // does not make image appear over target. FIX.
proc
engage()
if(src.client)
return 0
if(usr.target != null)
return 0
if(usr.target == null)
var/image/T = new('target.dmi',src)
usr.target = src
src << T
usr << "works"
return
In response to Abhishake
Well my purpose really isn't using this proc in a verb. It's to double click the enemy and activate the proc that way.

mob
enemy
DblClick()
src.engage()


I'll just use this I guess.. But if anyone could give me a solution to this problem, that would be great! I'd love to know what i'm doing wrong.

mob
var
target = null
mob/enemy
e_marker



client
DblClick(mob/M)
if(M.user_name == usr.user_name)
del usr.e_marker
return
if(usr.target != null)
return 0
if(istype(M))
del usr.enemy_marker
usr.enemy = M
usr.e_marker = image('target.dmi',M)
usr << usr.emarker
In response to Abhishake
I've even tried retooling the code completely. It executes the third if statement outputting "works" but it will not put a marker over mob target.

mob
var
target = null
marker



mob // does not make image appear over target. FIX.
proc
engage(mob/enemy/M)
if(src.client)
return 0
if(usr.target != null)
return 0
if(usr.target == null)
usr.marker = image('target.dmi',M,"target")
usr.target = M
M << usr.marker
usr << "works"

mob
enemy
DblClick()
src.engage()
In response to ZLegend
There is no need to use M for the enemy (which you didn't pass to the proc, by the way). src should work fine, as it's the monster that was clicked. What you do need to pass is the attacker, as usr is not safe in a process. Also, you want to send the "marker" to the attacker's client, not the enemy.