mIRC Home    About    Download    Register    News    Help

Print Thread
#270891 21/10/22 03:32 AM
Joined: Oct 2022
Posts: 2
N
nuke Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
N
Joined: Oct 2022
Posts: 2
Im trying to make a kinda of reminder where I'm saving stuff on a txt then trying to find that word and echo it to me, kinda a reminder script, but I came to a stop what's I missing?

Code
alias check_reminder {
  if ($1 == $null) { set %reminderdate $date }
  if ($1 != $null) { set %reminderdate $1 }
  set %remindlines $lines(reminder.txt)
  set %reminder0results 1
  echo -a Searching Reminders for: %reminderdate
  while (%remindlines > 0) {
    if ($read(reminder.txt,tws,%reminderdate) != $null) { echo -a ID: %remindlines $+ : $read(reminder.txt,tws,%reminderdate) | set %reminder0results 0 }
    dec %remindlines
  }
  if (%reminder0results == 1) { echo -a None Found }
}

Joined: Jan 2004
Posts: 1,949
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 1,949
a few things to look at.

Unless you need to keep a variable around for the script to use later, or so it can be seen by another alias, you should use /var instead of /set, so you don't end up cluttering your list of %global_variables with things that are either ignored by the script itself, or in some cases are never used again.

The 's' and 'w' switch are mutually exclusive, and by using them together, the 'w' is ignored. The 's' searches for a line beginning with your search string, then returns the remainder of the line. The 'w' searches for a wildcard, then returns the entire line including the 1st word.

When using 's', the way you were checking the results assumes that $null means no-match, but that also happens if the date is the only thing on the line. Instead you should check $readn, which returns 0 for no search-match but otherwise returns the line where it found a match.

You should also use the starting-line parameter, to begin the search at the line following the latest $readn. Luckily you were failing, otherwise you'd be in an infinite loop repeatedly finding the 1st match.

You're doing duplicate disk reads. You first look to see if there's a match in the disk file, and then you read it again in order to display it, when your search for the match should already give you the string.

You should always use the 'n' switch when reading from disk, to make sure that it doesn't try to evaluate %word or $word as variables or identifiers, or give special meaning to the "|" symbol. The evaluation of only applies to the reminder text being returned, so you can't skip the 'n' switch then have a line beginning with the 5 characters $date then have a match that shows up every day.

One thing I didn't do was to verify that $1 was actually a date, though this is fine if you want to search for other reminder tags besides an actual date.

This example is just minimal changes to your script. Other changes to make it more efficient could include:

Doing everything with 1 disk-read by using /filter to either send all matches to a hidden @win, or to have the /filter output going to an alias which handles all matches, displays etc.

If you want to return matches for reminders still in the list but are for a prior date, you could have the reminder file contain the date in 2022/12/31 style which makes it easier to compare if the date is greater/less than. But for that method, you couldn't use the scan method, but would instead need to examine each line to see if the date is in the range you're searching for.

Code
alias check_reminder {
  var %reminderdate $date
  if ($1 != $null) { var %reminderdate $1 }
  var %reminder0results 0
  var %startline 1
  echo -a Searching Reminders for: %reminderdate
  while ($true) {
    var %string $read(reminder.txt,ts,%reminderdate,%startline)
    if (!$readn) break
    inc %reminder0results | echo -a ID: %reminder0results $+ : %string | var %startline $readn + 1
  }
  if (%reminder0results == 0) { echo -a None Found }
}

Joined: Oct 2022
Posts: 2
N
nuke Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
N
Joined: Oct 2022
Posts: 2
omg so much info in detail TY U so much, that worked perfectly smile


Link Copied to Clipboard