mIRC Home    About    Download    Register    News    Help

Print Thread
#232422 04/06/11 01:32 PM
Joined: Jun 2011
Posts: 6
M
mur_phy Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Jun 2011
Posts: 6
Could be improved?
Code:
on !*:join:#: {
  writeini -n sys/join.ini $chan TOTAL $calc($readini(sys/join.ini,$chan,TOTAL) + 1)
  writeini -n sys/join.ini $chan $nick $calc($readini(sys/join.ini,$chan,$nick) + 1)
  msg $chan  $readini(sys/join.ini,$chan,$nick) - $readini(sys/join.ini,$chan,TOTAL) 
}

join.ini
Code:
[#channel_1]
TOTAL=100
mur_phy=5

[#channel_2]
TOTAL=53
mur_phy=10


mur_phy #232423 04/06/11 01:47 PM
Joined: Jul 2006
Posts: 4,151
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,151
You can do:
Code:
on !*:join:#: {
  var %t $calc($readini(sys/join.ini,$chan,TOTAL) +1),%n $calc($readini(sys/join.ini,$chan,$nick) +1)
  writeini -n sys/join.ini $chan TOTAL %t
  writeini -n sys/join.ini $chan $nick %n
  msg $chan %n - %t
}
which is clearer imo, but except the readability, nothing is really improved here.

Last edited by Wims; 04/06/11 02:08 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Wims #232424 04/06/11 02:12 PM
Joined: Jun 2011
Posts: 6
M
mur_phy Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Jun 2011
Posts: 6
Thanks Wims, looks much better grin

mur_phy #232431 04/06/11 11:07 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
I think this snippet can be greatly improved with $nick being stored in hash table data separated by a space and then use $hfind() to refer to the $nick who joins for the calculation. By using INI, it writes a new item for certain nicknames. This doesn't account for nick changes, so if a recorded nickname changes, and rejoins, the script will see it as another person and create a new INI item.

Tomao #232432 05/06/11 12:57 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Using hash tables isn't going to solve what you are commenting on. Using the $address() instead of $nick would. And that can be done with hash table or INI or a variety of other storage options.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #232433 05/06/11 03:43 AM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
It was just my two bits worth. What would you have done better if you were writing a code for this particular task?

Tomao #232439 05/06/11 03:34 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
As I mentioned, just use some form of $address. Using hash tables isn't a bad idea... it just won't solve the issue you mentioned because as long as you use $nick, you won't know if it's a changed nick no matter what method you use. $address in either hash tables or INI files will let you prevent much of that if it matters in the script.


Invision Support
#Invision on irc.irchighway.net
Riamus2 #232451 05/06/11 07:28 PM
Joined: Jul 2007
Posts: 1,129
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Fair enough, Riamus2.


Link Copied to Clipboard