mIRC Home    About    Download    Register    News    Help

Print Thread
if and while statements +additonal question #229772 17/02/11 05:29 AM
Joined: Sep 2010
Posts: 6
N
NXwolf Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
N
Joined: Sep 2010
Posts: 6
I can program in C++ just fine with if and while statments, but for some reason I can't get my code to work using MIRC.

Quote:
on *:TEXT:*!check*:#Wolfscripts:
{
if (NXwolf isin $nick) && (!check isin $1)
{
while ($1 == wolf)
{
if (NXwolf isin $2)
{ { /msg #Wolfscripts test complete } }
}
}
}


The above code isn't even close to what I have planned, but if I can't get the above to work, then I won't get anywhere. The basics of this program is to be constantly reading a channel for for the command !check. Once that command is used, the program will then cycle though the next couple of lines so long as wolf is in $1. It then goes down to check what is in $2. Provided both rn correctly, it will msg a test complete.

While in IRC, I've done the following for the command.

(I typed) !check
(bot types) wolf NXwolf

Check should have initiated the program and then the bot's line should have continued to complete the test, however, I get no error returns or anything. As if the code doesn't work/respond at all. I realize it's been a while since I last touched C++, but I just don't see what I'm doing wrong.


Ok, now my extra question is. I want to make this script run on a timer delay. The script should be able to finish on it's on with no timer, but in the event of a failure or something, I'd like a timer that will auto abort the program.

Thanks a lot for any help,
NX

Re: if and while statements +additonal question [Re: NXwolf] #229774 17/02/11 06:00 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
First, mIRC only supports { brackets on the same line as the comparison.

Wrong:
Code:

if (%var == 1)
{
...



Right:
Code:

if (%var == 1) {



Second, I can't tell by your post where your script is running... but in case you didn't know, you can't trigger your own onTEXT events from within your mIRC. If your code is in your own Remotes, you won't be able to trigger it. If that code is in your bot's mIRC, it will be ok.


Third, you can use the /timer command to delay the execution of your code. Just keep in mind that identifiers like $nick, $chan, etc that are set within an onTEXT event, are destroyed as soon as that event ends. If you want to use those identifiers in an /alias that your timer calls, you will need to save them in a variable, or pass them as arguments to the /alias.

Example:

Code:

on *:TEXT:!check:#:{
  .timer 1 4 myalias $nick $chan
}
alias myalias {
  echo -at Nick: $nick , Chan: $chan , 1: $1 , 2: $2
}



-genius_at_work

Re: if and while statements +additonal question [Re: NXwolf] #229775 17/02/11 06:00 AM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
A few things, but nothing major.
1) The positioning of brace brackets in your code is incorrect. 2) You have a condition to ensure that !check is part of $1
You also have the condition of $1 == wolf
Since $1 can only contain one value, it's impossible for both of these conditions to be true.
3) The bot can not respond to it's own output.
From /help ON TEXT
Quote:
Note: You cannot test out these events by typing text to yourself. They can only be initiated by someone else saying something in a channel or in a private message.


Thus the bot's output of wolf NXwolf is not recognized as a received message through the ON TEXT event. Even if it was received, the matchtext section of your event contains !check thus there is no match.

Most of the time, main exception being badly coded loops that end up becoming end-less, a script that fails will terminate itself with an error message, thus a timer is useless for the situation you were asking about.

If you would like to explain just what your intentions for this code are, I (or someone else) might be able to make some better suggestions as to how you can do it.

Re: if and while statements +additonal question [Re: NXwolf] #229776 17/02/11 06:39 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
What they said, but also...

With mIRC it's not suggested to use the while statement like you have it. We usually just use while for loops.

For instance:
Code:
var %x = 1
while (%x <= $chan(0)) {

inc %x
}


Also, since your text event specifies the text has !check in it, (!check isin $1) is uneccesary. It would be better to remove the 1st wildcard in the event.

on *:text:!check*:#:{

}
Remember this will only trigger if the first word is !check so the rest of your code wouldn't work. You can just make the text a wildcard, then check for $1.

Code:
on *:text:*:#:{
  if ($1 = !check) { ;commands }
  elseif ($1 = wolf) {
    if ($2 = NXwolf) msg # test complete

    }
}


Also,

{ { /msg #Wolfscripts test complete } }

There is no need for the double brackets. smile

In the event of a failure:

You can say:

if (this = $true) do this
elseif (this = $true) do this
else { ;planned for error }

Also, you can utilize :error. This would be at the end of the code block.

:error {
echo -s Error: $error
reseterror
}

Originally Posted By: mIRC help file
Error handling

Script errors can be caught by adding an :error goto point to your script. When an error occurs, the script will jump to :error and continue running. $error returns the error message.

You can reset the error with /reseterror. If you don't reset the error, it will propagate backwards to any calling aliases until an :error is found and will halt the script as usual.

Re: if and while statements +additonal question [Re: genius_at_work] #229778 17/02/11 07:52 AM
Joined: Sep 2005
Posts: 2,876
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,876
In this case using $nick and $chan would be fine because they're evaluated at the time the /timer command is issued and not when the timer is fired. There would only be a problem if you used $!nick and $!chan.

Re: if and while statements +additonal question [Re: genius_at_work] #229788 17/02/11 02:03 PM
Joined: Jul 2006
Posts: 3,530
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,530
In addition to hixxy's post and I know you know it, using # as the location, it could be exploited with $chan and the double evaluation of timer, the safe alias should be used


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: if and while statements +additonal question [Re: RusselB] #229803 17/02/11 06:00 PM
Joined: Sep 2010
Posts: 6
N
NXwolf Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
N
Joined: Sep 2010
Posts: 6
Let me explain more on what this is suppose to do then. This script is for use along side a gaming server bot. I want to create a script that when the command !check, is used. The bot will perform a !pl (player listing) command. The !pl command then displays aa list of the players on each team. Now, back to my script. The script will then read all the player names that the !pl command sent to the administration channel. If a certain player name is found, I want the bot to perform a check on them using a !pi (player info) command. The bot will then log the player info displayed and write it all to a file at which point me or any other admin will review latter when we get the chance. Should no player name be found that we are looking for, then the script will just terminate itself and be done.

In short, the script needs to be able to read multiple lines of text that IRC is streaming over. Below is an example run of how I want the script to work. (Please note, I hand typed this all, this isn't code ran, just for display view)

<NXwolf> !check
<MYbot> !pl
<ServerBot> Allies: Radion GENERICO [SG]OHD APB-FR-Ga3L Talon
<ServerBot> Soviets: cgf123 DracoTrooper kromb exia Beta
<MyBot> Found 1 player on watch list. Performing Search.
<Mybot> !pi Beta
<ServerBot> Id Name Score Side Ping Address Kb/s Time
<ServerBot> 11 Beta 0 Sov 223 ***.***.***.*** 0 000.00.02
<Mybot> Info logged and notice sent to admins.

The above stuff that the ServerBot returns look much nicer in IRC, but only so much I can do on spacing and all with forums, but it should give you a basic idea on what is going on. At the end, the script will terminate itself. The script will know what theplayer listing command is done because of the allies and soviet tags on each line that follow the !pl command.

Hope that explains more on what I'm trying to do.

Re: if and while statements +additonal question [Re: NXwolf] #229809 17/02/11 07:12 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
That all looks pretty straightforward to script. Here's a basic idea of how it could look.

Code:
on *:text:*:#: {
  ; If you need to check the $nick, you can do so here and stick everything
  ; that follows inside that IF's brackets.  Otherwise, if the command can
  ; be used by everyone, then don't bother including the $nick check from your original code.
  if ($1 == !check) { msg $chan !pl }
  elseif ($nick == ServerBot && (Allies: == $1 || Soviets: == $1)) {
    ; Perform whatever check you need to determine if there are matches.
    ; You didn't explain how that was decided, so just put that code here.
    ; Set it to %pl.match in the format of name1 name2 name3
    if (%pl.match) {
      var %t = $numtok(%pl.match,32)
      msg $chan Found %t player $+ $iif(%t > 1,s) on watch list.  Performing Search.
      ; Note that here, depending on how you need to format the name(s) for !pi,
      ; you may have to loop through using $gettok() to run the command on every match.
      msg $chan !pi %pl.match
    }
  }
  elseif ($nick == ServerBot && ($4 == Sov || $4 == All)) {
    ; You may need to adjust the IF to a better method of determining that the text is your data.
    ; You will also need to add in whatever code you need for the script to log and notice admins.
    msg $chan Info logged and notice sent to admins.
  }
}


Invision Support
#Invision on irc.irchighway.net