Belt system

Posted by Zendu on Thu 13 May 2004 11:15 AM — 19 posts, 82,684 views.

#0
I give up!


world.DeleteVariable ("count-ash") & world.DeleteVariable ("count-kelp") & world.DeleteVariable ("count-bayberry") & world.DeleteVariable ("count-kola") & world.DeleteVariable ("count-bellwort") & world.DeleteVariable ("count-Lobelia") & world.DeleteVariable ("count-bloodroot") & world.DeleteVariable ("count-moss") & world.DeleteVariable ("count-cohosh") & world.DeleteVariable ("count-pear") & world.DeleteVariable ("count-elm") & world.DeleteVariable ("count-skullcap") & world.DeleteVariable ("count-enchinacea") & world.DeleteVariable ("count-sileris") & world.DeleteVariable ("count-ginsing") & world.DeleteVariable ("count-valerian") & world.DeleteVariable ("count-goldenseal") & world.DeleteVariable ("count-weed") & world.DeleteVariable ("count-hawthorn") & world.DeleteVariable ("count-Leather") & world.DeleteVariable ("count-Coal") & world.DeleteVariable ("count-Obsidian") & world.DeleteVariable ("count-Cloth") & world.DeleteVariable ("count-Rope") & world.DeleteVariable ("count-Gold") & world.DeleteVariable ("count-Silver") & world.DeleteVariable ("count-Ice") & world.DeleteVariable ("count-Steel") & world.DeleteVariable ("count-Iron") & world.DeleteVariable ("count-Wood") & world.DeleteVariable ("count-stag") & world.DeleteVariable ("count-yellow") & world.DeleteVariable ("count-red") & world.DeleteVariable ("count-gold") & world.DeleteVariable ("count-green") & world.DeleteVariable ("count-blue") & world.DeleteVariable ("count-purple")
world.Send "p pocketbelt19630"
world.Send "p pocketbelt131810"
world.Send "p pocketbelt131999"
world.Send "p pocketbelt132009"
world.Send "p pocketbelt131215"
world.Send "p pocketbelt87258"
world.Send "p pocketbelt25680"
world.Send "p pocketbelt86557"
world.Send "p pocketbelt130587"
world.Send "p pocketbelt68619"
world.Note "herbs:" & GetVariable ("count-ash") & GetVariable ("count-kelp") & GetVariable ("count-bayberry") & GetVariable ("count-kola") & GetVariable ("count-bellwort") & GetVariable ("count-Lobelia") & GetVariable ("count-bloodroot") & GetVariable ("count-moss") & GetVariable ("count-cohosh") & GetVariable ("count-pear") & GetVariable ("count-elm") & GetVariable ("count-skullcap") & GetVariable ("count-enchinacea") & GetVariable ("count-sileris") & GetVariable ("count-ginsing") & GetVariable ("count-valerian") & GetVariable ("count-goldenseal") & GetVariable ("count-weed") & GetVariable ("count-hawthorn") & GetVariable ("count-Leather") & GetVariable ("count-Coal") & GetVariable ("count-Obsidian") & GetVariable ("count-Cloth") & GetVariable ("count-Rope") & GetVariable ("count-Gold") & GetVariable ("count-Silver") & GetVariable ("count-Ice") & GetVariable ("count-Steel") & GetVariable ("count-Iron") & GetVariable ("count-Wood") & GetVariable ("count-stag") & GetVariable ("count-yellow") & GetVariable ("count-red") & GetVariable ("count-gold") & GetVariable ("count-green") & GetVariable ("count-blue") & GetVariable ("count-purple")


This SHOULD delete, then add up the amount of herbs i have in my belts! [i have adding triggers, they work fine]
Russia #1
The world.DeleteVariable&world.DeleteVariable&... doesn't make much sense. It should throw an error of some sort, I think. But in any case, why delete the variables when you can just set them to 0? And it would be much better to do this in a script file, using arrays or lists, or whatever your favourite language has to offer. An example is in yet another one of my plugins - RiftList, at www.darkfenixxx.biz/achaea.
Greece #2
I don't know, I was making a plugin yesterday that was supposed to delete some variables, and I added notes to see what it was doing. It was deleting variables 1, 2 and 3, and adding a variable called 0. When i reloaded it, it still deleted 1, 2 and 3, which shouldn't have been there. Maybe it was my fault, but I just deleted the state file and reloaded it, and it works now. Maybe it has the same problem with you? Although I don't know how legal the stringing together commands with ampersands is.
#3
so how do i set all those to 0? its also having problems with the world.note line (i know there are better ways to do this, however i realy wanted to try making this on my own)
USA #4
The problem with your note line is how and when things execute. Mushclient does not run script in parallel, so if you send a command to the mud inside of a script, the command isn't executed until after your script exits and returns control to Mushclient. So, what happens is that your note line gets sent, *then* all the commands you did with 'send' are executed and I assume triggers capture those and put them in variables.

There are two ways to fix this. One is to use a timer to delay when the note happens. In other words, you would use world.addtimer as a temporary timer, then have that call its own script containing your note line. The other way is to use some response from the mud, so if you know "p pocketbelt68619" would always produce some sort of unique response you could have the script for it generate your note instead.

I am posting a suggestion about something I think can stream line the issue with deleting or clearing variables, making it easiereasier in the future, but it may be a while before/if Nick impliments it.
Amended on Thu 13 May 2004 09:26 PM by Shadowfyr
Australia Forum Administrator #5
Quote:

world.DeleteVariable ("count-ash") & world.DeleteVariable ("count-kelp") ...


This is not going to do what you expect.

By stringing together the deletes it is going to do something strange like this. Say you only had the first two like I have there.

It is trying to DeleteVariable a single variable named:

"count-ash" concatenated with world.DeleteVariable ("count-kelp")

Say that world.DeleteVariable ("count-kelp") works it will return "0" so the other Delete will try to delete:

"count-ash0"

which will not exist.

Thus, depending on the order of execution of the & things it will probably delete at most a single variable.

A simple loop might be better, like this:


varList = World.GetVariableList

If Not IsEmpty (varList) Then
  
  For Each v In varList 
    if Left (v, 6) = "count_" then
       world.DeleteVariable v
    end if
  Next

End If


This will delete all variables starting with "count_".

You could instead do:


  world.SetVariable v, "0"


if you wanted to just set them to zero.

Also, as I mentioned in a recent reply, you cannot have hyphens in variable names, so those variables won't exist anyway. Use underscores instead.

Also, Shadowfyr is right, sending stuff to the MUD and getting a reply takes a finite time, you cannot expect the trigger to fire while your "deletevariable" script is running - it won't.



Amended on Thu 13 May 2004 10:52 PM by Nick Gammon
Australia Forum Administrator #6
A better way anyway might be to use the new "array" functions, which can store everything in an array.

eg.


ArrayCreate "herbs" ' make array

ArraySet "herbs", "ash", 22
ArraySet "herbs", "kelp", 5


... and so on.

Then to find a particular value you do this:


world.Note ArrayGet ("herbs", "ash")


To delete the lot just do:


ArrayClear "herbs"


Now that is simpler, isn't it?

The whole lot can be exported to a variable for next time like this:


SetVariable "herbs", ArrayExport ("herbs", ",")


This makes a single variable "herbs" with each value as a comma-delimited list of names/value pairs.

Read up on the array functions, I think they will make your life easier.
USA #7
Also, your variable names cant have - (dash) in them. If you want a seperator, try an underscore (_).
#8
so it should look like this
Clear:
ArrayClear "herbs"
(probe the belts)

ADD:
^(.*?) ash$
ArraySet "count", "ash", + %1

DELAY, THEN:
World.Note ArrayExport ("herbs", ",")



do i need the newest version of Mush to do this? mine doesnt recognize array commands
Australia Forum Administrator #9
Have a look at this page:

http://www.gammon.com.au/mushclient/function.php?name=ArrayGet

It mentions that you need version 3.46 or more.
#10
how do i get all them?

DoAfter 1,
"herbs", ArrayExport ("herbs", ",")
world.Note GetVariable ("herbs"), 12





the trigger
ArraySet "herbs", "myrrh", + %1


seems to add the ammount, the whole goal in this is for it to add multiple lines like

154 myrrh
250 myrrh
250 myrrh
Amended on Sun 16 May 2004 09:15 AM by Zendu
Australia Forum Administrator #11
I'm not sure I understand here. Was that one or two triggers, or a trigger and an alias? What gets sent by the MUD exactly? When do you want all of them? Little snippets like that are just confusing.

Quote:

ArraySet "herbs", "myrrh", + %1


This won't make much sense, all you are doing is setting something like (assumming %1 contains "50"):

ArraySet "herbs", "myrrh", + 50


That will just make myrrh 50, not the old value plus 50.

You want something like this to bump the amount, if that is what you are trying to do:


ArraySet "herbs", "myrrh", CInt (ArrayGet ("herbs", "myrrh")) + %1


That retrieves the old value and adds the new one to it.
#12
My goal is one alias "belts" that

Clears the array herbs
then probes several pocketbelts(which displays alot of herbs like 250 myrrh,250 myrrh, 82 myrrh, 32 red ink etc etc)
The triggers are set to add those amount to the arrays.
Then i whould like the alias to display the total amounts. So i need a delay (i think?) so that it has time to do the adding
#13
got everything working, but its in 2 aliases, now all i need is to put it on one
Russia #14
A delay for the "probe belt" commands to produce output would be susceptible to lag. A better way would be to use triggers. If I remember correctly (haven't used pocketbelts in ages) then probing them gives you something like:

Your pocketbelt is holding:
100 myrrh, 25 ginseng, 30 goldenseal
10 bloodroot, 15 kelp, 29 valerian
H:2340, M:3400 ce-

All you'd need to do is make a trigger for the first line, a trigger for the prompt, and a regular expression trigger for the actual herbs. The first line trigger then could enable the herb trigger and the prompt trigger, and the prompt trigger would disable the herb one. That would work regardless of how bad the lag is, since it'll start counting the herbs only when you know that it's the actual pocketbelt you are looking at, and end counting them as soon as the pocketbelt output ends (with a prompt). That's how most of such systems work.
#15
it works! any way to force wordwrap it? not that worried about lag, since i wont be doing it any imporatnt time
#16
The problem is that it doesnt word wrap it, and if i turn wordwrapping on, it does the first line, but not the second.

so with it on or off, i miss something.
Russia #17
You mean to wrap the world.note output? It would be best to simply format it in the script, since echoing everything on one line doesn't make for a very visible display anyways.
#18
Wouldn't it make more sense to do this using the BELTLIST (or BL) command? That's what I'm doing and it seems much easier.

My only problem is that I was unable to make a single regular expression that would match 1, 2, or 3 times per line, even with the option to match multiple times on a single line. I ended up making three separate patterns to match all three cases.

For example, when I check the contents of my rift (almost identical to the pocketbelts display), I see this

Glancing into the Rift, you see:
  [ 483] bayberry bark      [ 182] bellwort flower    [  90] black cohosh
  [ 868] bloodroot leaf     [ 100] blue ink           [  75] cloth
  [ 100] echinacea          [ 801] ginseng root       [  10] gold ink
  [ 133] goldenseal root    [  60] green ink          [ 443] hawthorn berry
  [ 327] irid moss          [ 680] kelp               [ 540] kola nut
  [   1] lady's slipper r   [ 895] lobelia seed       [ 476] myrrh gum
  [  16] obsidian           [  39] piece of stag's    [ 208] prickly ash bark
  [ 461] prickly pear       [  67] purple ink         [ 135] red ink
  [  51] rope               [ 284] sileris            [ 129] skullcap
  [ 506] slippery elm       [ 756] valerian           [   9] wood
  [  60] yellow ink


I cannot make a single regular expression to match the number and item once, it seems.