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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
coloradoderek
Beginner


Joined: 07 Jan 2014
Posts: 18

PostPosted: Wed Apr 02, 2014 5:42 pm   

Code half skipping on first match?
 
Good Morning! I have a strange problem that I can't resolve. My code only "half works" on the first line it matches, then it works fine until it comes to another page break, then it "half works" again on the first line, and so on and so forth.

What i'm trying to do is read and make decisions based on a Shop's inventory list.
The shop's list looks like this:
Code:

  1. Potion               50  A creamy potion of flight
  2. Potion               45  A milky potion of see invisible
  3. Scroll              100  A glowing scroll of recall
  4. Scroll               25  A scroll of recall
  5. Potion               25  An empty potion bottle
  6. Scroll               25  A blank scroll
  7. Scroll              250  A scroll of legend lore
  8. Potion               50  A potion of knowledge
  9. Scroll               50  A scroll of identify


My Trigger Pattern looks like this: ^%s(%d)~.%s*%s(%d)%s(*)$
The code:
Code:

#IF (%3) {tempitem = %lower(%3);tempitem = %trimright(@tempitem)}
#SHOW @tempitem
#SQLDB Arctic.db
tsql = "SELECT * FROM lores WHERE realname LIKE "
tsql = %concat(@tsql,"'",@tempitem,"'")
row = %sql(Arctic ,@tsql)
#SHOW @tsql
tsql = ""


Here is what my output does:
Code:

  1. Potion               50  A creamy potion of flight
a creamy potion of flight
  2. Potion               45  A milky potion of see invisible
a milky potion of see invisible
SELECT * FROM lores WHERE realname LIKE 'a milky potion of see invisible'
SELECT * FROM lores WHERE realname LIKE 'a milky potion of see invisible'
  3. Scroll              100  A glowing scroll of recall
a glowing scroll of recall
SELECT * FROM lores WHERE realname LIKE 'a glowing scroll of recall'
  4. Scroll               25  A scroll of recall
a scroll of recall
SELECT * FROM lores WHERE realname LIKE 'a scroll of recall'
  5. Potion               25  An empty potion bottle
an empty potion bottle
SELECT * FROM lores WHERE realname LIKE 'an empty potion bottle'
  6. Scroll               25  A blank scroll
a blank scroll
SELECT * FROM lores WHERE realname LIKE 'a blank scroll'
  7. Scroll              250  A scroll of legend lore
a scroll of legend lore
SELECT * FROM lores WHERE realname LIKE 'a scroll of legend lore'
  8. Potion               50  A potion of knowledge
a potion of knowledge
SELECT * FROM lores WHERE realname LIKE 'a potion of knowledge'
  9. Scroll               50  A scroll of identify
a scroll of identify
SELECT * FROM lores WHERE realname LIKE 'a scroll of identify'


Do you notice how it "half works" on the first match (a creamy potion of flight)??
Then it puts the SQL statement in with the 2nd match, but the variables have now changed so it does the 2nd match twice, and the first match never.
This happens on the first match when you initially type "list" to see the list of items for sale, and then again if the list is large enough that it goes to a 2nd page.

I have tried unchecking/checking all the boxes at the bottom like "trigger on newline" "trigger on trigger" etc, and the only way the code works this way is if I have those 2 mentioned checked and nothing else checked. If I uncheck either of those, it doesn't work at all.

Any idea's how to make the code work for the first match 100% and then also for the 2nd match? once it gets past the first and 2nd matches, it works flawlessly, until page 2, when it does the same thing, first match and 2nd match screw up, but the rest work.

Thanks for any help.
This is really frustrating as there is no way I can do what I want to do, if the code only half works on the first match.

Derek Conlon
Reply with quote
hogarius
Adept


Joined: 29 Jan 2003
Posts: 221
Location: islands.genesismuds.org

PostPosted: Wed Apr 02, 2014 6:56 pm   
 
It sounds like the script is racing ahead before the capture values are completely captured and processed in the first line. If %3 hasn't been populated yet when the first #IF command is processed, the #IF command ain't gonna work.

Maybe, before that #IF statement, add an empty #LOOP statement?

Code:

#LOOP 1000 {}


(edited)
Reply with quote
hadar
Apprentice


Joined: 30 Aug 2009
Posts: 198
Location: my apt, in california

PostPosted: Wed Apr 02, 2014 8:10 pm   
 
try threading it throw a
Code:

#wait 0
at the top of the trigger and see if that helps
_________________
if you build it they will come, assuming that they have not already come to build it
Aardwolf Bootcamp
My youtube channel
Reply with quote
coloradoderek
Beginner


Joined: 07 Jan 2014
Posts: 18

PostPosted: Wed Apr 02, 2014 8:11 pm   
 
Thank you for your reply.
After some testing, I do not think your description of the problem is accurate.

What is happening is, the 2nd matching line is being evaluated in the *middle* of the first matching line.
I have changed my code some to better show what is happening and also what I did to prove it:

Trigger Pattern: <same as original post>
Code:

#LOOP 3 {#SHOW test}


With "Trigger on Trigger" checked, the output is like this:
Code:

  1. Potion               50  A creamy potion of flight
test
  2. Potion               45  A milky potion of see invisible
test
test
test
test
test
  3. Scroll              100  A glowing scroll of recall
test
test
test


With "Trigger on Trigger" Unchecked
Code:

  1. Potion               50  A creamy potion of flight
test
  2. Potion               45  A milky potion of see invisible
test
test
  3. Scroll              100  A glowing scroll of recall
test
test
test


It is clear to me, that the 2nd matching line is being evaluated before the first match's code has completely ran.

The question now is, is this a bug with my MUD's output, or a bug with CMUD's code.

Again, this happens anytime after I typed "list" the first time, and anytime I have to type "enter" to get to the next page. It only ever happens with the 1st and 2nd matches. 3+ work flawlessly.

It really seems to be a CMUD thing that is evaluating improperly when I hit "enter". (I have to press enter to send the initial "list" command also)

Thank you again for any help/insight into this issue.
Does Zugg even still check forums for bugs like this? I'd image he could tell me right away what the issue is, me or his code. (I'm betting its me, but how/why is eluding me)

Derek Conlon
Reply with quote
coloradoderek
Beginner


Joined: 07 Jan 2014
Posts: 18

PostPosted: Wed Apr 02, 2014 8:14 pm   
 
The #wait 0 suggestion also did not work.
It just made the output look even more messed up. I understand why.
Thanks for that suggestion though!!
Reply with quote
coloradoderek
Beginner


Joined: 07 Jan 2014
Posts: 18

PostPosted: Wed Apr 02, 2014 8:44 pm   
 
I used the #DEBUGFILE command and here is the resulting information:

From the .txt file: (all I did was type "list" while at a shop, yes the items have changed, I went to a shop with less items in its list, same results though)
Code:

Items for sale:

  1. Apple                 1  An apple
  2. Bread                 1  A loaf of rye bread
  3. Leg                   1  A roasted turkey leg

376H 116V 1X 41.87% 228C Exits:N> ÿù


From the .raw file:
Code:

out (    6) 04/02/14 14:38:41:207 : list<CR><LF>
in  (  241) 04/02/14 14:38:41:248 : Items for sale:<LF><CR>
  1. Apple                 1  An apple<CR><LF>
  2. Bread                 1  A loaf of rye bread<CR><LF>
  3. Leg                   1  A roasted turkey leg<CR><LF><CR><LF>
<ESC>[32m<ESC>[0;37m<ESC>[32m376H <ESC>[0;37m<ESC>[32m116V <ESC>[0;37m1X 41.87% 228C <ESC>[0;37mExits:N> <IAC><GA>


Hopefully that sheds some light on this.
Thanks,
Derek Conlon
Reply with quote
coloradoderek
Beginner


Joined: 07 Jan 2014
Posts: 18

PostPosted: Wed Apr 02, 2014 10:44 pm   
 
Good Afternoon.

I've found out that if I stop setting the %3 to a static variable, my "problem" goes away. CMUD code "remembers" that it was doing the first match and as long as I don't mess with CMUD built in variables (such as the %'s) then it works... although the code is still messed up. It executes #2 inside #1's match,then when its done with 2, finishes 1, and the moves onto 3 and works in order thereafter. it's so weird, and yet, so consistent. it does this on the first command, and every page i have to go to by hitting enter with no arguments. every time.

so now my code in the trigger looks like this:
Code:

#SQLDB Arctic.db
tsql = "SELECT * FROM lores WHERE realname LIKE "
tsql = %concat(@tsql,"'",%replace(%lower(%4),"'","''"),"'")
row = %sql(Arctic ,@tsql)
tsql = "SELECT COUNT(name) AS hm FROM lores WHERE realname LIKE "
tsql = %concat(@tsql,"'",%replace(%lower(%4),"'","''"),"'")
hm = %sql(Arctic,@tsql)
#IF (@hm.Item("hm") = 0) {#SUB (~*%1)}
#IF (@hm.Item("hm") > 1) {#SHOW TWO WERE SELECTED}
tsql = ""


Now the code still does what I want, and its not "broken" but still runs match #2 first then match #1. just doesn't matter in THIS code as the order in which I evaluate the items is irrelevant. that could easily matter though.

I guess the long story short here is, substituting real variables for %1,%2, etc breaks triggers that repeat on each line longer than once due to the 2nd match's %3 overwriting the variable stored when %1's match was matched, but code not executed. I hope i said that right.

Thanks for reading guys!
Hopefully this bug gets acknowledged, or I at least get told what i'm doing wrong :)

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