Confusion with variables

Posted by Calimun on Thu 23 Jun 2005 11:04 AM — 15 posts, 59,766 views.

#0
Okay, this is kinda hard for me to explain, but I'll try my best.

I got the client set-up so that my MUCK will append certain lines to a log. Important things, like whispers, tells, people looking at my character, etc. But I ran into something else. Poses, for example.

Calimun does something stupid.

They don't have anything special about them, except that the first word is always going to be the character's name.

So I thought, 'What if I make a trigger that checks a text file, or some other Variable for friend's names, so that the log only gets poses from friends.' I'll need some way to, not only make this trigger and variable, but another trigger that adds friend's names from the muck into the variable list.

Help?
USA #1
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4603

and

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=4415

You basically make a variable that acts as a regexp type thing. Then you don't have to check via scripting, but your trigger will check automatically.
#2
I read through the pointed-out topics, and I tried out a few different things. But I think I'm missing the whole picture. I never worked with Regular Expression before, and I only had previous experiance with varibles with a few things.

Can someone baby-step me through this? x.x; Maybe try and explain this to me so I can understand and learn what I'm doing. ^^;

Right now, I have it set so that one trigger matches:

> Adding player "*"

But when I tried to send it to variable friendlist:

|%1

It just resets it into the playername with a OR sign in front.

That, and I'm having trouble with the other part, the trigger that matches names from the friendlist variable. Regular Expression just confuses me. ;.;
USA #3
You need to append the new name (with the pipe) to the old contents of the variable.

In VBScript, this is the snippet to add to your list:
setvariable "charlist", getvariable("charlist") & "|%1"

and then... for your trigger, you just have (@!charlist) as a match (whereever you want any name). Which means the charlist variable, and then the ! means not to parse it (as in, don't escape special characters, like the pipes), but your whole match text will have to be a regular expression.

Heres an example:
<aliases>
  <alias
   match="^addfriend (.*)$"
   enabled="y"
   echo_alias="y"
   regexp="y"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>setvariable "friendlist", getvariable("friendlist") &amp; "|%1"</send>
  </alias>
</aliases>

<variables>
  <variable name="friendlist">Calimun|Flannel</variable>
</variables>

<triggers>
  <trigger
   custom_colour="9"
   enabled="y"
   expand_variables="y"
   ignore_case="y"
   keep_evaluating="y"
   match="(@!friendlist)"
   regexp="y"
   repeat="y"
   sequence="50"
  >
  </trigger>
  <trigger
   enabled="y"
   expand_variables="y"
   ignore_case="y"
   keep_evaluating="y"
   match="^(@!friendlist) (.*)$"
   regexp="y"
   send_to="12"
   sequence="50"
  >
  <send>note "log: %0"</send>
  </trigger>
</triggers>


There is an alias (as a regexp, just so you could see how regexps look) which adds a name to the friendlist (which does need to be initialized to at least one name, since otherwise you will add your first name, and have the variable be "|bob" which will match on 'bob' or '' (empty string) which isn't good).

There are TWO triggers, one matches any person in your friend list, and colors it, the other matches any line that starts with a friend (and then a space), and note's it back (you can add your own log command). Of course, this will match on a LOT of lines (bob attacks jane, bob dances, bob disconnects) so you might want to rethink that.
And they are set to a lower sequence (with keep evaluating checked) so they can hopefully not interfere with any other triggers, and still catch everything before other triggers. They have expand variables checked, and are regexps. And ignore case is set, just because. If you are real careful with case when setting your list, you'll be alright without it. But bob and Bob are different things, when it comes to triggers.
Amended on Sat 25 Jun 2005 02:30 AM by Flannel
#4
Cool, thanks!

Everything is working. Well...almost everything. The only thing that's not working for me is the alias. The script code keeps giving me errors, and everytime I attempt a fix, another error pops up. This:

setvariable "friendlist", getvariable("friendlist" &amp; "|%1")

This gave me a missing ")" error, so I googled it up and I took out amp; and just left &. Another error came up, something about mismatch setvariable. So I quoted everything after getvariable. So now it looks like this:

setvariable "friendlist", "getvariable("friendlist" & "|%1")"

But now I get the error of Expected end of statement at column 41

Now I think I'm stuck. x.x;
#5
The &amp; is there because that's how it is saved in your world file. XML formats certain special characters like this. The snippets that Flannel posted were meant to be pasted directly into your Triggers and Aliases dialogs. You can highlight the text here (including the "aliases" and "triggers" element around the whole thing) and then use the Paste button on each of these dialogs to get the settings into your world settings.
Amended on Fri 24 Jun 2005 01:14 PM by Larkin
#6
I realized that after I posted, and that's what I did. I'm still getting the VBScript errors.
#7
Don't put quotes around getvariable when setting the variable.
#8
I didn't. I copy-pasted what Flannel has typed, as you told me to, and it still gives me scripting errors.
#9
You misunderstand me. What Flannel posted has no quotes around the entire call to getvariable. Your post has quotes there, however. Remove the extra set of quotes and try it again.
USA #10
Why dont you copy and paste the alias you have? So we can know exactly what you have, and what you dont. (Copy and paste, from the alias dialog, just like what you did to put it there... well, just the opposite).
#11
<aliases
muclient_version="3.65"
world_file_version="15"
date_saved="2005-06-24 15:36:56"
>
<alias
match="^addfriend (.*)$"
enabled="y"
echo_alias="y"
regexp="y"
send_to="12"
ignore_case="y"
sequence="100"
>
<send>setvariable "friendlist", getvariable("friendlist" &amp; "|%1")</send>
</alias>
</aliases>

This is what I copy-pasted before, and I pulled it from my World file. There's no quotes around getvariable, which is what I was trying to say before. >.<
#12
I see the problem now. You need to move the addition of the name to outside of the getvariable call. You only want to specify the name of the variable to retrieve and THEN add the name to the value to be stored back in it.

setvariable "friendlist", getvariable("friendlist") &amp; "|%1"


(I think that's right, but I don't use VBscript myself.)
USA #13
Yeah. Thats right. I have edited my post to correct it. Sorry about that, no idea how it happened.
#14
It works now, thanks!

I did alter it a bit tho. Now instead of a alias, I made it a trigger that looks for players added to my in-muck friendlist. So whoever I add in-game, is added to my client friendlist. ^^