mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2004
Posts: 148
D
Vogon poet
OP Offline
Vogon poet
D
Joined: Nov 2004
Posts: 148
I'm having problems understanding why it fails (Logically).

Lets assume that sound.mp3 exists.


Code:
alias err {
  if ($1 == 1) {
    if ($exists("sound.mp3") == $true) {
      splay -q "sound.mp3"
      :error
    }
     goto end
  }
  if ($2 == 1) {
    if ($exists("sound.mp3") == $true) {
      splay -q "sound.mp3"
      :error
    }
  }
  :end
}

  



If I write: /err 1 then I get /goto: duplicate 'error' found


If I remove the " goto end" then it doesn't fail. My question is WHY??? I see no logic in this. confused confused

Joined: Dec 2003
Posts: 261
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Dec 2003
Posts: 261
The problem is that you used :error twise. I don't see why do you need that goto point, you are not even using it.


velicha dusha moja Gospoda
Joined: Dec 2003
Posts: 261
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Dec 2003
Posts: 261
And it fails becouse, when you use goto then the script is looking for goto points (:error and :end in your case) in every if statement and you have two of :error. If you don't use goto, then only one :error point is seen, becouse the second if statement is not looked, becouse it is not true.


velicha dusha moja Gospoda
Joined: Nov 2004
Posts: 148
D
Vogon poet
OP Offline
Vogon poet
D
Joined: Nov 2004
Posts: 148
I can also use /err 0 1 and then the second if happens!

Quote:
The problem is that you used :error twise


Well, what do you suggest? confused Sometimes when playing sounds, windows has problems playing it and then it causes error in mIRC.
This causes the script to halt!!! And since I don't want the script to halt then I use :error
Since I want it to continue just after the play command then I need to put :error after each "/splay" command.




If I remove the "goto end" and write: /err 1 1 then it should play the sound.mp3 twice... and since both statements are true and it fails.
How can I prevent the script from halting on error with this case (When it can't play the mp3 file and it has to play it twince in 2 different places in the alias) ??
How do I prevent it from

Joined: Dec 2004
Posts: 66
B
Babel fish
Offline
Babel fish
B
Joined: Dec 2004
Posts: 66
I use goto sometimes but it’s usually cleaner to script without them.
Code:
 
alias err {
  if ($1 == 1) {
    if ($exists("sound.mp3") == $true) splay -q "sound.mp3"
  }
  elseif ($2 == 1) {
    if ($exists("sound.mp3") == $true) splay -q "sound.mp3"
  }
}


Hmm, you are already testing for if the sound file exists, I haven’t had mirc error on a sound file if it’s found, try this:
Code:
 
alias err {
  if ($1 == 1) {
    if ($exists("sound.mp3") == $true) splay -q "sound.mp3"
  }
  elseif ($2 == 1) {
    if ($exists("sound.mp3") == $true) splay -q "sound.mp3"
  }
  :error
}


Since both use the same found file you can write it this way:
Code:
 
alias err {
  if (($1 == 1) || ($2 == 1)) {
    if ($exists("sound.mp3") == $true) splay -q "sound.mp3"
    else echo -s "sound.mp3" not found in alias err
  }
  :error
}

Joined: Jan 2006
Posts: 468
Fjord artisan
Offline
Fjord artisan
Joined: Jan 2006
Posts: 468
Hi there,
Use this code.
Code:
alias err {
  if ($1 == 1) {
    if $exists($qt(sound.mp3)) {
      splay -q $qt(sound.mp3)
    }
    else { echo -a Error }
  }
  elseif ($1 == 2) {
    if $exists($qt(sound.mp3)) {
      splay -q $qt(sound.mp3)
    }
    else { echo -a Error }
  }
}


PS: if $2 == 1 will not be supported like this, you need to use if ($1) && ($2) then if ($2 == <value>) etc.. but this code I posted for you shall work.

Joined: Dec 2004
Posts: 66
B
Babel fish
Offline
Babel fish
B
Joined: Dec 2004
Posts: 66
My understanding is that an alias should have at most one :error, it doesn’t have to be right after the command that might cause the error, an error that happens anywhere in the alias will jump to the :error.
Code:
alias err {
  if ($1 == 1) {
    splay -q "sound.mp3"
  }
  elseif ($2 == 1) {
    splay -q "sound.mp3"
  }
  goto end
  :error
  echo -s Error in alias err: $error
  reseterror
  :end
}


The reseterror might not be needed, simply having the :error in the alias might take care of it.

Joined: Nov 2004
Posts: 148
D
Vogon poet
OP Offline
Vogon poet
D
Joined: Nov 2004
Posts: 148
Well, for your information playing the sound may also fail because of codecs problems.

Bad codecs or something that prevents the sound from being played can cause an error even if it exists. I had this problem more than once, and I had to reinstall the codecs or restart the computer to solve it.

The point is that I don't want to make the alias jump to the end if it has an error. I just want it to continue.

Well, nevermind.

Thanks

Joined: Feb 2005
Posts: 681
M
Fjord artisan
Offline
Fjord artisan
M
Joined: Feb 2005
Posts: 681
If you don't want the script to halt if there is an
error playing the sound file, use a timer..

.timer 1 0 splay -q "sound.mp3"

Joined: Nov 2004
Posts: 148
D
Vogon poet
OP Offline
Vogon poet
D
Joined: Nov 2004
Posts: 148
Yeah I though of that. Either having a timer or calling another alias that will play the sound and will have a :error

Thanks for the idea, I didn't think of using a timer smirk


Link Copied to Clipboard