mIRC Homepage
Posted By: ix007 While loop ERROR - 11/04/08 10:31 PM
For some reason in the 2ndline of the while loop the Variable won't set, I have tried alot of alternatives of this but still no dice. Thanks ahead
Code:
 if ($1 == schedule) {
      if (!$regd) {
        msg $nick Must Register to use this system. Type '.register'
        return 0
      }
      if ($banned) {
        msg $nick Sorry $nick $+ , but you have been banned from using this service. Reason:4,0 $readini(banned.ini,banned,$address($nick,2)) $+ .
        return 0
      }
      elseif (!$2) {
        msg $nick To schedule use this format: .schedule <map> <rcon> <location>
        msg $nick We are in BETA-Testing. Please read our agreement policy before proceeding.
        var %x = 3
        while (%x <= $lines(servlist.ini)) {
          var %servertest = $gettok($read(servlist.ini,%x),1,61)
          if ($readini(servloc.ini,inuse,%servertest)) {
            set %changerble $+(%changerble,$chr(44)) $+($gettok($read(servlist.ini,%x),1,61),(4,1In Use1,0))
            inc %x
          }
          else {
            set %changerble $+(%changerble,$chr(44)) $gettok($read(servlist.ini,%x),1,61)
            inc %x
          }
        }
        msg $nick Current Servers: $gettok($read(servlist.ini,2),1,61) $+ %changerble $+ .
        unset %changerble
      }
Posted By: RusselB Re: While loop ERROR - 11/04/08 10:56 PM
You should use $readini not $read for an ini file, and $readini requires more parameters than $read.

I see from the 3rd line in your while loop that you are using $readini, so I don't know why you aren't using it in the 2nd line... and other locations in the script.

Posted By: kwell Re: While loop ERROR - 11/04/08 10:56 PM
Ahi ???

Code:
    var %x = 3
    while (%x <= $lines(servlist.ini)) {
      var %servertest = $gettok($read(servlist.ini,%x),1,61)
      if ($readini(servloc.ini,inuse,%servertest)) {
        set %changerble $+(%changerble,$chr(44)) $+($gettok($read(servlist.ini,%x),1,61),(4,1In Use1,0))
        inc %x
      }
      else {
        set %changerble $+(%changerble,$chr(44)) $gettok($read(servlist.ini,%x),1,61)
      }
      inc %x
    }
  }
Posted By: ix007 Re: RusselB - 11/04/08 11:04 PM
I am trying to grab certain things so I just used a $read, I guess I could have used $readini, but the problem is that it wont set a variable in the 2nd line of the while loop.
Posted By: RusselB Re: RusselB - 12/04/08 03:02 AM
I'll need to see an example of the line(s) that are in the servlist.ini file to make a better determination. As I said, you should use $readini for ini files, as that's what it's designed for. If your entire script isn't too big, and you'd like some suggestions as to how it could be made better (eg: proper use of the ini file), please post it and I'll be happy to see what I can do to make it better.
Posted By: Riamus2 Re: While loop ERROR - 12/04/08 12:16 PM
Also, rather than adding a comma in there like that, you can use $addtok. It's better suited for that sort of thing.
Posted By: ix007 Re: While loop ERROR - 12/04/08 03:04 PM
Alright well the ini setup is like this

Code:
servlist.ini
[servers]
dallas=127.0.0.1


Code:
servloc.ini
[servers]
dallas=person who used it, time date.
Posted By: RusselB Re: While loop ERROR - 13/04/08 12:06 AM
And with that information, here's my recommendation for a re-write of the section of code that you supplied
Code:
if ($1 == schedule) {
  if (!$regd) {
    msg $nick Must Register to use this system. Type '.register'
    return 0
  }
  if ($banned) {
    msg $nick Sorry $nick $+ , but you have been banned from using this service. Reason:4,0 $readini(banned.ini,banned,$address($nick,2)) $+ .
    return 0
  }
  if (!$4) {
    msg $nick To schedule use this format: .schedule <map> <rcon> <location>
    msg $nick We are in BETA-Testing. Please read our agreement policy before proceeding.
  }
  else {
    var %x = 1, %y = $ini(servlist.ini,0)
    while %x <= %y {
      var %a = 1, %b = $ini(servlist.ini,%x,0)
      while %a <= %b {
        if $readini(servloc.ini,servers,$ini(servlist.ini,%y,%a)) {
          var %inuse = $addtok(%inuse,$ini(servlist.ini,%y,%a),44)        
        }
        var %servers = $addtok(%servers,$ini(servlist.ini,%y,%a),44)
      }
      inc %a
    }
    inc %x
  }
  var %a = 1, %b = $numtok(%inuse,44)
  while %a <= %b {
    var %servers = $reptok(%servers,$gettok(%inuse,%a,44),$+($gettok(%inuse,%a,44),4,1In Use1,0),1,44)
    inc %a
  }
  msg $nick Current Servers: %servers $+ .

© mIRC Discussion Forums