mIRC Home    About    Download    Register    News    Help

Print Thread
Using hash tables for my betting system #251609 26/02/15 04:06 AM
Joined: Nov 2014
Posts: 79
N
Newbie Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
I keep hearing that hash tables are a faster and more efficient way of storing information that does not need to be stored. However my question is whether a key can have multiple values or only one? From what I've seen you can only have one value per key meaning that I would have to make 2+ hash tables.

Code:
on *:TEXT:!bet *: {
  if ($2 isnum) {
     msg # /me To bet type --> !bet boss dinocoins <--
  }
  else {
     hmake $2 
     hadd $nick $3 
     msg # $nick has wagered $3 on boss $2.  
  }
}


So when someone types !bet (boss name) (points) it will make a hash table for that boss. But is it possible to make a key with several people instead of having to make a new hash table for every option?

Re: Using hash tables for my betting system [Re: Newbie] #251619 26/02/15 06:09 AM
Joined: Sep 2014
Posts: 259
S
Sakana Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Yep, just use $gettok on the key wink

Re: Using hash tables for my betting system [Re: Sakana] #251621 26/02/15 06:23 AM
Joined: Nov 2014
Posts: 79
N
Newbie Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
But the key can't have more than one item? For example, instead of what I have I want it to be

Code:
hmake bets
hadd bets $3 $nick 


Where $3 would be the boss. So in the end I would have one key $3 which is equal to multiple $nicks. Is that possible?

Re: Using hash tables for my betting system [Re: Newbie] #251626 26/02/15 06:51 AM
Joined: Sep 2014
Posts: 259
S
Sakana Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Oops, I meant $gettok on the value/item :-p

Yeah, they cant hold more than 1 value, but a string is still just 1 value

Re: Using hash tables for my betting system [Re: Sakana] #251627 26/02/15 07:01 AM
Joined: Nov 2014
Posts: 79
N
Newbie Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
Oh, so I would basically go,

Code:
var %included $hget(bets,boss_name)
$hadd bets %included $+ ,$nick
$gettok($hget(bets,boss_name),N,44)

Re: Using hash tables for my betting system [Re: Newbie] #251631 26/02/15 07:19 AM
Joined: Sep 2014
Posts: 259
S
Sakana Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
Your hadd line seems wrong. Something like this?

Code:
hadd bets $nick $2-
$gettok($hget(bets,$nick),N,32)

Re: Using hash tables for my betting system [Re: Sakana] #251632 26/02/15 07:21 AM
Joined: Nov 2014
Posts: 79
N
Newbie Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
Ok, and the 32 simply means space if I remember correctly