mIRC Homepage
Posted By: Omikron If statement bracket error - 09/05/11 02:55 PM
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?
Posted By: 5618 Re: If statement bracket error - 09/05/11 03:45 PM
Put spaces between your ) and {
Posted By: DJ_Sol Re: If statement bracket error - 09/05/11 03:50 PM
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".
Posted By: Omikron Re: If statement bracket error - 09/05/11 04:25 PM
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
Posted By: Riamus2 Re: If statement bracket error - 09/05/11 05:56 PM
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
© mIRC Discussion Forums