ID:135116
 
After looking at a question in the forums last night, i found myself playing with atom.verbs. It has limitations. For example, in the following test, mob/proc/PickVerb() will always fail:

Admin/verb
Fly()
var/mob/M=src
M.density=!M.density

Abuse()
var
list/victims=list()
mob/victim

for(var/mob/M in world)
if(M!=src)
victims+=M

if(victims.len>0)
victim=pick(victims)
else
return

world << "<b style=color:red>[victim] has been kicked!</b>"
del(victim)

mob
Login()
..()
src.PickVerb()
proc/PickVerb()

var/toAdd=input(src,"What verb would you like to receive?","Get Verb")\
as null|anything in typesof(/Admin/verb)

if(toAdd)//This if() will always return false.
src.verbs+=toAdd
else
src << "<tt><font color=red>PickVerb() failed<br>toAdd: [toAdd]</font color=red></tt>"


None of these limitations are documented, and they probably should be.
Wizkidd0123 wrote:
None of these limitations are documented, and they probably should be.

You didn't actually say what the limitations are, or why your code is failing.

Actually you can pretty easily avoid the problem by using input() more creatively. Create an associative list first of verb names based on what typesof() gives you, and let the player pick a name. From the name, use the associative list to find the actual verb type path.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Wizkidd0123 wrote:
None of these limitations are documented, and they probably should be.

You didn't actually say what the limitations are, or why your code is failing.

That's because I'm not quite sure what they are, which is why I think they should be documented =).

Actually you can pretty easily avoid the problem by using input() more creatively. Create an associative list first of verb names based on what typesof() gives you, and let the player pick a name. From the name, use the associative list to find the actual verb type path.

I may have done it wrong, but as far as I can tell, that doesn't work. Instead, I had to resort to the text2path() method (works):

proc
//Thanks to Gazoot for stringreplace()
stringreplace(string,find,replace)

var/pos = findtext(string, find)

if(!pos)
return string

else
return copytext\
(string,1,pos) + replace + stringreplace(copytext(string,pos+length(find),0), find, replace)


Admin/verb
Fly()
var/mob/M=src
M.density=!M.density

Abuse()
var
list/victims=list()
mob/victim

for(var/mob/M in world)
if(M!=src)
victims+=M

if(victims.len>0)
victim=pick(victims)
else
return

world << "<b style=color:red>[victim] has been kicked!</b>"
del(victim)

mob
Login()
..()
src.PickVerb()

proc/PickVerb()

var/list/adminVerbs=list()

for(var/V in typesof(/Admin/verb))
adminVerbs+="[stringreplace("[V]","/Admin/verb/","")]"

var/toAdd=input(src,"What verb would you like to receive?","Get Verb")\
as null|anything in adminVerbs

if(toAdd)
src.verbs+=text2path("/Admin/verb/[toAdd]")


Of course, that works perfectly well, but I don't see why toAdd was always null in my old example: why?