Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ MUSHclient ➜ General ➜ Alias assistance

Alias assistance

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1 2  

Posted by David Berthiaume   (202 posts)  Bio
Date Sat 08 Oct 2005 04:39 AM (UTC)

Amended on Sat 08 Oct 2005 04:41 AM (UTC) by David Berthiaume

Message
Right then, I should know this, but for some reason the code is escaping me.

I'm basically trying to create my own profile of characters on the mud I play.

I want to create an alias that does several things.

The alias is going to be: name *

Now, I know most of what I need, there are however 2 things I want to do. One I can't remember how. The other I've never done.

The thing I can't remember is to compare that wildcard to an array of names held in a variable.

I.E. if (wildcard) <> (array of names)
Then note whatever.

That's the thing I know I know how to do, I just can't remember.

The other thing is a bit more complicated.

Ya, know... I'm such an idiot... In the middle of explaining the second thing I wanted to do, it came to me. Will this work?

name = "%1"
addname = split(name)
if addname(lbound) = "add" then
oldnames = Getvariable("NameList")
newname = addname(ubound)
oldnames = oldnames + newname
SetVariable "NameList", oldnames
end if
The only problem i see with that is spacing, How do I add an extra space to make it work? The way I did it before was based off a wildcard.
a = GetVariable ("Whatever")
b = " %1" 'yeah, so with the ubound, how do I put that extra space needed?
a = a + b
SetVariable "Whatever", a


Basically in this alias, I'm gonna have several functions.

name "info" - noting the current charactername being used, and then listing all the names in the NameList(this is the part I already know how to do
name <name of a character compared to the list of names then switching the name variable to that name if on the list>
name add <new name>
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #1 on Sat 08 Oct 2005 07:18 AM (UTC)
Message
All Right then. I got the name <info> part done, that was easy.

I also got the name add <new name> part all figured out.

All I need help with is comparing to the list of names. Which I might also add will be very handy in the adding of new names, I wouldn't want to double up names would I?
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #2 on Sun 09 Oct 2005 10:36 AM (UTC)
Message
Not sure about this, but I think a for.. each will work here.

This is what I got so far. If I'm not on the right track, lemme know.
newname = "Franko"
namelist = split(Getvariable("namelist")) 'Names in the array are irrelavant to what I have here, suffice it to say, none of the names are franko
for each x in namelist
note x
if newname = x then
note "The name matches"
exit for
else
Note "The newname does not match"
end if
next
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #3 on Mon 10 Oct 2005 03:58 AM (UTC)

Amended on Mon 10 Oct 2005 04:04 AM (UTC) by David Berthiaume

Message
<aliases>
  <alias
   match="name *"
   enabled="y"
   expand_variables="y"
   send_to="12"
   sequence="9000"
  >
  <send>addname = split("%1")
nameoption = "%1"
namelist = split(GetVariable("NameList"))
if nameoption = "info" then
for i = lbound (namelist) to ubound (namelist)
Note "|Character: " &amp; namelist(i)
next
elseif addname(LBound (addname)) = "add" then
newname = addname(Ubound(addname))
for i = LBound(namelist) to UBound(namelist)
if newname = namelist(i) then
match = "true"
else
match = "false"
end if
next
if match = "false" then
newname = " " &amp; newname
oldlist = GetVariable("NameList")
newlist = oldlist + newname
SetVariable "NameList", newlist
else
Note "That name is already on the list"
end if
else
newname = nameoption
for i = LBound(namelist) to UBound(namelist)
if newname = namelist(i) then
match = "true"
exit for
else 
match = "talse"
end if
next
if match = "true" then
SetVariable "Name", newname
else
Note "That name is not on the list of names"
end if
end if
</send>
  </alias>
</aliases>
Success!!

But I just realized I'm gonna want to remove a name from an array sometimes, so if anyone knows how, so I don't have to overly stress my brain on figuring it out, you'd get much appreciation from me.
Top

Posted by Nick Gammon   Australia  (23,100 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 10 Oct 2005 08:02 AM (UTC)
Message
Quote:



else 
match = "talse"
end if



I would fix this for a start. "talse" doesn't sound right.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #5 on Mon 10 Oct 2005 08:22 AM (UTC)

Amended on Mon 10 Oct 2005 08:24 AM (UTC) by David Berthiaume

Message
Yeah, I fixed it. but it really didn't even matter. I didn't even need to put that line of code in.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #6 on Mon 10 Oct 2005 07:05 PM (UTC)
Message
VBScript doesn't contain a function to remove a given item from an array, so you'll have to do it manually.
That means iterate through your array, and remove the offending name when you get to it, basically. This can be optimized through various means, such as a binary search (after sorting the list), but just iterating through will work just as well.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #7 on Tue 11 Oct 2005 04:56 AM (UTC)
Message
namelist = split(GetVariable("NameList"))
remname = "Franko"
for i = LBound(namelist) to UBound(namelist)
if remname <> namelist(i) then
newlist = namelist(i) & " " & newlist
end if
next
Note newlist


At the moment, I'm just trying to fingure out how to go through each one in the array, creating a new array. This is what I have so far. The problem with what I have here is if I trigger the alias 2 times, then I get a problem.

One trigger:
Relafen Frostonius Jodah Demonica

two triggers:
Relafen Frostonius Jodah Demonica Relafen Frostonius Jodah Demonica

Anyways, That's what is happening, It's not resetting between alias uses. I can get it to remove the names if I want. But it gets funky. What am I doing wrong?
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #8 on Tue 11 Oct 2005 05:22 AM (UTC)
Message
You're just making the array into a space delimited string? Why not use the join function?

Also, is that the output? or the variable contents?

I honestly can't say I fully understand what you mean by creating a new array. (are you just trying to remove the name from the array?)

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #9 on Tue 11 Oct 2005 06:10 AM (UTC)

Amended on Tue 11 Oct 2005 06:37 AM (UTC) by David Berthiaume

Message
I have a variable of all my character names for this particular name.

I'm lazy. I'd rather sit here and spend 5 hours trying to figure out how to make one alias do all the work for me. Simply because that's the way I am, than just remove the name from the variable by hand.

I have the alias name *

I can successfully compare a new name to the namelist(I.E. A mushclient variable, that is also an array) If i type name <name> that is not in the list, it does nothing. Otherwise, it changes the variable "name" to the new selected name. This lets me switch characters easily, I don't need 5-6 different worlds customized to each character(Note: All characters hold most skills in common. Just the specialized skills vary depending on race). I can then only use 1 world, and just script in various "if" statements to keep things flowing easily.

I can also successfuly add a new name into the NameList variable(I.E. the array).

What I am currently working on is working on removing a name in the Variable NameList.

When I was testing the name removal script, I was using an alias "test" and manually setting up the remove name, just to see if it worked. That's how I did it to get name add <name> working.

The output you are seeing there is just a Note to the output buffer, It is the contents of the namelist array. I intentionally used a name that was not in the array.

This is the code for the script, Basically, what will happen is I'll have an elseif statement that matches on the LBound for remove, then it'll run this script
namelist = split(GetVariable("NameList"))
remname = "Jodah"
for i = LBound(namelist) to UBound(namelist)
if remname <> namelist(i) then
newlist = namelist(i) & " " & newlist
end if
next
Note newlist


First trigger of alias:
Relafen Frostonius Demonica

This is the second triggering of the alias(immediately afterwards):
Relafen Frostonius Demonica Relafen Frostonius Demonica

The third:
Relafen Frostonius Demonica Relafen Frostonius Demonica Relafen Frostonius Demonica

I was under the impression that every time an alias goes off it resets itself. Obviously, my impression is wrong.

Edit: Looking at the results, and thinking about it, The part that I'm missing is what to do in the loop if the remname = namelist(i)


Edit 2: The problem is at no point do I exit the for, so it'll keep running the for no matter how many times I run the alias. It looks to me, that I'm going to need to run a double loop!

One to build the new array, and one to set the new array and exit the for loop. because right now, it's just running in the for loop each time I trigger the alias.
Top

Posted by Nick Gammon   Australia  (23,100 posts)  Bio   Forum Administrator
Date Reply #10 on Tue 11 Oct 2005 07:53 AM (UTC)
Message
To remove an item from a list, try using the MUSHclient "array" capability, which provides key/value pairs.

http://www.gammon.com.au/scripts/doc.php?general=Arrays

You could convert your list into an array, then delete an item by key, then convert it back.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #11 on Tue 11 Oct 2005 09:33 AM (UTC)

Amended on Tue 11 Oct 2005 09:36 AM (UTC) by David Berthiaume

Message
So, my question is, when using array's like that, does there have to be a value to the key?
Top

Posted by David Berthiaume   (202 posts)  Bio
Date Reply #12 on Tue 11 Oct 2005 09:59 AM (UTC)
Message
remname = Jodah
ArrayCreate "name"
ArrayImport "name", GetVariable("Namelist"), " "
Note ArrayExists ("name")
Note ArrayKeyExists ("name",  remname)


Everything works untill I get to the ArrayKeyExists


Actually, The ArrayImport isn't working. I dunno.
Top

Posted by Flannel   USA  (1,230 posts)  Bio
Date Reply #13 on Tue 11 Oct 2005 10:35 PM (UTC)
Message
You could try using a collection of array functions I made for afflictions, or at least, thats the original application, but it's really just a collection of array utilities.

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=5304
Fifth from the bottom of that page, post from me, link in that.

~Flannel

Messiah of Rose
Eternity's Trials.

Clones are people two.
Top

Posted by Nick Gammon   Australia  (23,100 posts)  Bio   Forum Administrator
Date Reply #14 on Wed 12 Oct 2005 02:19 AM (UTC)

Amended on Wed 12 Oct 2005 02:21 AM (UTC) by Nick Gammon

Message
You need to import key/value pairs, the value can be empty.

I have got this to work, although I think it would have been somewhat simpler in Lua.


remname = "Jodah"
SetVariable "Namelist", "Relafen Frostonius Jodah Demonica Relafen Frostonius Jodah Demonica"

' add empty values
names = Replace (GetVariable("Namelist"), " ", ",,") & ","

' create array
ArrayCreate "ary"

' make sure empty in case it already exists
ArrayClear "ary"

' import names
ArrayImport "ary", names, ","

' delete required key
ArrayDeleteKey "ary", remname

' export new names
SetVariable "Namelist", ArrayExportKeys ("ary", " ")



Of course, the first couple of lines are just there for testing.

The result is that duplicates are automatically eliminated (as the array functions do not allow duplicates), and the ArrayDeleteKey function deletes the required key.

Your code wouldn't have worked because you had:

remname = Jodah

when you meant:

remname = "Jodah"

Apart from the other problems. :)




- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


50,091 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.