mIRC Homepage
Posted By: dominic_eddy While loops - 17/02/13 04:53 PM
I'm making a script, which uses this.
Quote:
set %announcer 1
set %remainer $read(remaining.txt, %announcer)
while (%remainer != $null) {
if (%remainer ison #test) {
notice %remainer $1-
write -ds $+ %remainer remaining.txt
}
inc %announcer 1
set %remainer $read(remaining.txt, %announcer)
}

it basically reads through a txt file, and see's if someone is on channel, if they are, it'll send them a /notice, it will then delete them from the file. Althoguh i'm having some problems, it only seemed to notice the first person. I'm starting to think that it's the if statement in the while loop, would that stop it looping perhaps?
Posted By: 5618 Re: While loops - 17/02/13 05:44 PM
I don't see an immediate flaw in your script.
From how you use $read I assume the .txt file only contains nicknames?
Also, you can probably use local variables instead of global ones here (or do you need the variables in other events too?)
I have rewritten the script to be more condensed/'simpler'.
Does this perhaps work for you?

Code:
var %announcer = 1
while ($read(remaining.txt,n,%announcer)) {
  if ($v1 ison #test) {
    notice $v1 $1-
    write -ds $+ $v1 remaining.txt
  }
  inc %announcer
}
Posted By: dominic_eddy Re: While loops - 17/02/13 06:01 PM
didn't seem to work, maybe it's because It doesn't really work with the rest of the script.
this is the full script:
Code:
alias announce { 
  if ($1 == $null) { 
    echo 4 -a Add a message to announce!
    halt
  }
  writeini announce.ini set true 1
  copy -o people.txt remaining.txt
  set %announcer 1
  set %remainer $read(remaining.txt, %announcer) 
  while (%remainer != $null) {
    if (%remainer ison #test) {
      notice %remainer $1- 
      write -ds $+ %remainer remaining.txt 
    }
    inc %announcer 1
    set %remainer $read(remaining.txt, %announcer)
  }
  if ($read(remaining.txt, 1) == $null) {
    writeini announce.ini set true 0
  }
}
on *:JOIN:#test: {
  if ($readini(announce.ini,set,true) == 1) {
    set %remainer $read(remaining.txt, s, $nick) 
    if (%remainer != $null) { 
      notice %remainer $1- 
      write -ds $+ %remainer remaining.txt
    }
  }
}

Do you reckon you could modify my entire script please smile? I would, but I have never really done the kind of things you used in script you did.

as for global or local variables, I don't know, I guess global to be on the safe side laugh

EDIT:
____________
OMG, can't believe I forgot to note down the announcement message so if someone joins, the script didn't know what it was saying! lol, i'm such a derp
I'll let ya know if it works once i added the message thing.

EDIT: AGAIN
________________
i replaced notice wooolly $1- with $readini(announcement.ini(ETC)) so the script knew what it was actually announcing lol, but it still didn't work unfortunatly. Only send message to the first person on list, and when i /hop'ed, it didn't send notice to person.
Posted By: dominic_eddy Re: While loops - 18/02/13 12:30 AM
Anyone got any ideas smile?
Posted By: Deega Re: While loops - 18/02/13 01:30 AM
You should change this line (in the on join event)
Code:
$read(remaining.txt, s, $nick)
to
Code:
$read(remaining.txt,nw,$nick)

Using the s switch for read only returns the text which comes after the matched text, which in this case is nothing.
Originally Posted By: mirc.hlp
//echo $read(info.txt, s, mirc)
Scans the file info.txt for a line beginning with the word mirc and returns the text following the match value.
Posted By: dominic_eddy Re: While loops - 18/02/13 09:19 AM
aw thaks man! smile join is working perfectly now, only thing tat's still a bit messed up is the announcement alias :S i tested it with 3 names in the list to begin with, all 3 we're in chan, and it sent message to only 2, then i added a 4th one, and switched the names round abit to see if it was anything to do the order, and it still only announced to the 2 nicks :S lol.
That puzzles me :S
Posted By: 5618 Re: While loops - 18/02/13 09:56 AM
The problem is possibly caused by the fact that two present nicks are right beneath one another in the .txt file. Because you delete a line from the file on a match, increasing the value of %announcer will actually mean you skip one line on the next $read()
Posted By: dominic_eddy Re: While loops - 18/02/13 09:59 AM
um, I get what your saying, good point! i'll have a little look around and see what I can do. maybe soemhow only increade %announcer if the curent nick isn't on #test.
Posted By: 5618 Re: While loops - 18/02/13 10:04 AM
or cheat and dec %var first when it is
Posted By: dominic_eddy Re: While loops - 18/02/13 10:50 AM
Thank god! Finally it's working, thanks all! much appreciated
© mIRC Discussion Forums