mIRC Home    About    Download    Register    News    Help

Print Thread
[Amateur] If / else promblem. #244525 07/03/14 03:07 PM
Joined: Mar 2014
Posts: 18
D
DvD_cD Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Mar 2014
Posts: 18
I write one code for my twitch chat bot.
Code:
on *:TEXT:!mod*:#: {
  if ($nick isop #) {
    if ($2 == giw) {
      if ($3 == start) {
        msg $chan Giveaway start!
        set %giw on
        } elseif ($3 == stop) {
        msg $chan Giveaway was closed.
        set %giw off
        }  { return } elseif ($3 == pauseon) {
        if (%giw == off) {
          msg $chan Giveaway is currently paused.
          } else {
          msg $chan Giveaway was paused.
          set %giw off
        }
      }
      { return } { return } elseif ($3 == pauseoff) {
        if (%giw == on) {
          msg $chan Giveaway is currently unpaused.
          } else {
          msg $chan Giveaway was unpaused.
          set %giw on
        }
      }
      { return } { return } else ($3 == status) {
        if (%giw == on) {
          msg $chan Giveaway status: ON
          } else (%giw == off) {
          msg $chan Giveaway status: OFF
        }
      }
    } 
  }
}


Where is the problem:

Quote:
Me: !mod giw start
Bot: Giveaway start!

Me: !mod giw stop
Bot: Giveaway was closed.

Me: !mod giw pauseon
Bot: Giveaway was closed.



And this with all:
  • !pauseon
  • !pauseoff
  • !status

Re: [Amateur] If / else promblem. [Re: DvD_cD] #244526 07/03/14 03:55 PM
Joined: Jul 2006
Posts: 3,764
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,764
See http://en.wikichip.org/wiki/Introduction_-_mIRC, specifically the part about block of code

You cannot put elseif on the same line right after the }, or you need a pipe character: '|'
The way you use { return } is also wrong


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: [Amateur] If / else promblem. [Re: Wims] #244527 07/03/14 05:22 PM
Joined: Mar 2014
Posts: 18
D
DvD_cD Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Mar 2014
Posts: 18
But if i don't use { return }, the bot says all commands like that:
Quote:
Giveaway start!
Giveaway was closed.
Giveaway is currently paused.
Giveaway was paused.


It just fires them all off.
Show me how its done.

Re: [Amateur] If / else promblem. [Re: DvD_cD] #244528 07/03/14 06:43 PM
Joined: Feb 2011
Posts: 369
K
KindOne Offline
Pan-dimensional mouse
Offline
Pan-dimensional mouse
K
Joined: Feb 2011
Posts: 369
Code:
on *:TEXT:!mod*:#: {
  if ($nick isop #) {
    if ($2 == giw) {
      if ($3 == start) {
        msg $chan Giveaway start!
        set %giw on
      } 
      elseif ($3 == stop) {
        msg $chan Giveaway was closed.
        set %giw off
      } 
      elseif ($3 == pauseon) {
        if (%giw == off) {
          msg $chan Giveaway is currently paused.
        } 
        else {
          msg $chan Giveaway was paused.
          set %giw off
        }
      }
      elseif ($3 == pauseoff) {
        if (%giw == on) {
          msg $chan Giveaway is currently unpaused. 
        } 
        else {
          msg $chan Giveaway was unpaused.
          set %giw on
        }
      }
      elseif  ($3 == status) {
        if (%giw == on) { msg $chan Giveaway status: ON } 
        elseif (%giw == off) { msg $chan Giveaway status: OFF }
      }
    }
  }
}


Skimmed though and kinda fixed it. I didn't want to mess with your `return` attempts, so I just removed it for my own sanity.


<@KindOne> !mod giw start
<bot> Giveaway start!
<@KindOne> !mod giw stop
<bot> Giveaway was closed.
<@KindOne> !mod giw status
<bot> Giveaway status: OFF
<@KindOne> !mod giw start
<bot> Giveaway start!
<@KindOne> !mod giw status
<bot> Giveaway status: ON

Start reading the wiki and run this. It will show syntax issues. http://www.msldev.com/

Re: [Amateur] If / else promblem. [Re: KindOne] #244531 07/03/14 09:27 PM
Joined: Mar 2014
Posts: 18
D
DvD_cD Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Mar 2014
Posts: 18
10x dude <3

Re: [Amateur] If / else promblem. [Re: DvD_cD] #244536 08/03/14 12:34 PM
Joined: Mar 2014
Posts: 18
D
DvD_cD Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Mar 2014
Posts: 18
New problem... frown

Quote:
on *:TEXT:!mod*:#: {
if ($nick isop #) {
if ($2 == giw) {
if ($3 == start) {
msg $chan The giveaway has started!
set %giw on
}
elseif ($3 == clear) {
msg $chan Nobody is in the giveaway now.
set %giw off
/white -c giw.ini
}
elseif ($3 == pause) {
if (%giw == off) {
msg $chan Giveaway is currently paused.
}
else {
msg $chan Giveaway was paused.
set %giwpause off
}
}
elseif ($3 == unpause) {
if (%giw == on) {
msg $chan Giveaway is currently unpaused.
}
else {
msg $chan Giveaway was unpaused.
set %giwpause on
}
}
else ($3 == status) {
if (%giw == on) { msg $chan Giveaway status: ON }
elseif (%giw == off) { msg $chan Giveaway status: OFF }
}
}
elseif ($2 == cmd) {
if ($3 == giw) {
msg $chan start, clear, pause, unpause, status
}
elseif ($3 == bug) {
msg $chan show, clear
}
}
elseif ($2 == lottery) {
if ($3 == start) {
msg $chan The lottery has started! Type <!enter lotter> to join. Cost 25 points, and you can get $4 points!
}
}
elseif ($2 == bug) {
if ($3 == show){
msg $chan $read(bugreport.txt)
}
elseif ($3 == clear) {
/white -c bugreport.txt
msg $chan Bug reports was cleared.
/write bugreport.txt No bug reports.
}
}
}
else {
msg $chan You must to be mod to use this command.
}
}



Now everyting without !mod giw (!mod cmd/bug/lottery) dont work :(( I can't understand why ;?

Re: [Amateur] If / else promblem. [Re: DvD_cD] #244537 08/03/14 01:03 PM
Joined: Feb 2011
Posts: 369
K
KindOne Offline
Pan-dimensional mouse
Offline
Pan-dimensional mouse
K
Joined: Feb 2011
Posts: 369
Just quickly looked it it.. well, used mSLDev

Open the script in mSLDev. It will make this EXTREMELY easy to fix.

You will see issues at lines 31 and 50.

Line 31 is suppose to be `elseif` not `else`.

Line 50 is kinda self explanatory.

`/white` what? Typo...


http://www.msldev.com
http://en.wikichip.org/wiki/MIRC


irc.swiftirc.net #msl (mIRC Scripting Language)
Re: [Amateur] If / else promblem. [Re: KindOne] #244538 08/03/14 03:09 PM
Joined: Mar 2014
Posts: 18
D
DvD_cD Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Mar 2014
Posts: 18
This mSLDev realy help a lot o.o
Btw, how to make symbol for noting?
I mean:
if ($2 == "noting")

Like:
on *:TEXT:!test*:#: {
if ($2 == 1)
msg $chan Number is $2
}
elseif (2$ == "noting") {
smg $chan Invalid command. !test <number> is right.
}

Re: [Amateur] If / else promblem. [Re: DvD_cD] #244539 08/03/14 03:12 PM
Joined: Jan 2004
Posts: 1,319
L
Loki12583 Online
Hoopy frood
Online
Hoopy frood
L
Joined: Jan 2004
Posts: 1,319
$null

Re: [Amateur] If / else promblem. [Re: Loki12583] #244541 08/03/14 03:45 PM
Joined: Mar 2014
Posts: 18
D
DvD_cD Offline OP
Pikka bird
OP Offline
Pikka bird
D
Joined: Mar 2014
Posts: 18
Originally Posted By: Loki12583
$null




Ok tanks, and what is the opposite of this?
If i use only this:
Quote:
on *:TEXT:!bugreport*:#: {
if ($2 == $null) {
msg $chan Type <!bugreport info> for more information.
}
elseif ($2 == info) {
msg $chan If you found a bug, you can report it with this command: !bugreport <something>
}
/write -il1 bugreport.txt $2-
msg $chan The bug report was sended! 60 second delay for next report.
}


and somebody type only <!bugreport>, bot says this:
Quote:
Bot: Type <!bugreport info> for more information.
Bot: The bug report was sended! 60 second delay for next report.

Last edited by DvD_cD; 08/03/14 03:46 PM.