mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Oct 2005
Posts: 54
B
Babel fish
OP Offline
Babel fish
B
Joined: Oct 2005
Posts: 54
I'm working on my own trivia script (omg) and I was wondering if someone could tell me if this would work or not, mostly because I don't want to be dissapointed once I get far enough into it to use that command. If it wouldn't work I would be greatfull if you could tell/help me on how to get this to work.
Code:
alias -l give.points { var %x $get.score($1) | if (%x == $null) { set %x 0 } | inc %x 1 | writeini -n benstriv_vars.ini PLAYERS score. $+ $1 %x | msg $2 $pointcheck($1) }

Aliases:
$get.score
Code:
alias -l get.score { $iif($readini(benstriv_vars.ini,PLAYERS,score. $+ $nick) == $null, return 0, return $readini(benstriv_vars.ini,PLAYERS,%score. $+ $nick)) }


$pointcheck
Unfinished


Chat NSN
My Server: sleepystickman.ircxpro.com
Joined: Apr 2003
Posts: 701
K
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Try to limit the usage of file read and write commands, they can be very slow...
I put the return in front of the $iif since it doesn't depend on the condition, changed the condition == $null since a %var or $identifier is evaluated as $false when it's $null, $false or 0. In all these cases $get.score should return 0, otherwise it returns the contents. $v1 gives the first (or only) part of the last matching if condition (also $iif and while)

Code:
alias -l get.score return $iif($readini(benstriv_vars.ini,PLAYERS,score. $+ $nick),$v1,0)


And since I'm on a roll, how about
Code:
alias -l get.score return $calc($readini(benstriv_vars.ini,PLAYERSCORE,$nick))


Why not make a topic PLAYERSCORE instead of all those concatenations? I used $calc, since $calc($null), $calc(%dsfgsdgsdgsd), $calc(thisisnotanumber) and $calc($false) all return 0, and if the $readini reads a number, it returns that.

Now the other alias:
Code:
alias -l give.points { var %x = $get.score($1) + 1 | writeini -n benstriv_vars.ini PLAYERS score. $+ $1 %x | msg $2 $pointcheck($1) }

The whole if construct isn't needed, we know that $get.score always returns 0 or a number. Make sure you always use the = in var %x = something, it is part of it's syntax. Only one exception, when you compute the %varname with $identifiers, $+ etc.
I'm no fan of using | either, the moment I see a horizontal scroll bar in my editor, I work hard to get rid of it again.


Another problem with ini files is that [ and ] have special meaning, and as such are not allowed in entries. This means that nicknames with [] in can give errors... Maybe hash tables are a solution, or a small script to convert a nickname to a decent nickname.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I admit that our trivia script uses a text file for scores... but it was written by a friend and I just took it over and never bothered to change how it handled scores.

But, usually the best way to work with scores on a trivia script would be to use hash tables. Just make sure you have a timer to automatically save the table every so often in case you crash, or you'll lose the data.

Here's just a basic structure example to help you get started:

Code:
[color:green]; You should consider setting and using a variable for %trivia.channel rather than specifying the channel name all the time.
; This section will create and load and set up automatic saving of the table of scores whenever you join the channel.[/color]
on *:join:#yourchannel: {
  if ($hget(Trivia).item == $null) {
    hmake Trivia 50
    hload Trivia Trivia.Scores
  }
  if ($timer(TriviaScores) == $null) {
    .timerTriviaScores 0 30 hsave Trivia Trivia.Scores
  }
}


Ok, so now, let's look at points. Let's say you have random points per question and the points for the current question are in %points. Let's say that the winner's nick is stored in %winner. You would then insert this into your "winning" section of code:

Code:
  hinc Trivia %winner %points


When you want to see the current points, you use:

Code:
  [color:green]; Again, if you use a channel variable like %trivia.channel, you should use that instead of $chan.[/color]
  msg $chan %winner won and got %points points!  %winner now has $hget(Trivia,%winner) points!


If you want, you can do a similar idea and expand this to include week scores, month scores, and all time scores. You could do that by using three hash tables, or by putting the scores all into one. Personally, I'd prefer to use 3 different tables, but there are good and bad things about using 3 and good and bad for using 1.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard