|
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: Sun Dec 05, 2010 1:24 pm
Cmud Error when using #read function. |
happens very rarely on this one trigger i have that reads files for other people.
Closed D:\cmud\SlothmudIII\killing.txt on file 1
ERROR: Operator LT requires two arguments
ERROR: Operator binaryint requires two arguments
What can be causing this ? |
|
|
|
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: Sun Dec 05, 2010 2:11 pm |
Here's the trigger in question if anyone wants to have a read through (this works fine 99% of the time) but it has a few other related triggers that define database items which this trigger uses, so its not a complete picture:
Code: |
<trigger priority="5960" prompt="true" id="1289">
<pattern>(%w) tells you 'go on'</pattern>
<value>#if (%iskey(@rookie,%1) OR %iskey(@newbie,%1)) {
#if (%db( @{%1fake}, @{currentreading.%1})!=completed) {
#if %db(@files,@currentreading.%1)=%1 {tell %1 Dont you want to finish reading what you started?} {
#var rookiename %1
$nextfile=(%numitems(@files)+1)
#addkey files {@currentreading.%1} %1
$nextfilename={@currentreading.%1}
#file $nextfile @currentreading.%1~.txt
#math {%1.@{currentreading.%1}} %db( @{%1next}, @currentreading.%1)+1
#math {%1next.@{currentreading.%1}} %db( @{%1}, @currentreading.%1)+@{lines.%1}
#if %db( @{%1next}, @currentreading.%1)>%db( @guidelines, @currentreading.%1) {#var {%1next.@{currentreading.%1}} %db( @guidelines, @{currentreading.%1})}
#loop %db( @{%1}, @{currentreading.%1}),%db( @{%1next}, @currentreading.%1) {#READ $nextfile %i;#wait @{readingspeed.%1}}
#close $nextfile
#delkey files $nextfilename
#if (%db( @{%1next}, @{currentreading.%1})>=%db( @guidelines, @{currentreading.%1})) {
#if %iskey(@rookie,%1) {tell %1 You are finished with this guide;#var {%1next.@{currentreading.%1}} %db( @guidelines, @{currentreading.%1})}
#if (%iskey(@newbie,%1) AND @currentreading.%1=basics) {tell %1 Type: newbie hello, and i will continue our lesson}
#if (%iskey(@newbie,%1) AND @currentreading.%1=basics2) {tell %1 You are finished with your basic training, but there is still alot to learn, tell anrok progress to see more topics.;#delkey newbie %1;#addkey rookie %1 0}} {tell %1 Tell anrok ~"go on~" to continue. Your progress is: %db( @{%1next}, @{currentreading.%1})/%db( @guidelines, @{currentreading.%1})}}} {
#if (%iskey(@newbie,%1) AND @currentreading.%1=basics) {tell %1 You need to type newbie hello, to continue with our lesson.} {tell %1 You have finished reading everything from this @currentreading.%1 guide, tell anrok progress to see what is left.}
#var {%1.@{currentreading.%1}} %db( @guidelines, @{currentreading.%1})
#var {%1next.@{currentreading.%1}} %db( @guidelines, @{currentreading.%1})
}} {tell %1 I'm sorry %1, but you are not eligible to read my guides}</value>
</trigger> |
|
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Mon Dec 06, 2010 12:55 am |
If it works 99% of the time, I'm inclined to say it has to do with the contents of the file. If the file is always the same then post the file and other folks can test it.
I also put you code in code tags for legibility.
Also if CMUD generates an error report, post that as well. |
|
_________________ Asati di tempari! |
|
|
|
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: Mon Dec 06, 2010 1:35 am |
The file is basic text
Maybe there's something odd in the code that someone might be able to see that im missing ? |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Mon Dec 06, 2010 1:40 pm |
You didn't say whether the contents of the file are always the same, nor did you show us the contents of the file. That is still the most likely cause.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Dec 06, 2010 5:25 pm |
The #READ command executes each line in the file as a script (as if it was typed in the command line). So it sounds like you have a < character in the file somewhere. You can try surrounding the line in the file with the < character in " quotes to see if that helps.
|
|
|
|
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: Mon Dec 06, 2010 7:55 pm |
Nope there are like 15 different files that this script reads upon request, but the last crash happend on killing.txt and i've looked through it and used the search function and it didnt find any script signs like < or > or = or () {}.. Dont really want to post the text file as its 50 lines long. Im inclined to think that i've made a mistake somwhere in the trigger code but i cant for the life of me find what it is.
|
|
|
|
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: Thu Dec 09, 2010 12:23 pm |
I found what the problem was, maybe that will be of some help to someone :
First problem was the ugly #math functions here:
Code: |
#math {%1.@{currentreading.%1}} %db( @{%1next}, @currentreading.%1)+1
#math {%1next.@{currentreading.%1}} %db( @{%1}, @currentreading.%1)+@{lines.%1} |
Changed to :
Code: |
#addkey %1 {@currentreading.%1} (%db( @{%1next}, @currentreading.%1)+1);
#addkey %1next {@currentreading.%1} (%db( @{%1}, @currentreading.%1)+@lines.%1)} |
Second problem was CMUD's multi-threading. Whereas ZMUD would wait for the first #IF sets to finish before stepping onto the next #IF set (which used the same global variable as first #IF set changed) CMUD did not wait and simply went on to execute the next #IF set while first #if set was still in the process of changing the global variable for that set! which caused all sorts of weird problems. This was fixed using #section function to give order to CMUD's multi-threaded pattern.
So the proper script looks like this :
Code: |
#section reading {#addkey %1 {@currentreading.%1} (%db( @%1next, @currentreading.%1)+1);
#addkey %1next {@currentreading.%1} (%db( @%1, @currentreading.%1)+@lines.%1)}
#section reading {
#if %db( @{%1next}, @currentreading.%1)>%db( @guidelines, @currentreading.%1) {#var {%1next.@{currentreading.%1}} %db( @guidelines, @{currentreading.%1})}
#loop %db( @{%1}, @{currentreading.%1}),%db( @{%1next}, @currentreading.%1) {#READ $nextfile %i;#wait @{readingspeed.%1}}
#close $nextfile
#delkey files $nextfilename}
#section reading {
#if (%db( @{%1next}, @{currentreading.%1})>=%db( @guidelines, @{currentreading.%1})) {
#if %iskey(@rookie,%1) {tell %1 You are finished with this guide;#var {%1next.@{currentreading.%1}} %db( @guidelines, @{currentreading.%1})}} |
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Dec 09, 2010 5:57 pm |
Quote: |
CMUD did not wait and simply went on to execute the next #IF set while first #if set was still in the process of changing the global variable for that set! |
Huh?? CMUD threading doesn't work like that at all. Within a single script, CMUD executes each statement in order and waits for each statement to complete before going to the next statement.
The only reason your #section would work is if you have *multiple* copies of this script running at the same time. And you can't even get that without using #WAIT commands since even triggers wait till they are complete before running the next trigger on the line.
Now, I suppose it is possible that this behavior is somehow changed when reading a file with #READ. |
|
|
|
Anrok Apprentice
Joined: 19 Nov 2010 Posts: 119
|
Posted: Thu Dec 09, 2010 8:34 pm |
How does threading work in #loops with a #wait command between each line ? Is it going to execute all the looped #waits before switching to next statement ? I have a feeling that the culprit was this here
Code: |
#loop %db( @{%1}, @{currentreading.%1}),%db( @{%1next}, @currentreading.%1) {#READ $nextfile %i;#wait @{readingspeed.%1} |
As the next statements after it were not being evaluated properly and causing all sorts of trouble, after sectioning them it works absolutely perfect and smooth. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Dec 09, 2010 9:34 pm |
As soon as you use #WAIT, your current script thread goes into the background and CMUD starts processing the next trigger for the line and processes additional lines.
Anything in the script that contains the #wait statement should still wait until the loop is completed. But what is happening here is that after the #WAIT puts the script into the background, the next line from the file is read, and any triggers that match that line will be fired. If any of those triggers access the same variables used in the script with the #WAIT in it, then you definitely need the #section command to protect them.
So I think the issue wasn't that CMUD was executing the lines after your #loop, the issue is that you are causing multiple copies of the same trigger to be running simultaneously and #section was needed to ensure that only one trigger was accessing the data at the same time.
You can use the #THREAD command to display a list of all running threads to see how many simultaneous triggers you might have running. |
|
|
|
|
|
|
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
|
|