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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Ren
Beginner


Joined: 04 Apr 2003
Posts: 27

PostPosted: Fri May 30, 2003 10:03 pm   

comparing a string to a variable
 

Used in a trigger value, the below doesn't work when I try to match it to the number stored in @amount.

#if ("36|32|28|24|20|16|12|8|4|0" =~ @amount) {#show Aha!}


This is the value for a test alias I created, which did work.

#if ("0|4|8|12|16|20|24|28" =~ {%1}) {#show Aha!}

*wonders why the first example doesn't work*

- Ren
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri May 30, 2003 11:04 pm   
 
The pattern matching operator =~ is almost never needed. As to why the first doesn't work when the second does I don't know. In both cases though the pattern should be the second operand. So you should have a syntax of:

#IF (@amount =~ "{36|32|28|24|20|16|12|8|4|0}") {#SHOW Aha!}

Note the addittion of braces to your pattern. When using the pattern matching operator all the rules that apply to trigger patterns apply. Hence the {}'s are required to mark a list of possibilities.
Reply with quote
Ren
Beginner


Joined: 04 Apr 2003
Posts: 27

PostPosted: Thu Jun 05, 2003 11:57 am   
 

Okay, this is the value when my trigger fires.

#ad inv_portal -1
#if ({@inv_portal} =~ "{20|16|12|8|4|0}") {#show Daily limit!}

The problem is that the #if fires when @inv_portal is

18
16
14
12
10
8
4
0
-4
-8

Why does it go around firing on weird numbers not specified in the string I gave it?

- Ren
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Thu Jun 05, 2003 12:42 pm   
 
Remember that you are dealing with a pattern here. Unless you explicitly anchor a pattern it will match at the beginning, at the end or anywhere in the middle. Thus a pattern of:
{20|16|12|8|4|0}

will match any number that contains one of those numbers. Such as: 2013, 16478, 87, 42, 10, -18, -121, -34, and many others.

What you need is to tell zMUD that the pattern is supposed to appear at the beginning and be the last thing in the number (i.e. that the number is one of those in the stringlist). This pattern should do it:
^{20|16|12|8|4|0}$

Kjata
Reply with quote
Ren
Beginner


Joined: 04 Apr 2003
Posts: 27

PostPosted: Thu Jun 05, 2003 12:52 pm   
 

Hmm, ^ and $ didn't work.
I also tried "{"20"|"16"|"12"|"8"|"4"|"0"}" which didn't work either.

- Ren
Reply with quote
Kjata
GURU


Joined: 10 Oct 2000
Posts: 4379
Location: USA

PostPosted: Thu Jun 05, 2003 1:15 pm   
 
Oh, and remove the curly braces from around @inv_portal.

Kjata
Reply with quote
Ren
Beginner


Joined: 04 Apr 2003
Posts: 27

PostPosted: Thu Jun 05, 2003 3:26 pm   
 

That fixed it. :) Thanks Kjata.

- Ren
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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