Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Gael
Beginner


Joined: 18 Sep 2006
Posts: 29

PostPosted: Fri May 08, 2009 6:08 pm   

How to enumerate all the aliases in a class?
 
I'd be surprised if this hasn't been answered before, but I couldn't find anything. So here goes...

For a given class, I would like to be able to list and loop through all the aliases (or variables, or triggers, etc). Ideally I would get both the alias name and the associated script text, but just the name would suffice.

Any pointers would be much appreciated.

Thanks.
Reply with quote
wrym
Magician


Joined: 06 Jul 2007
Posts: 349
Location: The big palace, My own lil world

PostPosted: Fri May 08, 2009 7:28 pm   
 
I don't know of a way to do this via zscript. But the lua interface provides an easy enough interface to do so.



Code:
for i = 1 to zs.numalias do
if zs.getalias(i).class == "class you want to search" do
script stuff you want to do
end -- end if
end -- end for loop


for more information on the lua interface see :http://forums.zuggsoft.com/modules/mx_kb/kb.php?page=3&mode=doc&k=2920

And to get started you might want to check out Fang's lua tutorial: http://forums.zuggsoft.com/modules/mx_kb/kb.php?page=3&mode=doc&k=2862
_________________
"To the engineer, all matter in the universe can be placed into one of two categories: (1) things that need to be fixed, and (2) things that will need to be fixed after you've had a few minutes to play with them" - Scott Adams, The Dilbert Principle
Reply with quote
Gael
Beginner


Joined: 18 Sep 2006
Posts: 29

PostPosted: Thu May 14, 2009 6:09 am   
 
Thanks Wrym, your reply got me on the right track. Just for the sake of anyone else who stumbles on this, here's the Lua script I wrote to be able to search my aliases...

Usage: afind <searchterm>

Code:

searchterm = zs.param(1)
foundcount = 0
aname = ""
acomment = ""
displaytext = ""
displaytable = {}
foundalias = ""


print("Searching for '" .. searchterm .. "'.....")

acount = zs.numalias

for i=1,acount do

  A = zs.getalias(i)
 
  if string.find(A.name,searchterm) ~= nil then
    aname = A.name
    acomment = A.comment
    if (acomment == nil) then acomment = "" end

    foundcount = foundcount + 1
    displaytext = string.format("%20s : %s",aname,acomment)
    table.insert(displaytable,displaytext)
  end

end
table.sort(displaytable)

for foundalias in pairs(displaytable) do
  print(displaytable[foundalias])
end
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net