|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Sat Nov 06, 2010 11:11 pm
[3.31] DB var possible bug. |
I came across an issue the other day helping someone. I'm unsure how they were entering the key=value pairs into the db var but somehow they got a multi line entry in the key field of one of the records. This presented a problem when using the db var in the pattern of a trigger. See the code below.
Code: |
<class name="test_class" id="3">
<var name="test" type="Record" id="1">
<value>Person standing north=Person north|Person standing east=Person east|Person standing west=Person west|"Person standing south
south=Person south"</value>
<json>{"Person standing south
south":"Person south","Person standing north":"Person north","Person standing west":"Person west","Person standing east":"Person east"}</json>
</var>
<trigger priority="20" prompt="true" id="2">
<pattern>({@test})</pattern>
<value>#if (%iskey(@test,%1)) {#sub {%mxp<send '#print %db(@test,%1) - %1' '%db(@test,%1)'>%ansi(bright,blue)%1%ansi(reset)</send>}}</value>
</trigger>
<alias name="test" id="4">
<value>#show {Person standing north}</value>
</alias>
</class> |
In that example all the keys are in the format of "Person standing <direction>" except for the record showing "Person standing south"
The key is actually:
Code: |
Person standing south
south |
This multi line key causes the variable to not work in the trigger pattern for any of the other entries if they are matched.
TO TEST:
1. Open the untitled session.
2. Open the package editor.
3. Create a new class in the untitled session.
4. Click on the new class and then select the XML tab.
5. Copy the first block of code above into the XML tab of the new class you just created, overwriting anything that was already in the class.
6. Click save at the top of the package editor and close the package editor.
7. In the command line of the untitled session type test.
8. Go into the package editor and delete the row for the key Person standing south.
9. Click save at the top and close the package editor.
10. Type test on the command line again. (Notice how the trigger now fires)
Is this the intended behavior? Like I said, I have no idea how the person was entering keys to get the one causing problems to have multiple lines like that. I just found it odd, that one key would keep the whole DB from matching in a trigger pattern.
edited to fix an error that was causing the code to not display correctly. |
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34
Last edited by Fizgar on Sun Nov 07, 2010 5:12 pm; edited 1 time in total |
|
|
|
Moo Apprentice
Joined: 10 Apr 2009 Posts: 145
|
Posted: Sun Nov 07, 2010 10:05 am |
You can insert a newline into the field by pressing control-enter.
And yes, it seems to stop the trigger pattern matching for anything. But %iskey still works. |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Sun Nov 07, 2010 10:51 am |
First of all, you should be using {%%dbkeys(@test)}, not {{@test}}, since @test is not a string list.
Second, why are you using %iskey in the #IF statement? Obviously it is a key from the test variable, otherwise the trigger would not have fired.
Charneus |
|
|
|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Sun Nov 07, 2010 4:33 pm |
@Charneus:
@test is not a string list you are correct, but the help files say the following
Quote: |
@variable match any of the specified strings or keys works with string lists and record variables |
{(@test)} should work just fine.
I'm using %iskey in the #if because the statement was originally designed to have a second condition that would need to be true, I just cut the extra crap out to make testing easier.
@Moo:
You are correct, %iskey seems to handle the multiline key just fine |
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
|
Yetzederixx Beginner
Joined: 19 Oct 2010 Posts: 14 Location: Sulphur, LA
|
Posted: Sun Nov 07, 2010 4:58 pm |
Quote: |
<value>#if (%iskey(@test,%1)) {#sub {%mxp%ansi(bright,blue)%1%ansi(reset)}}</value> |
Isn't the %mxp function missing parentheses, and when I went to the help files to figure out what it does I couldn't find it in the funtion reference....but did find #mxp |
|
|
|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Sun Nov 07, 2010 5:31 pm |
My use of %mxp may not exactly be correct but it usually gets what I want done. That's the great thing about scripting there is generally more than one way to accomplish the same task. %mxp is actually a predefined variable within CMUD, and is referenced in the predefined variable help file. In my usage above if you enclosed what follows %mxp with parentheses, they would be shown in the substitution which is undesirable.
|
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Mon Nov 08, 2010 5:32 pm |
The problem, I believe, is that #mxp and %mxp don't work across multiple lines. If the text being sent to the mxp command includes a line break, it will interpret MXP codes only up to the line break. I came across exactly this same situation yesterday. I don't know whether it should be considered a bug, but it could be.
My solution was to make the variable into a stringlist, breaking it into items instead of inserting %crlf, then loop through the stringlist executing #mxp on each item. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Nov 08, 2010 6:08 pm |
Multiline keys are not going to work. CMUD uses JSON for the internal data representation of string lists and tables and control characters in the key values is not supported by JSON. Keys must be normal strings...no control characters such as linebreaks.
|
|
|
|
Fizgar Magician
Joined: 07 Feb 2002 Posts: 333 Location: Central Virginia
|
Posted: Mon Nov 08, 2010 8:29 pm |
My question was not so much one of how to deal with the multiline keys, but rather just because there was a multiline key in the variable should that stop the trigger from firing for any other keys that were not multiline. In other words, if your variable gets screwed up would it be possible for CMUD to just skip over the key if it had control characters in it?
|
|
_________________ Windows Vista Home Premium SP2 32-bit
AMD Athlon Dual Core 4400+ 2.31 GHz
3 GB RAM
CMUD 3.34 |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Nov 08, 2010 9:01 pm |
Perhaps. I can look into that, although it might also cause users to wonder why a trigger works with certain keys and not others.
|
|
|
|
|
|