DeleteLines function not working

Posted by Rollanz on Tue 21 May 2019 06:28 PM — 4 posts, 18,725 views.

#0
If I'm understanding the documentation for DeleteLines function correctly, it should work if I have a trigger call a function in my script file which calls the DeleteLines function. But it seems to be failing silently instead.

Steps to replicate:
1) Add a wrapper for DeleteLines to the script file.

GagLines = function()
  --print("deleting a line")
  DeleteLines(1)
end


2) Create a trigger that calls the wrapper (the one below matches calls the wrapper when a prompt is received).

<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^.+$"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>local count = GetLineCount()

if count==GetInfo(289) then
  GagLines()
end</send>
  </trigger>
</triggers>


Additional notes:
-I originally encountered the problem on version 5.06. To confirm this was not due to interaction with plugins/other code, I created a blank world in v5.07 pre-release with default settings other than checking the "Convert IAC EOR/GA to new line" option and the code shown above. I was playing Achaea
-Increasing the argument of DeleteLines to 2, 5, and 10 did not make a difference.

Thanks in advance.
Australia Forum Administrator #1
You aren't following the instructions in the documentation:

Quote:

Warning - do NOT call DeleteLines from a trigger, alias or timer using send-to-script. For design reasons this will not work. In version 3.76 you will cause the client to crash if you do this. In version 3.77 upwards it will silently fail (ie. do nothing).


You are using send-to-script, right? Just putting the function into a script file doesn't change the fact that you are deleting the lines from a script that starts in send-to-script.

You need to not use send-to-script and put the function name into the "Script" box of the trigger, like this:


<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^.+$"
   regexp="y"
   script="prompt"
   sequence="100"
  >
  </trigger>
</triggers>


Template:pasting
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


Now the script file should contain:


function prompt (name, line, wildcards, styles)
  local count = GetLineCount()
  
  if count==GetInfo(289) then
      DeleteLines(1)
  end
end -- prompt


The processing of scripts in this way is deferred internally in such a way that you are allowed to delete lines.

The arguments aren't used in this particular case so you could just make it:


function prompt ()
  local count = GetLineCount()
  
  if count==GetInfo(289) then
      DeleteLines(1)
  end
end -- prompt
Australia Forum Administrator #2
I admit the documentation might have been a bit ambiguous in that respect. I have amended the online documentation to make it clearer:

Template:function=DeleteLines
DeleteLines

The documentation for the DeleteLines script function is available online. It is also in the MUSHclient help file.

#3
Nick Gammon said:

You aren't following the instructions in the documentation:

Quote:

Warning - do NOT call DeleteLines from a trigger, alias or timer using send-to-script. For design reasons this will not work. In version 3.76 you will cause the client to crash if you do this. In version 3.77 upwards it will silently fail (ie. do nothing).


You are using send-to-script, right? Just putting the function into a script file doesn't change the fact that you are deleting the lines from a script that starts in send-to-script.

You need to not use send-to-script and put the function name into the "Script" box of the trigger, like this:


<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^.+$"
   regexp="y"
   script="prompt"
   sequence="100"
  >
  </trigger>
</triggers>


(pasting)

Now the script file should contain:


function prompt (name, line, wildcards, styles)
  local count = GetLineCount()
  
  if count==GetInfo(289) then
      DeleteLines(1)
  end
end -- prompt


The processing of scripts in this way is deferred internally in such a way that you are allowed to delete lines.

The arguments aren't used in this particular case so you could just make it:


function prompt ()
  local count = GetLineCount()
  
  if count==GetInfo(289) then
      DeleteLines(1)
  end
end -- prompt



Thanks for the quick reply. I didn't realize a script called in the Script box would run after the send boxes of all triggers matching that line.