ID:1778428
 
(See the best response by Kaiochao.)
Code:

Example:

mob/proc/Cast_Fireball()
var/T = src.AttackTarget
src << "You casted fireball at [T]!"

mob/var/CurrentSpell = Cast_Fireball()

mob/proc/CastSpell()
src.CurrentSpell()

//////THIS ISNT MY ACTUAL CODE, JUST AN EXAMPLE
/////OF WHAT IM TRYING TO ACCOMPLISH :)


Problem description:

I want to know how I can do something like this.
Best response
If you use call()(), you can set CurrentSpell to the "path" of the proc, such as /mob/proc/Cast_Fireball
Thank you so much, didn't know about the call proc!!! You are a great help
I'm having trouble, you think maybe you could give me an example how to do this? It's not working.

I tried

mob/var/attacktarget = null
mob/proc/Cast_Fireball(var/mob/T)
mob/var/currentspell = /mob/proc/Cast_Fireball


mob/verb/TestCast()
call(usr.currentspell)(T = usr.attacktarget)

I get errors I tried many time, can you give an example how to properly do this?
under mob/verb/TestCast(), call takes two arguments in the first set of parenthesis:

call(source, procname)(args)

Also, I tested this using this example:

client

var/current = "Calling"

proc/Calling(T)
src << T

verb/TestCall(A as text)
call(src,current)(A)


This seemed to work. You're able to invoke the proc of an object using a string as the proc.
Wow thanks for the fast reply, I'll try in the morning
This is really weird... I tried to put

    call(src,ChanceOnHit)()   //My var

////This causes it to be an unknown proc when I try to ///use the verb... but when I use
call(src,current)() //IT WORKS? So what the hell, how //come it works when I use current, but when I put it as ///ChanceOnHit it gives errors?

EDIT: NVM, for some reason it's working now.. that was REALLY weird lol
I wanted to post a little update regarding this.

I for whatever reason forgot about text2path() and then saw that it is possible to assign global procs as strings to objects.

This means that it is indeed possible to edit the string while also using embedded expressions to fully customize which proc you'd like to call, like "some_proc_[rand(1,10)]".

proc/call_proc(T)
call(text2path(T))(args.Copy(2))

proc/custom_proc()
world << "hi."

object1
var/my_proc = "/proc/custom_proc"
proc
do_something()
call_proc(my_proc)