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
➜ Perl and if ( )
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Nid
Sweden (9 posts) Bio
|
Date
| Fri 25 Aug 2006 07:06 PM (UTC) Amended on Fri 25 Aug 2006 07:07 PM (UTC) by Nid
|
Message
| Hey!
I have a trigger, and then this to set summon names:
$summon1 = $world->trim ($world->GetTriggerInfo ($thename, 102));
$summon2 = $world->trim ($world->GetTriggerInfo ($thename, 104));
Now, if $summon1 = $summon2 I want $summon2 to be "$summon2 2"
Using:
if( $summon1 = $summon2 )
{
$world->setvariable("summon2", "$summon2 2");
}
The problem is, it doesn't matter if $summon1 is the same as $summon2 or not, it sets $summon2 to "$summon2 2" anyway.
And when I'm at it, anyone know if theres a "elseif" or "else" for perl?
Anyone know? :)
Thanks in advance! | Top |
|
Posted by
| David Haley
USA (3,881 posts) Bio
|
Date
| Reply #1 on Fri 25 Aug 2006 07:07 PM (UTC) |
Message
| You need to use '==', not '='. '==' is the equality test, and '=' is an assignment. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | Top |
|
Posted by
| Nid
Sweden (9 posts) Bio
|
Date
| Reply #2 on Fri 25 Aug 2006 07:15 PM (UTC) |
Message
| if( $summon1 == $summon2 )
{
$world->setvariable("summon2", "$summon2 2");
}
Did not work either. It always sets the summon2 variable to "summon2 2", no matter if they're the same or not :( | Top |
|
Posted by
| Onoitsu2
USA (248 posts) Bio
|
Date
| Reply #3 on Sat 26 Aug 2006 12:38 PM (UTC) |
Message
| try making it do the following after the set operations in your code.
$world->Note($summon1);
$world->Note($summon2);
And are the names correct?
If Not, then you are setting them to incorrect wildcards, if so then I have no idea, it could be the particular method of setting them, I always use variables, as attempting to retrieve a previous wildcard match, I have found to be quite messy and causes more problems than the ease of a few less variables is. Because of the particular execution time or even order of said trigger may occur AFTER the set summonX statements do.
if you can post your entire code I can see what I can do to debug it, perl is not my primary language, but I am learning it rapidly via reading these forums... heheh
Laterzzz,
Onoitsu2 | Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #4 on Sat 26 Aug 2006 11:47 PM (UTC) |
Message
| Ah, Perl. :)
I see what you mean, I tried that and it did it to me too. Had to go fish out my Perl book from the bookshelf. It seems that (unlike Lua) Perl has different comparison operators for strings to numbers. You need to use "eq" and not "==". This test works:
$summon1 = "rat";
$summon2 = "rat";
if( $summon1 eq $summon2 )
{
$summon2 = "$summon2 2";
}
$world->Note ("summon1 is $summon1");
$world->Note ("summon2 is $summon2");
If you change summon2 to be something other than rat, it does not get a "2" at the end.
You want to be a bit careful too, in not confusing MUSHclient variables with Perl variables. For example, you had:
$world->setvariable("summon2", "$summon2 2");
Now after this the MUSHclient variable "summon2" has changed, but not the Perl variable $summon2. For simplicity in my example, I just changed the Perl variable. |
- 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.
15,699 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top