ID:2187718
 
(See the best response by Ter13.)
I wanted to know if there were a way to use strings to determine which proc to call. Not in the context of an if statement, but in this way. I know MOO, so I know how to do it there, but I don't know if BYOND has the same capability.


number = rand(1, 5)
numstring = "[number]"

vstring = "verb_" + numstring


vstring()

Is there code to then call the resulting verb, other than using switch() or a string of if statements?

You can use call()() like so:
call(src, "verb_[rand(1, 5)]")()

call()() is unsafe because it bypasses compile-time checks for whether an object actually has the proc you want to call (which is what hascall() is for, I guess).

Fortunately, there are better, safer alternatives that are more object-oriented, such as the "Command" pattern:
action
proc
Perform(mob/actor/Actor)

blah_blah
Perform(mob/actor/Actor)
Actor << "Blah blah"

blargh
Perform(mob/actor/Actor)
// do other stuff

// etc.

mob/actor
var list/actions

New()
actions = list(
new /action/blah_blah,
new /action/blargh,
// etc.
)

verb
do_random_action()
var action/action = pick(actions)
action.Perform()

In an action RPG, active skills can be like these "action" datums. You could implement a hotbar as a simple array of action datums, and when a hotkey is pressed, you perform the action bound to that hotkey.

More info here: http://gameprogrammingpatterns.com/command.html
Is the same thing possible with vars?
Best response
If you know both that the target object has the variable and that the variable's name has been resolved at compile-time:

datum.var_name //compile-time access


If you don't know whether the target object has the variable, and the variable's name hasn't been resolved at compile-time:
datum.vars["var_name"] //runtime instance access


If you don't know whether the target object has the variable, but the variable's name has been resolved at compile-time:

datum:var_name //runtime access