mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2017
Posts: 4
D
Self-satisified door
OP Offline
Self-satisified door
D
Joined: May 2017
Posts: 4
Hey, so I'm still pretty new to irc but I tried throwing something together to add points to everyone in a specific channel userlist and it's only adding points to myself when I try it. I'm probably missing something super obvious :p

Code:
on *:TEXT:!bonusall:#testchannel: {
  var %n = $nick(#,0)
  var %i = 1
  var %nick = $nick(#,%i)
  %nick = $nick(#,%i)
  set %points $calc( $readini(Points.ini,n,$+(,#,.,%nick),Points) + 500 )
  /writeini -n Points.ini $+(,#,.,%nick) Points %points
  { msg $chan Everyone has been given 500 points! }
}

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
you never increment %i so it only acts against the top nick in the list.

Code:
on *:TEXT:!bonusall:#testchannel: {
  var %n = $nick(#,0)
  var %i = 1
  while (%i <= %n) {
  var %nick = $nick(#,%i)
  set %points $calc( $readini(Points.ini,n,$+(,#,.,%nick),Points) + 500 )
  /writeini -n Points.ini $+(,#,.,%nick) Points %points
  inc %i
  }
  { msg $chan Everyone has been given 500 points! }
}

Joined: Sep 2015
Posts: 101
Vogon poet
Offline
Vogon poet
Joined: Sep 2015
Posts: 101
does any use goto or only me? I observe that all use while only smile

Joined: May 2017
Posts: 4
D
Self-satisified door
OP Offline
Self-satisified door
D
Joined: May 2017
Posts: 4
You're a legend dude, I'll make note of that, thanks!

Originally Posted By: maroon
you never increment %i so it only acts against the top nick in the list.

Code:
on *:TEXT:!bonusall:#testchannel: {
  var %n = $nick(#,0)
  var %i = 1
  while (%i <= %n) {
  var %nick = $nick(#,%i)
  set %points $calc( $readini(Points.ini,n,$+(,#,.,%nick),Points) + 500 )
  /writeini -n Points.ini $+(,#,.,%nick) Points %points
  inc %i
  }
  { msg $chan Everyone has been given 500 points! }
}

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
goto has its uses, but while often saves several lines of code. For example, if he wanted to give points only to 'regular' users who don't have op/voice status, he'd be looping throught $nick($chan,0,r)

But sometimes there are zero of these, so instead of checking to make sure there's at least 1 nick to act against, you can use WHILE, which not only quits when you've processed everyone, but also lets you avoid processing when there's nobody on the list.

Joined: Sep 2015
Posts: 101
Vogon poet
Offline
Vogon poet
Joined: Sep 2015
Posts: 101
Look:
Code:
on *:TEXT:!bonusall:#testchannel: {
  %n = $nick(#,0) | %i = 1
  :next
  if (%i > %n) goto end
  %nick = $nick(#,%i)
  %points = $calc( $readini(Points.ini,n,$+(,#,.,%nick),Points) + 500 )
  writeini -n Points.ini $+(,#,.,%nick) Points %points
  inc %i 1 | goto next
  :end
  msg $chan Everyone has been given 500 points!
}


So, even the %n will be 0, goto works perfectly. My opinion that using goto is more easy then while, even if you have other difficult situations smile


Link Copied to Clipboard