[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Alias assistance

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Alias assistance
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1  2 

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Wed 12 Oct 2005 08:05 AM (UTC)  quote  ]

Amended on Wed 12 Oct 2005 08:06 AM (UTC) by David Berthiaume

Message
Perfect. I love it. I knew you could do that with Lua, I didn't know you set it up to work with VBscript. It never even crossed my mind to check.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Wed 12 Oct 2005 02:19 AM (UTC)  quote  ]

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
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Tue 11 Oct 2005 10:35 PM (UTC)  quote  ]
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.
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Tue 11 Oct 2005 09:59 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Tue 11 Oct 2005 09:33 AM (UTC)  quote  ]

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?
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 11 Oct 2005 07:53 AM (UTC)  quote  ]
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
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Tue 11 Oct 2005 06:10 AM (UTC)  quote  ]

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.
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Tue 11 Oct 2005 05:22 AM (UTC)  quote  ]
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.
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Tue 11 Oct 2005 04:56 AM (UTC)  quote  ]
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?
[Go to top] top

Posted by Flannel   USA  (1,230 posts)  [Biography] bio
Date Mon 10 Oct 2005 07:05 PM (UTC)  quote  ]
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.
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Mon 10 Oct 2005 08:22 AM (UTC)  quote  ]

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.
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Mon 10 Oct 2005 08:02 AM (UTC)  quote  ]
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
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Mon 10 Oct 2005 03:58 AM (UTC)  quote  ]

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.
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Sun 09 Oct 2005 10:36 AM (UTC)  quote  ]
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
[Go to top] top

Posted by David Berthiaume   (202 posts)  [Biography] bio
Date Sat 08 Oct 2005 07:18 AM (UTC)  quote  ]
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?
[Go to top] 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.


5,201 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]