|
Joined: Dec 2002
Posts: 204
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 204 |
hey y'all, i am having a little trouble with if-then-else statements ... i think. i am trying to make a script that will /splay a song, and also tell me if i have the lyrics for it. my songs are on one drive, and my lyrics on another. i have come up with something, but i cant seem to get it to tell me if the lyrics are there or not. They should be under the exact same filename that the song is in, but has a .txt extension instead of .mp3. any help you can give me would be appreciated .. oh and i marked my comments in red.
alias rhp {
[color:red] ;sets %i to a random number which it gets from a hash table [/color]
set %i $rand(0,$hget(filelist,0).item)
[color:red]; sets &hp to the actual file name[/color]
set %hp $hget(filelist,%i).data
[color:red] ; if lyrics exists do this: this is where i grab the filename of the mp3 that i want to play, and
; munge the filename to where the text file should be, (ex. g:\metalica\metalica - one.mp3
; ==> c:\lyrics\m\metallica - one.txt), and checks to see if it exists.[/color]
if ( $exists($lydr $+ $right($left(%hp,4),1) $+ \ $+ $replace($nopath(%hp),.mp3,.txt))) = $true ) {
[color:red] ; sets %ly to the text file with the lyrics[/color]
set %ly $lydr $+ $right($left(%hp,4),1) $+ \ $+ $replace($nopath(%hp),.mp3,.txt)
echo -a File $+($chr(35),%i,$chr(58)) $nopath(%hp) :: Lyrics Available
;splay %hp
}
else {
echo -a File $+($chr(35),%i,$chr(58)) $nopath(%hp) :: No Lyrics Available
;splay %hp
}
}
so far i have gotten it to return something like this File #33: Elton John - Rocket Man.mp3 :: Lyrics Available the trouble with this code is is that it ONLY returns that message even when i dont have the lyrics, i want it to return "NO LYRICS for %hp" when i do not have the lyrics ps. i commented out the splay's cause i figgured i dont need them for testing
keek: Scots - intr.v. keeked, keekĀ·ing, keeks To peek; peep.
|
|
|
|
Joined: Aug 2005
Posts: 525
Fjord artisan
|
Fjord artisan
Joined: Aug 2005
Posts: 525 |
In your if statement, you need to use the double ==. However, you actually don't need to use $true/$false here. Instead you can simply do: if ($exists(blahblah)) {
;do this
} As long as $exists(blahblah) returns something other than 0, then it makes the condition true. It will only return 0 if the file does not exist, at which point the script does not proceed any further. In an if-else, unless you specifically check for the condition to be numerically 0, then a 0 represents a false condition and anything non-0 is a true condition. Here's a simplified version. I used $iif() in place of the if-else since it's doing a simple check. It saves a line or two of code. Have a look at /help $iif to see how it works. alias rhp {
var %i = $r(0,$hget(filelist,0).item), %hp = $hget(filelist,%i), %ly = $replace(%hp,.mp3,.txt)
if ($exists($+($lydr,%hp))) {
echo -a File $+($chr(35),%i,$chr(58)) $nopath(%hp) :: $iif($exists($+($lydr,%hp)),Lyrics,No Lyrics) Available
}
}
|
|
|
|
Joined: Dec 2002
Posts: 204
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 204 |
Thank You for the quick response schaefer31, it works pretty good now after a little filename tweaking .... but i had to use set instead of var = . dont know why, but its working now thanks
keek: Scots - intr.v. keeked, keekĀ·ing, keeks To peek; peep.
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
$exists() returns either $true or $false, not numbers or anything else. Also, "and anything non-0 is a true condition." isn't actually correct. $null and $false are non-zero values, yet if ($null) and if ($false) are false conditions.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
You should change your start value in $rand() from 0 to 1. Almost all indices in mirc start from 1 and a 0 index usually means "total number of items". Note that you won't notice the problem unless $rand() happens to return 0. In this case, %hp will be set to $hget(filelist,0).data (total number of items)
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
|