mIRC Home    About    Download    Register    News    Help

Print Thread
If statement bracket error #231895 09/05/11 02:55 PM
Joined: May 2011
Posts: 2
O
Omikron Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
O
Joined: May 2011
Posts: 2
I have seen a tutorial on mIRC scripting and I've made a test command:
Code:
on *:TEXT:*:#script-test:{
  if ($me isop $chan){
    if ($1 == !test){ msg $chan A test, you say? }
}


But when I click check brackets it says there seems to be a bracket mis-match pointing to the last curly bracket and auto-indents it to look a bit strange:
Code:
on *:TEXT:*:#script-test:{
  if ($me isop $chan){
if ($1 == !test){ msg $chan A test, you say? }
}

I think this is because the if command doesn't work. It works if I do it like this:
Code:
on *:TEXT:!test:#script-test:msg $chan A test, you say?

But I want to do it the other way. Can anyone tell me what I did wrong?

Last edited by Omikron; 09/05/11 02:57 PM.
Re: If statement bracket error [Re: Omikron] #231896 09/05/11 03:45 PM
Joined: Jun 2007
Posts: 933
5
5618 Offline
Hoopy frood
Offline
Hoopy frood
5
Joined: Jun 2007
Posts: 933
Put spaces between your ) and {

Re: If statement bracket error [Re: Omikron] #231897 09/05/11 03:50 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Code:
on *:TEXT:*:#script-test:{1
  if ($me isop $chan){2
if ($1 == !test){3 msg $chan A test, you say? }3
}2


You have to count your brackets. With brackets and parentheses I count up till the last open one, then I subtract them as I count the closing brackets until I get back to 1. As you can see you are missing a bracket here. Also, as said, you need a space between () and {}.

And on a sidenote, there are prefixes that allow you to check if you are an op in the channel.

Code:
on @*:TEXT:*:#script-test:{
if ($1 == !test) { msg $chan A test, you say? }
}


The @ means "if ($me !isop #) return".

Re: If statement bracket error [Re: DJ_Sol] #231898 09/05/11 04:25 PM
Joined: May 2011
Posts: 2
O
Omikron Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
O
Joined: May 2011
Posts: 2
Oops, I missed one smile Thanks also for the op check tip. And the space between ) and { like 5618 said also prevented a bracket error, although it didn't effect the result of the code. Thanks smile

Re: If statement bracket error [Re: Omikron] #231902 09/05/11 05:56 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
You'll find that if you don't use spaces around the {}'s, it will affect the code. There may be instances where mIRC will manage to get through without the spaces and get you results, but in general, it will fail. You'll want to always use spaces around the {}'s. The one exception to that is on the EVENT line, where you can have the { touching the final : in the event as seen in the on TEXT event above. And even then, if you want to get in the habit of spaces so you never forget, you may want to just use a space there as well. That's up to you, but it does keep you from accidentally forgetting a space around another {}. Most people don't bother, but if it helps, go for it. smile


Invision Support
#Invision on irc.irchighway.net