mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jun 2011
Posts: 5
W
Whazzaa Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
W
Joined: Jun 2011
Posts: 5
Hello

I'm not that familiar with mirc scripting but trying to learn it.

I have a script that saves data into multiple text files.
Let's say, user A has gained 234 and 345 points - instead of showing those separately (in x-file 234 points and in y-file 345 points) it would calculate them together so it would display user A gained 579 points in z-file.

So, what I understand, the script should read the data in both files, match the nick from both files and calculate the points together. The way the points are currently saved is: points nick.

Possible? Thanks.

Joined: Mar 2010
Posts: 146
Vogon poet
Offline
Vogon poet
Joined: Mar 2010
Posts: 146
Yes, it depends on the format that you saved the files. There are several ways to read the data from file.

  1. If you have saved the file in INI format you can use $readini() - syntax: $readini(File.ini,TopicName,ItemName) which can be $readini(File.ini,$chan,$nick)
  2. Using $read() and reading the file line by line and match the data
  3. Using File Handling which is similar to $read() but this is so faster.
  4. Using /filter

You may read the help file about each of these and ask your possible questions here and we will assist you.


Nothing...
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Is there a specific reason that you need so many text files? I'm sure what you are doing could be done with a single file.


Invision Support
#Invision on irc.irchighway.net
Joined: Jun 2011
Posts: 5
W
Whazzaa Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
W
Joined: Jun 2011
Posts: 5
Well yes, most likely all the scores could be saved in a single file. Currently the scores from different areas are saved in different files and in the end all the scores are saved into one final file.

These few files I'm talking about track the score of almost same things so it would be easiest to put them together and see who did the best overall in those.

But ye, thanks Masoud, I'll see what I can come up with.

Last edited by Whazzaa; 14/06/11 01:27 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Have you considered using hash tables? Scores are generally updated regularly and hash tables are very good for regularly updated data. They can then be easily saved to a file (or files for multiple tables). For sorting, it's very easy to sort hash tables into numerical order (for top scores or whatever) by saving the data to a file and using /filter to sort it.

Because you already have a system set up for saving scores, I won't write up a hash table example. But if you decide you'd like to try that instead for your scores and want some help with it, just let me know.


Invision Support
#Invision on irc.irchighway.net
Joined: Jun 2011
Posts: 5
W
Whazzaa Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
W
Joined: Jun 2011
Posts: 5
The scores don't need to be updated regulary, only when needed. Like for example, who gets most points within 1 hour. I don't think hash tables would be the right choice for that. Also I'm that new to mirc scripting I haven't experienced them at all.

What comes to counting, so far no good. I fixed few bugs that made the script not to work. I managed to do that myself. I looked into those four options Masound said and I think $read would be the right choice here. However, I'm struggling how to match the data. I'm quite good when it comes to editing something already there but writing something new... I need to learn mirc scripting a lot more (at least personally I feel like: "ohh man, how am I supposed to make this work... *headache* "). :S

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Depending on how you format your data, just use $read() with the s or w parameter to search for the line with the right nick in all files and add the values together (possibly using $gettok() depending on how your data is formatted).

Basic example that would need adjusted based on your data:
Code:
alias AddScores {
  return $calc($read(file1.txt,snt,$1) + $read(file2.txt,snt,$1))
}


Use: //echo -a $addscores(somenick)

Of course, you don't have to put that return line into an alias. You can replace return with /var or /set or /msg or whatever and stick it into the rest of your script. This is just an example that can be shown without knowing any of the rest of your script. Also, this assumes that data is in this format:

nick score

Btw, seeing who gets the most points in an hour is checking data, not updating data. Updating data would be adding new scores for the person. The combination of how often data is added + how often data is checked would be used to decide if something is accessed often or not.


Invision Support
#Invision on irc.irchighway.net
Joined: Jun 2011
Posts: 5
W
Whazzaa Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
W
Joined: Jun 2011
Posts: 5
Oki thanks. The data is in format:

score nick

from highest score to lowest.
I played with your example and below is the code how I got it somewhat working so I think it's getting close.

Code:
var %USERtotal $calc($read(file1-temp.txt,w,* $1) + $read(file2-temp.txt,w,* $1))
  if (%USERtotal != 0) { write $tempfiles(total) %USERtotal %nick }

It reads the data from both files (1 and 2) but if user has gained points in both files it only grabs the points from file1. Also, it doesn't count the points together so.. what needs to be changed/added?

Thanks for your help.

Last edited by Whazzaa; 17/06/11 02:28 PM.
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Right now, you are reading in "score nick". You can't add those together because nick isn't a number. You will need to get just the part you need...

Code:
var %USERtotal = $calc($gettok($read(file1-temp.txt,w,* $1),1,32) + $gettok($read(file2-temp.txt,w,* $1),1,32))


Invision Support
#Invision on irc.irchighway.net
Joined: Jun 2011
Posts: 5
W
Whazzaa Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
W
Joined: Jun 2011
Posts: 5
Ahhhh... My bad. I totally forgot the $gettok() you mentioned. Well, you learn from mistakes. Working now, thanks for your patience and help. smile


Link Copied to Clipboard