ID:158277
 
So I was wondering how to have verbs in a list, as in the verb has a name, and in the list they see the name of the verb, and when they click it, it calls the verb:

mob
verb
use()
for(var/obj/things/t in world)
var/list/p_options = new
p_options.Add(t.options, "cancel")
input("Select an option from [t]") in p_options
obj
things
var/list/options = new
var/the_name_of_this_verb
New()
..()
for(var/a in verbs)
options += (a:the_name_of_this_verb) //How would I have the name of the verb pop up here, and yet\
if I was to use it, have it call the actual verb?

thing1
verb
pwn()
the_name_of_this_verb = "attack"
world<<"pwned!"
uberpwned()
the_name_of_this_verb = "super attack"
world<<"wut?"
thing2
verb
suck()
the_name_of_this_verb = "stink"
world<<"nub."
really_suck()
the_name_of_this_verb = "loser"
world<<"lol."
The hascall and call procs, I think, are what you're looking for.

EDIT
Don't use the colon! >:O
In response to Spunky_Girl
Spunky_Girl wrote:
The hascall and call procs, I think, are what you're looking for.

Thanks, I'll look into those as soon as I finish another aspect of my game I've been working on since I didn't know of these procs prior :)

EDIT
Don't use the colon! >:O

;) I know.
Speedro wrote:
and in the list they see the name of the verb, and when they click it, it calls the verb

To dynamically call a procedure (proc or verb, the two are really basically one and the same), use the call()() proc. You need either its procedure path or name and object (in this case you get the path from the verbs list), look up 'call' for more info.
To read the name of a procedure from its node path, you can use an undocumented technique to do just that outlined here: [link] (beginning at the text above the 3rd code box). What you do is just read the name var from a var containing the path using the . or : operators, just as if you were doing it with an actual object - even though you're not and reading a path's vars makes no sense. Procedure paths (e.g. /mob/proc/Die) are special and different from normal type paths (e.g. /mob/player), so they're an exception and it works with them.
In response to Kaioken
I really have no idea what I'm doing. :/

obj
thing
proc
this()
set name = "THIS"
//do stuff

that()
set name = "THAT"
//do stuff
mob
verb
use_thing()
var/list/templist = new
var/list/options = new
for(var/obj/thing/t in world)
templist += t
for(var/verb/a in templist)
options += a
var/proc/question = input("Select an option") in options:name
call(question)
In response to Speedro
mob/proc/testProc()
world<<"Test successful!"

mob/verb/Verby()
var/list/L = list("testProc")
var/whatever = input(src,"","") as null|anything in L
if(whatever)
if(hascall(src,whatever))
call(src,whatever)
In response to Speedro
Speedro wrote:
I really have no idea what I'm doing. :/

That is a correct observation. Nowhere in that code are you doing anything with verb paths (which you'd find in the verbs list), which is what you should be doing. Instead you're doing... well, a bunch of confused crap, basically, if you'll excuse the bluntness.
for(var/verb/x in List) just won't go, there's no type named 'verb' (and it's a reserved word), procedures aren't objects, and their reference is their node type path, so to access that you can't use an object filter, as that skips non-object values (like type paths).
Here's an example that lets a player select from a list of verb names one of his verbs to run (with no arguments). Note that you actually only need the verb paths to read the name and you don't need to use them to call the verb, as call() supports using the procedure name itself to call it, too.
mob/verb/SelectVerb()
var/list/verb_names = new
for(var/path in src.verbs)
var/verb_name = path:name //access the name from the path
verb_names += verb_name
var/chosen_name = input(src,"Select:") as null|anything in verb_names
if(!chosen_name) return

call(src,chosen_name)() //call the verb on the player's mob
In response to Kaioken
Thank you both; and another question (as always):

I'm not exactly sure if it's possible to create a full tree of verbs, but I'm not sure how to do it exactly. Ex:
obj
item
verb
this()
that()
other(mob/m) //How could I make it so if the player select this, it would bring up options "other" contains?"
//I know this obviously doesn't work:
jump()
sing()

mob
proc
call_item_verbs(obj/item/_item)
var/list/l = new
for(var/a in _item.verbs)
l += a
var/q = input("do stuff","ya.") in l
call(_item, q) (src)
In response to Speedro
It could be the fact that it's 4 AM at the moment, but I don't follow exactly what your question is. May you elaborate?
In response to Kaioken
Absolutely.

So for example, I have an object that contains many verbs, but I want them organized, so that if you selected the "attack" verb, it would then go down further into the attack verb options of the object such as "kick", and "punch".


Hence what I mean as in a tree- just like this:

mob
verb
attack()
kick()
punch()

If it still doesn't make sense, I'm more than happy to further elaborate. :)
In response to Speedro
mob
var/list/attacklist = list("punch","kick")
verb/attack()
var/v = input() in attacklist
call(src,v)()