#134421 - 2005-02-24 12:34 AM
A script has stopped working
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
The funny thing is, it's a script that has been working ever since I wrote it...
I get the following error:
Quote:
ERROR : undefined variable [$count]!
Script: J:\playlist.kix
Line : 30
Here's the script (with the external UDFs trimmed off):
Code:
Break on
Global $starttime
$rc = runningtime()
If Exist(@SCRIPTDIR + "\rock.m3u") = 1
DEL @SCRIPTDIR + "\rock.m3u"
EndIf
If Exist(@SCRIPTDIR + "\pop.m3u") = 1
DEL @SCRIPTDIR + "\pop.m3u"
EndIf
If Exist (@SCRIPTDIR + "\all music.m3u") = 1
DEL @SCRIPTDIR + "\all music.m3u"
EndIf
? "Generating base playlists..."
$rockarray = Dirlist(@SCRIPTDIR + "\rock\*.mp3",2+4)
$poparray = Dirlist(@SCRIPTDIR + "\pop\*.mp3",2+4)
$allmusic = JoinArray($rockarray,$poparray)
$ = WriteFile(@SCRIPTDIR + '\Rock.m3u',$rockarray)
$ = WriteFile(@SCRIPTDIR + '\Pop.m3u',$poparray)
$ = WriteFile(@SCRIPTDIR + '\All Music.m3u',$allmusic)
$rockartists = DirPlus(@SCRIPTDIR + "\rock\","/ad")
$count = 3
For Each $artist In $rockartists
$artistiso = Split($artist,"\")
$x = UBound($artistiso)
If Exist (@SCRIPTDIR + "\playlists\" + $artistiso[$x] + ".m3u") = 1
DEL @SCRIPTDIR + "\playlists\" + $artistiso[$x] + ".m3u"
EndIf
Select
Case $artistiso[$x] = "Various Artists"
$VARock = Dirlist($artist + "\*.mp3",2+4)
Case $artistiso[$x] = "Miscellaneous"
$MSRock = Dirlist($artist + "\*.mp3",2+4)
Case 1
$artistm3u = Dirlist($artist + "\*.mp3",2+4)
? "Generating Playlist for " + $artistiso[$x]
$ = WriteFile(@SCRIPTDIR + "\playlists\" + $artistiso[$x] + ".m3u",$artistm3u)
$count = $count + 1
EndSelect
Next
$popartists = DirPlus(@SCRIPTDIR + "\pop\","/ad")
For Each $artist In $popartists
$artistiso = Split($artist,"\")
$x = UBound($artistiso)
If Exist (@SCRIPTDIR + "\playlists\" + $artistiso[$x] + ".m3u") = 1
DEL @SCRIPTDIR + "\playlists\" + $artistiso[$x] + ".m3u"
EndIf
Select
Case $artistiso[$x] = "Various Artists"
$VApop = Dirlist($artist + "\*.mp3",2+4)
Case $artistiso[$x] = "Miscellaneous"
$MSpop = Dirlist($artist + "\*.mp3",2+4)
Case 1
$artistm3u = Dirlist($artist + "\*.mp3",2+4)
? "Generating Playlist for " + $artistiso[$x]
$ = WriteFile(@SCRIPTDIR + "\playlists\" + $artistiso[$x] + ".m3u",$artistm3u)
$count = $count + 1
EndSelect
Next
? "Generating miscellaneous playlists..."
If Exist(@SCRIPTDIR + "\playlists\Miscellaneous Rock.m3u") = 1
DEL @SCRIPTDIR + "\playlists\Miscellaneous Rock.m3u"
EndIf
If Exist(@SCRIPTDIR + "\playlists\Miscellaneous Pop.m3u") = 1
DEL @SCRIPTDIR + "\playlists\Miscellaneous Pop.m3u"
EndIf
$MiscRock = JoinArray($MSRock,$VARock)
$ = WriteFile(@SCRIPTDIR + "\playlists\Miscellaneous Rock.m3u",$MiscRock)
$Miscpop = JoinArray($MSpop,$VApop)
$ = WriteFile(@SCRIPTDIR + "\playlists\Miscellaneous Pop.m3u",$Miscpop)
$count = $count + 2
$rc = runningtime()
MessageBox("Processed " + $count + " playlists in " + $rc + " seconds.","Finished!",64,0)
Quit
I'm a little confused as to why it's telling me that the variable is undefined, as I explicitly define $count. If I move that line up to the top of the script, it then bugs me that $artist in line 32 is undefined...
I don't think I've made any changes to my system since the last time I successfully ran the script...any tips as to the nature of the problem would be appreciated.
FWIW, I'm using KiX 4.22
Edited by eriqjaffe (2005-02-24 12:34 AM)
|
|
Top
|
|
|
|
#134426 - 2005-02-24 10:00 AM
Re: A script has stopped working
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Quote:
I'm a little confused as to why it's telling me that the variable is undefined, as I explicitly define $count. If I move that line up to the top of the script, it then bugs me that $artist in line 32 is undefined...
Kind of.
You explicitly assign a value to the variable which implicitly declares it.
Explicitly declaring a variable can only be done with the DIM or GLOBAL statements (don't use GLOBAL).
The option SetOption("Explicit","ON") which is in one of your UDFs instructs KiXtart to handle undeclared variables as an error.
The "Explicit" option is global in scope and should never be set in a UDF unless the UDF also resets it to it's original value.
Having said that, *you* should set it at the top of your script and then declare all your variables. It's good coding practice, will enable you to track typos and bugs much more quickly and if you ever post to the UDF forum you will be required to explicitly declare all variables.
|
|
Top
|
|
|
|
#134429 - 2005-02-25 04:16 PM
Re: A script has stopped working
|
eriqjaffe
Hey THIS is FUN
Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
|
But...the script as posted worked fine once I re-installed WSH. And, as I mentioned, it had worked fine for months up until the other day, even without declaring the variables...
Before reinstalling WSH, I went through the script, declaring all the variables, and was still getting odd behavior. In particular, the DirPlus calls were not generating arrays, as they prevoiusly had..unless I was declaring the variables incorrectly, which is possible. Is this the correct method:
Code:
DIM $artist,$artistiso,$x ...etc?
I would think that it could have been a UDF which requires WSH causing the problem, but none of the UDFs in the script list WSH as a prerequisite.
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1636 anonymous users online.
|
|
|