mIRC Home    About    Download    Register    News    Help

Print Thread
#209927 27/02/09 01:55 AM
Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
Code:
on 1:text:*number*:#: {
  if ($1 == %c $+ number) {
    set %lottonames $addtok(%lottonames, $nick, 32)
    set %lottonums $addtok(%lottonums, $2, 32)
    inc %playernum 1
    msg %lotchan %lottonums %lottonames
    msg %lotchan 5 $nick has guessed $2 $+ .
  }
}


I've been working on a !lotto game for my bot lately, and I've run into a roadblock in getting it to recognize people's guesses. I've been using the $addtok function to add everyone's guesses to a single variable, but it seems that using this method, I can't add the same number more than once to the variable. It handles different numbers just fine, however. It wouldn't be very fair to award just a single winner if multiple people guess the number correctly. What methods could I use to set this up so that multiple people can guess the number?

...There is a lot more to the code, but I'm reluctant to share it right now. I'm just asking for advice, I'm not asking to have my code rewritten and handed back to me.

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
This is the method that $addtok uses, and is described in the help file.
Quote:
Adds a token to the end of text but only if it's not already in text.


I'm going to presume that you want to keep each person't guesses associated with that person's nick.

You can do this in a number of ways, but the top two I would recommend are using compound variables using the nick as part of the variable name, or using a hash table.

The more people you get, the more I would lean towards the hash table method.

Good luck, and if you want/need more assistance, please be sure to tell us what method you decide to use.

FYI: other methods include using a file (ini or text).

Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
At most, there would be 15 people playing, usually around 4-6 or so. What would you recommend for that? Also, is there another name for compound variables? I searched the help file for them, but came up with nothing.

Joined: Jul 2006
Posts: 4,151
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,151
Then don't use $addtok.
If you want the variable to be space separated use :

Code:
set %lottonames %lottonames $nick
set %lottonums %lottonums $2



#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
The help file refers to them as dynamic variables.

Joined: Jan 2009
Posts: 25
F
Fernin Offline OP
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Jan 2009
Posts: 25
Originally Posted By: Wims
Then don't use $addtok.
If you want the variable to be space separated use :

Code:
set %lottonames %lottonames $nick
set %lottonums %lottonums $2



This works out perfectly, thanks much!


Link Copied to Clipboard