mIRC Home    About    Download    Register    News    Help

Print Thread
#182201 06/08/07 10:35 AM
Joined: May 2007
Posts: 13
T
trink Offline OP
Pikka bird
OP Offline
Pikka bird
T
Joined: May 2007
Posts: 13
Basically I have this going on.
Quote:
while (!$findfile(C:\program files\mirc3\files\,$gettok($read(songrequest.txt,1),%a,58),1)) {
if ($deltok($read(request.txt,1),%a,58) != $null) { write -c songrequest.txt $deltok($read(songrequest.txt),%a,58) }
if ($file(songrequest.txt).size == 0) { remove songrequest.txt }
}


In this case %a = 1
What I've got is an online php script that will write to songrequest.txt in this fashion: if there is already text in songrequest.txt it will append : and the song request to whatever is currently in the file. I'm using a tokenized list within this file with : as the separator. When this while loop is run, it will basically go into the nonstop loop of death, causing me to have to kill mIRC and restart it.

Basically all this needs to do is WHILE it cannot find the filename, then IF there are still other tokens in the list, it deletes that token within the list and writes that updated tokenized list to the file, or IF the filesize is 0, then it deletes the file. It seems to me that that is covering both cases. Yet, judging from the loop of death I'm getting each time the while the loop runs, i'm assuming that its failing. Any help here would be appreciated.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
In your second line, the $read command references request.txt not songrequest.txt

Joined: May 2007
Posts: 13
T
trink Offline OP
Pikka bird
OP Offline
Pikka bird
T
Joined: May 2007
Posts: 13
That changed, it still doesnt work.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Try this version
Code:
while $numtok($read(songrequest.txt,1),58) {
  if !$findfile($+("C:\program files\mirc3\files\",$gettok($read(songrequest.txt,1),1,58))) {
    .write -c songrequest.txt $deltok($read(songrequest.txt,1),1,58)
  }
  if !$numtok($read(songrequest.txt,1),58)  { remove songrequest.txt }
}


Personally I don't like using text files for something like this, as the reading/writing is what's going to take the longest time, due to the relatively slow speed of your hard drive.

Last edited by RusselB; 06/08/07 11:38 PM.
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
There's too many parameters in that $numtok identifier. smile

Code:
if !$numtok($read(songrequest.txt,1),58)  { remove songrequest.txt }

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Good catch...code edited

Joined: May 2007
Posts: 13
T
trink Offline OP
Pikka bird
OP Offline
Pikka bird
T
Joined: May 2007
Posts: 13
For all you mIRC scripting newfolk out there, you may learn something from this.

I recoded the script, looks like this now
Quote:
while (!$findfile(C:\program files\mirc3\files\,$gettok($read(songrequest.txt,1),%a,58),1)) && ($findfile(C:\program files\mirc3\,songrequest.txt,1)) {
if ($deltok($read(songrequest.txt,1),%a,58) != $null) { write -c songrequest.txt $deltok($read(songrequest.txt),%a,58) }
else { remove songrequest.txt }
}

Basically when I had just while (!$findfile(C:\program files\mirc3\files\,$gettok($read(songrequest.txt,1),%a,58),1)) { it was running the loop while there was an invalid filename in the %a token AND while a $null was returned, meaning the file wasn't there. Since the script deletes songrequest.txt, I had to make it run the loop only while it could find the file.

See, kids, its as easy as 1, 2,
Quote:
alias rettime {
var %a $gettok($calc($calc($sound($file($gettok(C:\program files\mirc3\files\ $+ $readini(playlist.ini,playlist,playlist),1-2,58)).shortfn).length / 1000) / 60),1,46)
if ($len($gettok($round($calc($round(0. $+ $gettok($calc($calc($sound($file($gettok(C:\program files\mirc3\files\ $+ $readini(playlist.ini,playlist,playlist),1-2,58)).shortfn).length / 1000) / 60),2,46),2) * 0.6),2),2,46)) == 1) { var %b $gettok($round($calc($round(0. $+ $gettok($calc($calc($sound($file($gettok(C:\program files\mirc3\files\ $+ $readini(playlist.ini,playlist,playlist),1-2,58)).shortfn).length / 1000) / 60),2,46),2) * 0.6),2),2,46) $+ 0 }
else { var %b $gettok($round($calc($round(0. $+ $gettok($calc($calc($sound($file($gettok(C:\program files\mirc3\files\ $+ $readini(playlist.ini,playlist,playlist),1-2,58)).shortfn).length / 1000) / 60),2,46),2) * 0.6),2),2,46) }
if ($len(%b) == 0) { var %b 00 }
return $chr(91) $+ %a $+ : $+ %b $+ $chr(93)
}

THATS NOTHING!!! ITS LIKE, 2+2!!

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Well, I didn't get the point of that code.
Anyway - I tried to, hence reformulated your code, hoping to get that point.
I still don't know for sure what it is doing, or should be doing... but at least it's looking a bit cleaner now... wink And, if I made no errors while reformulating, it should still return the same results.
Code:
alias rettime {
  var %dir = C:\program files\mirc3\files\
  var %read = $readini(playlist.ini,playlist,playlist)
  var %num = $calc($sound($file($gettok($+(%dir,%read),1-2,58)).shortfn).length / 60000)
  var %tok = $gettok($round($calc($round(0. $+ $gettok(%num,2,46),2) * 0.6),2),2,46)

  var %a = $gettok(%num,1,46)
  var %b = $iif(($len(%tok) == 1),$+(%tok,0),%tok)
  if ($len(%b) == 0) { var %b = 00 }

  return $+($chr(91),%a,:,%b,$chr(93))
}

I do post this for all the scripting newfolk out there, to demonstrate how important some code streamlining / -management could be... it's just like 2 + 2 cool

Last edited by Horstl; 14/08/07 03:06 AM.
Joined: May 2007
Posts: 13
T
trink Offline OP
Pikka bird
OP Offline
Pikka bird
T
Joined: May 2007
Posts: 13
It just comes to show you, that I'm not organized at all. laugh
All that script was doing was getting the length of an mp3 file, and turning it into [x:xx], of course it tends to fail, which I have to fix.

Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Ah! So, I suggest using the following method:
Code:
; set file
var %file = $shortfn(somedir\something.mp3)

; set length in seconds ($sound(x).length returns milliseconds)
var %len = $calc($sound(%file).length / 1000)

; use the $duration identifier and the ,3 switch to get an output "hh:mm:ss"
var %dur = $duration(%len,3)

; use $gettok to grab the last 2 tokens "mm:ss", add these square brackets
return $+($chr(91),$gettok(%dur,2-3,58),$chr(93))


condensed to one line:
Code:
 return $+($chr(91),$gettok($duration($calc($sound($shortfn(somedir\something.mp3)).length /1000),3),2-3,58),$chr(93))

Joined: Jun 2006
Posts: 508
D
Fjord artisan
Offline
Fjord artisan
D
Joined: Jun 2006
Posts: 508
You can also do this..
Code:
alias mp3dur return $+([,$gmt($calc($sound($$1).length /1000),nn:ss),])

  • //echo -a $mp3dur($sfile(*.mp3))


Joined: Dec 2002
Posts: 1,527
_
Hoopy frood
Offline
Hoopy frood
_
Joined: Dec 2002
Posts: 1,527
wow its sad to see ppl still dont realize $mircdir is a better method of finding your mirc directory, also it helps if you ever plan on sharing your code with others, and really mirc scripting is more about sharing what you learn with others, its what keeps us all reading here.


D3m0nnet.com
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
As a general remark, this is absolutely true. Using $scriptdir, $logdir, $mircdir etc is higly recommended. I'd never use hard coded foldernames in my own snippets...
Yet all I did was:
Quote:
(...) hence reformulated your code, hoping to get that point. (...)
In addition to this, and regarding the piece of code given by the OP, I had not been 100% certain whether or not "C:\program files\mirc3\files\" was a subfolder of $mircdir or $scriptdir. Regards smile

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
For personal scripts or just for typing into the editbox, I prefer using "." (//echo -a $findfile(.,*,0,echo -a $findfilen ~ $1-)) to $mircdir because it's much quicker, but you're right; for public scripts $mircdir would be the way to go.

Personally though, I think storing your settings files in $mircdir is bad practice, and you should use $scriptdir.


Link Copied to Clipboard