mIRC Home    About    Download    Register    News    Help

Print Thread
#228662 05/01/11 11:02 PM
Joined: Jan 2011
Posts: 2
L
Bowl of petunias
OP Offline
Bowl of petunias
L
Joined: Jan 2011
Posts: 2
Hello,

There are not very many information about $feof identifier in the manual. I know it returns the results of the last file access attempt in any script and it indicates the end of file was reached. However, how do I know which file was the last accessed?

Basically I have simple if-then-else statement:
If ($feof = 1) { CMDs }

But it seems like it never reaches the end of file ($feof is always 0). Is there any way how to find out what file is the last one accessed?

--------------------------------------------------------------

FYI this is my script with explanation:

Code:
Var %line=1 /* global variable */
On *:TEXT:*:#chan: {
  If ( ($nick == nick) && ($network == network) && (0NEW = $1) )  { 
    If (!$window(@NEW)) { window -k0 @NEW }
    aline -ph @NEW $strip($4)
    savebuf -a 1 @NEW queue.dat /* saving each line from NEW window to file, faster then fopen-fwrite-fclose */
  }
  If ( $timer(timerNEW) = $null ) { timerNEW 0 120 /Start } /* checking if timer is not already running, otherwise downloading every two minutes new input from the file */
}

Alias Start {
  msg BOT xdcc send $read(queue.dat, %line) /* sending bot pack number, each is on the each line */
  If ($feof = 1) { /* if the end of file was reached */
    %line=1 /* start from the beginning next time */
    fOpen -o Queue queue.dat /* clearing/emptying the file */
    fClose Queue
    timerNEW off /* turning off the timer */
  } 
  else inc %line 1 /* else check next line */
}


Am I missing something here?


Creator of /dev/null
Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
the reason you never reach the end of the file is that $read() does not advance the file pointer. you should be using $fread(Queue) which returns the next line from the current position and then advances the pointer to the end of that line. this saves you having to maintain a %line variable to monitor line position, and also takes advantage of the fact that you've established a handle to that file ($read does not).

also, bear in mind you need spaces around '%line=1' and that you cannot use code outside of events/aliases; sticking the line 'var %line = 1' above the on TEXT event as you showed will accomplish nothing. furthermore, you can't use /* comments */ in the middle of commands nor, apparently, on the same line following a close brace. i know these things may seem contradictory to what you're used to from other languages, but you'll get accustomed to mIRC's seemingly bizarre syntax through a bit of trial and error :P


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Jan 2011
Posts: 2
L
Bowl of petunias
OP Offline
Bowl of petunias
L
Joined: Jan 2011
Posts: 2
First, thanks for the helpful inputs jaytea.

1/ I will definitely try $fread and get back to you with result.
2/ 'var %line = 1' works the same way as 'var %line=1'
3/ 'var' was absolutely necessary in my deployment otherwise it would not work at all. It is primeval/starting value.
4/ I know how to use comments in mIRC, they are not actually in the code I use, I just wrote them for you guys on this forum to understand what I am trying to accomplish here;-)

Regards,


Creator of /dev/null
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: luckylittle

2/ 'var %line = 1' works the same way as 'var %line=1'


Actually, no, it doesn't. Spaces are required. You can verify this if you like. Type the following from the edit line:

//var %testspace=1 | echo -a %testspace

You will get an error. Now, put in the spaces and try again. You will echo 1. As mentioned, /var cannot be outside of an event. It does nothing. That's probably why you think it works. If it's outside an event, then it is "technically" true that spaces don't matter because it doesn't work regardless. But if you put it in the event or alias where it belongs, then spaces are required for it to work.

mIRC completely ignores anything that is in Remotes that is not inside an event or inside an alias. Everything else will be ignored.

And most likely, if you think it's working, then you've already /set a variable (variables aren't erased automatically once /set), so that it seems to work. Global variables are done with /set instead an event or alias. /var is used for temporary variables and also must be inside an alias or event. Note that you should use something like %testspace when testing what I showed above (not %line) so that there's no chance that you already have the variable set that way you aren't confused about whether or not it works.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard