Halting script WITHOUT haltdef

Posted by: Protopia

Halting script WITHOUT haltdef - 08/08/18 03:13 PM

Is there a way to halt script processing of an event without also doing a /haltdef?

If I use the "^" prefix on an event, then I can /haltdef to prevent mIRC displaying the event, or I can /halt to both /haltdef and stop the script running further, but AFAIK there is no way stop the script processing further without doing a /haltdef.

Does anyone know a way to halt the scirpt from running further without /haltdef the message?
Posted by: westor

Re: Halting script WITHOUT haltdef - 08/08/18 03:33 PM

Give us an code example to understand your problem to help you further..
Posted by: maroon

Re: Halting script WITHOUT haltdef - 08/08/18 04:37 PM

If "stop the script running further" means you want to stop it from running YOUR event-handler code but not hiding the event's messages, you can do it the same way you can stop any other alias you make:

1. return
2. returnex
3. GOTO label_at_last_line_of_your_event_handler
4. Call My_alias without a parameter, but my_alias contains $$1
5. //echo -a $sha1 | echo -a invalid syntax stops your script
etc.
Posted by: Wims

Re: Halting script WITHOUT haltdef - 08/08/18 05:22 PM

In an event like:

on *:text:*:#:{
/myalias
}

Inside the alias 'myalias', there is no way to halt the whole script engine without stopping default processing for that event.
The only good way is to make all your alias /return as mentioned, and finally one /return from the event itself
Posted by: Protopia

Re: Halting script WITHOUT haltdef - 08/08/18 05:25 PM

1. Return or returnex only work if called from the basic event handler - if called from several nested aliases below it doesn't work.

2. Goto presumably only works inside an alias - so doesn't actually halt processing.

3. Calling an alias which requires a parameter I will try.

4. Invalid syntax stops the script but produces an error message.

The use case is a very large script which is structured as many small aliases which each do simply things - and to halt all script processing for an event which might need to be /haltdef but not on this occasion (and so has a ^ prefix) from within an alias several nested calls deep but on this occasion without doing a /haltdef.
Posted by: Wims

Re: Halting script WITHOUT haltdef - 08/08/18 05:39 PM

3. won't work because it's calling /halt basically
Posted by: Protopia

Re: Halting script WITHOUT haltdef - 08/08/18 06:10 PM

At the moment the code looks a bit like this (grossly simplified - the real script is 100x as complicated):
Code:
on ^*:Text:*:#:*: {
  alias1 $1-
  halt
}

And what I want to do in the nested alias is to stop processing but not using /halt and avoiding /haltdef, so that the halt at the higher level is not processed.

(I should add that I have fixed my current code with something that looks like this - so this is now theoretical:
Code:
on ^*:Text:*:#:*: {
  if ($notify($nick)) return
  alias1 $1-
  halt
}

But it might be nice to have a /stop which does the same as /halt but without the implied /haltdef.)
Posted by: Wims

Re: Halting script WITHOUT haltdef - 08/08/18 06:27 PM

Yeah, you need to return to the event and return from there:
Code:
on ^*:Text:*:#:*: {
  if ($notify($nick)) return
  alias1 $1-
  if (%shouldreturn) return
  halt
}

alias1 {
eventual code..
if (shouldreturn) { set -u %shouldreturn | return }
eventual code..
}
Instead of a /stop command, maybe /halt could be improved with a switch so that /haltdef is not executed when /halt is used
Posted by: jaytea

Re: Halting script WITHOUT haltdef - 09/08/18 07:08 AM

Originally Posted By: Protopia

4. Invalid syntax stops the script but produces an error message.


there shouldn't be any invalid syntax. this is a fine solution that totally works. here's a related form:

Code:
on ^*:text:*:*:{
  myalias

  ; this doesn't execute
}

alias myalias {

  $$null
  
  ; this doesn't execute either
}


essentially /halt without the /haltdef component.

it should go without saying that you can also use "$$null" inside the event itself, or indeed anywhere else, to the same effect.
Posted by: Protopia

Re: Halting script WITHOUT haltdef - 09/08/18 09:10 AM

So tweaking this as follows effectively gives us a stop command?
Code:
alias stop { $$null }
Posted by: Raccoon

Re: Halting script WITHOUT haltdef - 11/08/18 08:55 AM

Aye. I had come up with /noop $$! on the second post down, but any line containing $$! or $$() or $$null will work.

Good stuff to know. I consider /halt and /haltdef to be rather confusing and inconsistent, and really appreciate where the OP is coming from here. Had somebody else ask the same question in the past day, too.

Here's a question for everyone. How can I take advantage of the $halted identifier across multiple script files, if using /halt is a disaster in itself?
Posted by: Protopia

Re: Halting script WITHOUT haltdef - 11/08/18 09:32 AM

Originally Posted By: Raccoon
Here's a question for everyone. How can I take advantage of the $halted identifier across multiple script files, if using /halt is a disaster in itself?

I am not sure I would describe /halt as a "disaster".

Leaving aside potential issues of malicious scripts which use halt to hide messages and possibly replace them with something different, in my experience the only issue with /halt is ...

... that we cannot distinguish between scripts which use /halt to hide messages completely or those which /halt and then display the message themselves (e.g. in order to display the message somewhere other than mIRC's default window) ...

... and this is generally only an issue if the second script wants to hide or redirect the message too (rather than simply react or respond to it). It cannot hide a message which has been halted and then echoed, nor can it redirect the message somewhere else because it has already been echoed.

The solutions are IMO:

1. to use $halted to avoid echoing the message again or avoid echoing any message which assumes that the user has seen the original message, using code like:

Code:
if (!$halted) echo -s Stuff


2. to avoid halting and echoing the message by default (i.e. do it only when absolutely necessary) as some scripts like https://github.com/ElectronicWar/nbs-irc/issues/17 appear to do.
Posted by: Wims

Re: Halting script WITHOUT haltdef - 11/08/18 04:48 PM

When you halt an on text event in script file A, on text in others files are still triggered/checked.

@jaytea: I also didn't know that $$ wasn't calling /halt directly like that, good to know indeed.
Posted by: Protopia

Re: Halting script WITHOUT haltdef - 11/08/18 05:11 PM

Originally Posted By: Wims
When you halt an on text event in script file A, on text in others files are still triggered/checked.

Exactly!!