|
diehard2k0 Beginner
Joined: 17 Aug 2008 Posts: 25
|
Posted: Wed May 15, 2013 11:21 pm
#temp and local variables |
I have a trigger, that worked perfect on 2.37, but now on 3.34 it wont work. With some modification i got it to work though, but would like to know if this is a bug or a change
Old
startroom = %db(@startrooms, $bot)
#TEMP "startroom" {$startroom} {#class {Bots|vars};#var bot $bot;#var step 1;#class 0;rampage %db( @klist, $bot);#T+ {Bots|Triggers}}
This would make a trigger with the pattern = to $startroom instead of whatever $startroom was set to through the function before it. As a workaround i just used the new feature
#tempvar sroom %db(@startroom, $bot)
#TEMP "startroom" {@sroom} {#class {Bots|vars};#var bot $bot;#var step 1;#class 0;rampage %db( @klist, $bot);#T+ {Bots|Triggers}}
This returns a trigger with the pattern = to @sroom, but it works. The original one would not work. |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Wed May 15, 2013 11:50 pm |
The reason it wouldn't work is because "startroom" is not a local variable. For local variables, the varname must always be preceded by $ regardless of which side of the assignment it was on (regular variables don't include the @ when on the left of the equals sign.) You instead created a regular variable named startroom, which you would then refer via @startroom.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
diehard2k0 Beginner
Joined: 17 Aug 2008 Posts: 25
|
Posted: Thu May 16, 2013 2:20 am |
Sorry, forgot to add the $ to that, but it was setup correctly, and worked on 2.37. But here on 3.34 it just makes a new trigger with Pattern = $startroom. I've tried it again and it still does that.
Even with a test script it still fails.
Code: |
<alias name="test" id="84">
<value>#class {TESTS}
$test = %-1
#temp {$test} {#echo Test passed}
#class 0</value>
</alias> |
when going
'test Just a test'
This will create a temp trigger
Code: |
<trigger priority="2190" temp="true" saved="false" id="219">
<pattern>$test</pattern>
<value>#echo HA</value>
</trigger> |
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Thu May 16, 2013 3:31 am |
I think it's intended, but regardless there's actually a better way. Creation and destruction is a slower activity than enabling/disabling, so you would be better off creating a normal trigger with a variable as the pattern and then changing the variable.
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4691 Location: Pensacola, FL, USA
|
Posted: Thu May 16, 2013 4:03 am |
#TEMP {$temp} {blah}
Should never fire as $temp has no referable value outside of the trigger that created. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
diehard2k0 Beginner
Joined: 17 Aug 2008 Posts: 25
|
Posted: Thu May 16, 2013 8:43 pm |
All I'm trying to get at is that the trigger worked before. Doing that would create a new trigger with whatever $startroom would be. I use that to cut down on clutter of variables and triggers since it was a trigger i only needed on occasion, but still needed. But that was back in 2.37, and i upgraded to the new one, and now most of my scripts need to be redone because a lot of them used something along those lines.
I just wanted to know if it was a bug, intentional, or if it was going to go back to how it was before. I will use the workaround of @startroom, though i need to keep a variable in there now and have lines to blank it out after it's been fired off. |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Mon May 27, 2013 3:03 am |
As Shalimar said, you can't use a local variable in a trigger pattern. It doesn't reference anything because it is out of scope and is not global.
In other words, it is not a bug. You are just misusing local variables.
Take that alias you posted. When you enter that alias it creates the following trigger:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<trigger priority="40" temp="true" saved="false" copy="yes">
<pattern>$test</pattern>
<value>#echo Test passed</value>
</trigger>
</cmud>
|
This will work though:
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<alias name="test" copy="yes">
<value>#temp {%eval(%-1)} {#echo Test passed} </value>
</alias>
</cmud>
|
|
|
|
|
|
|