mIRC Home    About    Download    Register    News    Help

Topic Options
#231895 - 09/05/11 03:55 PM If statement bracket error
Omikron Offline
Bowl of petunias

Registered: 09/05/11
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?


Edited by Omikron (09/05/11 03:57 PM)

Top
#231896 - 09/05/11 04:45 PM Re: If statement bracket error [Re: Omikron]
5618 Offline
Hoopy frood

Registered: 18/06/07
Posts: 933
Put spaces between your ) and {

Top
#231897 - 09/05/11 04:50 PM Re: If statement bracket error [Re: Omikron]
DJ_Sol Offline
Hoopy frood

Registered: 04/01/07
Posts: 1156
Loc: Seattle
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".

Top
#231898 - 09/05/11 05:25 PM Re: If statement bracket error [Re: DJ_Sol]
Omikron Offline
Bowl of petunias

Registered: 09/05/11
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

Top
#231902 - 09/05/11 06:56 PM Re: If statement bracket error [Re: Omikron]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
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

Top