mIRC Home    About    Download    Register    News    Help

Print Thread
#256341 12/01/16 07:07 AM
Joined: Nov 2015
Posts: 3
W
Self-satisified door
OP Offline
Self-satisified door
W
Joined: Nov 2015
Posts: 3
Hey, I've been banging my head against a brick wall for a while now. I'm writing a script to sort points and cannot get the greater than sign to work properly in an if statement. Code below.

Code:
;VARIABLES LIST FOR !SORT
;%a = Points Output Local
;%b = End Trigger For Checking For .
;%c = Increase For $right And $left
;%d = Name Output Local
;%e = Points Output Global
;%f = Name Output Global
;%x = Loop

on *:TEXT:!sort*:#: {
  if (!$2) {
    var %x $lines(exp.txt)
    while (%x) {
      var %e 0
      var %c 1
      var %b 0
      while (%b != 1) {
        var %a $right($read(exp.txt,%x),%c))
        inc %c
        if (. isin $right($read(exp.txt,%x),%c)) { var %b 1 }
      }
      var %c 1
      var %b 0
      while (%b != 1) {
        var %d $left($read(exp.txt,%x),%c))
        inc %c
        if (. isin $left($read(exp.txt,%x),%c)) { var %b 1 }
      }
      if ( %a > %e) {
        var %e %a
        var %f %d
      }
      msg # %e %a
      dec %x
    }
    msg # First place is %f with a score of %e $+ .
  }
  ;  elseif ($2 >= 1) {
  ;    var %x $lines(exp.txt)
  ;    while (%x) {
  ;      var %c 1
  ;      var %b 0
  ;      while (%b != 1) {
  ;        var %a $right($read(exp.txt,%x),%c))
  ;        inc %c
  ;        if (. isin $right($read(exp.txt,%x),%c)) { var %b 1 }
  ;      }
  ;      var %c 1
  ;      var %b 0
  ;      while (%b != 1) {
  ;        var %d $left($read(exp.txt,%x),%c))
  ;        inc %c
  ;        if (. isin $left($read(exp.txt,%x),%c)) { var %b 1 }
  ;      }
  ;      dec %x
  ;    }
  ;    msg # First place is %f with a score of %e $+ .
  ;  }
}


on *:TEXT:*:#: {
  unset %exp.*
  ;if ($($+(%,flood.,$nick),2)) { return }
  ;set -u30 %flood. $+ $nick On
  var %x $lines(exp.txt)
  while (%x) {
    if ($nick isin $read(exp.txt,%x)) {
      inc %exp.search
      set %exp.return $addtok(%exp.return,%x,32)
    }
    dec %x
  }
  if (!%exp.search) { .write exp.txt $nick $+ . $+ 1 }
  elseif (%exp.search == 1) {
    var %a  $read(exp.txt,%exp.return)
    var %b $remove(%a,$nick $+ .)
    var %b $calc(%b + 1)
    .write -dl $+ %exp.return exp.txt
    .write exp.txt $nick $+ . $+ %b
  }
  unset %exp.*
}


The short section in question is as follows.

Code:
      if ( %a > %e) {
        var %e %a
        var %f %d
      }


The test exp.txt file I'm using is as follows.

Code:
jaxxet2.1
mackverick20.7
wolfpup118.31
nightcourtdan8.19


My output, however, reads as this.

Code:
bot: 19 19
bot: 31 31
bot: 7 7
bot: 1 1
bot: First place is jaxxet2 with a score of 1.


If I change around the sign to be if ( %a < %e ) then I get the following.

Code:
bot: 0 0
bot: 0 0
bot: 0 0
bot: 0 0
bot: First place is with a score of 0.


This seems to say it isnt just blindly jumping through it all. I just cannot at all figure out why this is not working for the life of me. Can any of you see something I did wrong by any chance?

EDIT: Also, as an aside, would $gettok work as a replacement for the $right and $left system I have to find a word? I'm still new to all this and it seems like it may be a good simple replacement for it.

Last edited by wolfpup118; 12/01/16 07:17 AM.
Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
Without going into detail about script and changing everything: if the file format is "NICK.POINTS", you can just do:
Code:
window -h @points
filter -cfwtue 2 46 exp.txt @points
tokenize 46 $line(@points,1)
window -c points
msg # First place is $1 with a score of $2 $+ .



And since I'm here: I wouldn't recommend reading ($lines/$read) a file multiple times in a text event, or even writing to one.

Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
You can use this code that has an different saving/reading way than yours and is better and faster.

Remove the 'exp.txt' file and the previous code before pasting this code.


Usage: !sort <nickname>

Code:
ON *:TEXT:*:#test_chan: {
  ; if ($($+(%,flood.,$nick),2)) { return }
  ; set -eu30 %flood. $+ $nick On

  var %f = exp.txt

  if ($strip($1) == !sort) {
    if (!$2) { msg $chan ( $+ $nick $+ ): Error, Please specify a nickname! | return }
    var %data = $read(%f,nw,$2 $+ *)
    if (!%data) { msg $chan ( $+ $nick $+ ): Error, The $qt($2) nickname does NOT exist into the database! | return }
    var %nick = $gettok(%data,1,126)
    var %result = $gettok(%data,2,126)
    msg $chan ( $+ $nick $+ ): First place is $qt(%nick) with $qt(%result) score.
    return
  }

  var %r = $read(%f,nw,$nick $+ *)
  var %rn = $readn

  if (!%r) { write $qt(%f) $nick $+ ~ $+ 1 }
  elseif (%r) {
    var %value = $gettok(%r,2,126)
    var %result = $calc(%value + 1)
    write -dl $+ %rn $qt(%f) 
    write $qt(%f) $nick $+ ~ $+ %result
  }
}


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Nov 2015
Posts: 3
W
Self-satisified door
OP Offline
Self-satisified door
W
Joined: Nov 2015
Posts: 3
Thanks for the responses. Both systems work great! For westor, I'm trying to sort who would have the most points in the channel, however, but I really like how you implemented the writing to exp.txt. Thanks for the detailed reply!

I'm going to be using dazuz's system for now while i figure out just how yours works, westor, then switch to that. I personally dont like using something that I dont understand how it works in case if I need to make changes.

Time to dive into looking up just how the commands you used work! You both gave me a lot of stuff to look into.

Thanks, from a beginner to all of this stuff.

Last edited by wolfpup118; 12/01/16 08:52 PM.

Link Copied to Clipboard