mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2014
Posts: 36
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Jul 2014
Posts: 36
My mirc is crashing with this script here:

Remote:
Code:
on *:TEXT:!on*:#:{
  if ($nick == tylersgaming) {
    if ($read(botstatus.txt,t,1) == on) {

    }
    if ( $read(botstatus.txt,t,1) == off) {
      /write -c botstatus.txt
      /timerAward 0 1800 /awardPoints $chan
      write botstatus.txt on
      msg $chan Points will now be awarded.
    }
  }
}

on *:TEXT:!off*:#:{
  if ($nick == tylersgaming) {
    if ($read(botstatus.txt,t,1) == off) {

    }
    if ( $read(botstatus.txt,t,1) == on) {
      /write -c botstatus.txt
      write botstatus.txt off
      /timerAward off
      msg $chan Points will no longer be awarded.
    }
  }
}



Sorry, forgot to include the other part of the script.

Alias:

Code:
awardPoints {

  var %numUsers = $nick($1, 0)

  var %x = 1

  while (%x <= %numUsers ) {

    var %viewer = $nick($1, %x)

    if (%viewer != nightbot && %viewer != tylerb0t) {

      ;if viewer exists in file, add 1 to wolfcoins, otherwise add them to the 'wolfcoins' file and init at 1

      if (%viewer != tylersgaming && %viewer != tylerb0t) {

        if ( $read(viewers.txt,w,%viewer) == %viewer) { 

          var %r = $readn

          var %i = $read(wolfcoins.txt,t,%r)

          /INC %i

          /write -l $+ %r wolfcoins.txt %i

        }

        else {

          write viewers.txt %viewer

          $read(viewers.txt,w,%viewer)

          /write -l $+ $readn wolfcoins.txt 1

        }

      }

      /INC %x

    }


My mIRC only crashes when I'm streaming and when this script is in use. Let me explain what the script does so you can get a better understanding of it. Basically, this script writes too two text files, one of them being the users points, and the other is the names. I have a c+ program that complies both txt files into a spreadsheet so I know which names the points belong too. I just need a different to write to txt files I guess? All help is appreciated.

I would appreciate if someone could rewrite this so it does the same thing but puts less strain on mIRC. Can't wait to see what you guys come up with. XD

Last edited by TylersGaming; 20/08/14 01:17 PM.
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
You haven't even included the part that does the work. And use the [code] tag instead of [spoiler]

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
Instead of us going through your broken code, tell us exactly what you want the code to do?


A few questions:

Whats the format of the file your C+ code creates? Can it accept CVS files?
Do you only want this script to run on your twitch channel?
Do you only want to add 1 point a minute(5pts per 5 minutes?)




Last edited by FroggieDaFrog; 20/08/14 01:00 PM.

I am SReject
My Stuff
Joined: Jul 2014
Posts: 36
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Jul 2014
Posts: 36
Originally Posted By: FroggieDaFrog
Instead of us going through your broken code, tell us exactly what you want the code to do?


A few questions:

Whats the format of the file your C+ code creates? Can it accept CVS files?
Do you only want this script to run on your twitch channel?
Do you only want to add 1 point a minute(5pts per 5 minutes?)





Spreadsheet Excel is what it gives me.

I just use IRC for racing and using a twitch bot but this script will be solely for giving points to my viewers in my twitch chat, yes.

1 point per 30 minutes.

Joined: Jul 2014
Posts: 36
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Jul 2014
Posts: 36
Originally Posted By: Loki12583
You haven't even included the part that does the work. And use the [code] tag instead of [spoiler]


Fixed.

Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
A crash is when mirc.exe is shutdown by Windows because he did an invalid operation, you cannot get back to mIRC in any way, a freeze is when you try to do a lot of stuff and it requires time to do them, but in this case mIRC will get back to a working state.

Are you experiencing a crash or a freeze?
How many lines in BOTH files at the time of the crash/freeze?
How many nickname in the channel at the time of the crash/freeze?


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2014
Posts: 36
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Jul 2014
Posts: 36
Originally Posted By: Wims
A crash is when mirc.exe is shutdown by Windows because he did an invalid operation, you cannot get back to mIRC in any way, a freeze is when you try to do a lot of stuff and it requires time to do them, but in this case mIRC will get back to a working state.

Are you experiencing a crash or a freeze?
How many lines in BOTH files at the time of the crash/freeze?
How many nickname in the channel at the time of the crash/freeze?


its a crash and I don't know, my irc just says not responding and shuts down.

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
How many users are in the channel?

Keeping data in an unordered text file is terrible for performance. Think about it. If you have 2 users, that's 3 searches/comparisons. 1 to find the first, 2 to find the second. Expand that to 100 users and it's 5,050 comparisons. Expand that to 1000 users and it's 500,500 comparisons. This is n^2 time on disk.

Using a modified version of your script I checked 100, 1000, and 2000 users and the times were 1 second, 24 seconds, and 1 minute 16 seconds respectively. This was on my ssd, I expect an hdd would be somewhat slower.

Storing the values in an ini file, loading them to a hash table, and then saving to the ini file would be much faster. With a hash table, you don't search at all. With 1000 users you get 1000 hashes, 1000 increments, and 1 file save. This is n time in memory.

Testing this out quickly, I was able to increase the values of 100,000 users in 8-12 seconds. Saving to a binary instead of an ini file I was able to do this in 5 seconds. Postponing the save for later I could update the table of 100,000 users in 3 seconds.

Code:
alias awardpoints {
  var %chan = $$1, %table = coins. $+ %chan, %file = coins.ini

  if (!$hget(%table)) {
    hmake %table
    if $ini(%file,%chan) hload -i %table %file %chan
  }

  var %i = 1, %n = $nick(%chan,0)
  while (%i <= %n) {
    hinc %table $nick(%chan,%i)
    inc %i
  }

  hdel %table nightbot
  hdel %table tylerb0t
  hdel %table tylersgaming

  hsave -i %table %file %chan
}


Ways to possibly improve on this further: Do not load the entire ini file into the table, instead only add users currently in the channel and append this table to the ini file with the -a switch. Do not save the file immediatley, save it on a timer in order to allow mIRC to process more IRC events. Play with the size of the hash table.

*For testing purposes I used a simple integer for the user name, I don't know what performance impact using $nick will have.

Quote:
its a crash and I don't know, my irc just says not responding and shuts down.

If you're told it's not responding and given the option to wait or close, that's freezing.

Last edited by Loki12583; 20/08/14 07:59 PM.
Joined: Jul 2014
Posts: 36
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Jul 2014
Posts: 36
Originally Posted By: Loki12583
How many users are in the channel?

Keeping data in an unordered text file is terrible for performance. Think about it. If you have 2 users, that's 3 searches/comparisons. 1 to find the first, 2 to find the second. Expand that to 100 users and it's 5,050 comparisons. Expand that to 1000 users and it's 500,500 comparisons. This is n^2 time on disk.

Using a modified version of your script I checked 100, 1000, and 2000 users and the times were 1 second, 24 seconds, and 1 minute 16 seconds respectively. This was on my ssd, I expect an hdd would be somewhat slower.

Storing the values in an ini file, loading them to a hash table, and then saving to the ini file would be much faster. With a hash table, you don't search at all. With 1000 users you get 1000 hashes, 1000 increments, and 1 file save. This is n time in memory.

Testing this out quickly, I was able to increase the values of 100,000 users in 8-12 seconds. Saving to a binary instead of an ini file I was able to do this in 5 seconds. Postponing the save for later I could update the table of 100,000 users in 3 seconds.

Code:
alias awardpoints {
  var %chan = $$1, %table = coins. $+ %chan, %file = coins.ini

  if (!$hget(%table)) {
    hmake %table
    if $ini(%file,%chan) hload -i %table %file %chan
  }

  var %i = 1, %n = $nick(%chan,0)
  while (%i <= %n) {
    hinc %table $nick(%chan,%i)
    inc %i
  }

  hdel %table nightbot
  hdel %table tylerb0t
  hdel %table tylersgaming

  hsave -i %table %file %chan
}


Ways to possibly improve on this further: Do not load the entire ini file into the table, instead only add users currently in the channel and append this table to the ini file with the -a switch. Do not save the file immediatley, save it on a timer in order to allow mIRC to process more IRC events. Play with the size of the hash table.

*For testing purposes I used a simple integer for the user name, I don't know what performance impact using $nick will have.

Quote:
its a crash and I don't know, my irc just says not responding and shuts down.

If you're told it's not responding and given the option to wait or close, that's freezing.


Does this use textfiles? I will prob have to rewrite the c+ program if this doesn't make text files, can you walk me through the steps, I'm still kind of confused on what to do with this. ;-;

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
I was missing the parens in an if statement, use this:
Code:
alias awardpoints {
  var %chan = $$1, %table = coins. $+ %chan, %file = coins.ini

  if (!$hget(%table)) {
    hmake %table
    if ($ini(%file,%chan)) hload -i %table %file %chan
  }

  var %i = 1, %n = $nick(%chan,0)
  while (%i <= %n) {
    hinc %table $nick(%chan,%i)
    inc %i
  }

  hdel %table nightbot
  hdel %table tylerb0t
  hdel %table tylersgaming

  hsave -i %table %file %chan
}


It's a replacement for your existing alias. It takes the channel name as input, and as output you get an ini file with the channel as the section name. It does not use plain text files. Those were the problem. Maybe you can loop over the hash table at the end and write to plain text instead of ini, but altering the c++ would probably make more sense.

To convert your existing point structure to ini you'll need to loop over both files and use writeini, or add them to the hash table and save it when you're done.

/help hash tables
/help writeini

Last edited by Loki12583; 21/08/14 11:49 AM.
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Quote:
Keeping data in an unordered text file is terrible for performance.
The problem isn't that the data was unordered, hash tables are unordered as well.
Hash tables are associative arrays, that's the important part which explains why it's so fast compared to his text file routine, because the data is already associated with the nickname, there's no need to browse 2000 lines for 2000 entries for nothing, you already know which line it is (basically).

@OP: it's better to keep the hash table; if you need two text files for excel, you should keep that hash table and makes a new function, which will extract the data in two different text file from the hash table, that function can be slow, it's only used manually by you, shouldn't be a problem.
And you still didn't clarify, is mIRC freezing (it shows 'not responding' in the titlebar, eventually windows reports that the program is not responding and ask you to close it but you can always click 'wait' here) or is mIRC crashing (mirc.exe is shutdown and you can't see the mIRC main window, you can't see anything but eventually windows reporting that the application crashed)
Getting a freeze is normal, getting a crash is not, regardless of how bad your script can be, if you see a crash your should report it.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2014
Posts: 36
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Jul 2014
Posts: 36
Originally Posted By: Wims
Quote:
Keeping data in an unordered text file is terrible for performance.
The problem isn't that the data was unordered, hash tables are unordered as well.
Hash tables are associative arrays, that's the important part which explains why it's so fast compared to his text file routine, because the data is already associated with the nickname, there's no need to browse 2000 lines for 2000 entries for nothing, you already know which line it is (basically).

@OP: it's better to keep the hash table; if you need two text files for excel, you should keep that hash table and makes a new function, which will extract the data in two different text file from the hash table, that function can be slow, it's only used manually by you, shouldn't be a problem.
And you still didn't clarify, is mIRC freezing (it shows 'not responding' in the titlebar, eventually windows reports that the program is not responding and ask you to close it but you can always click 'wait' here) or is mIRC crashing (mirc.exe is shutdown and you can't see the mIRC main window, you can't see anything but eventually windows reporting that the application crashed)
Getting a freeze is normal, getting a crash is not, regardless of how bad your script can be, if you see a crash your should report it.


Can you help me put my text data into a hash table? I can give you my skype.

and it was freezing.

Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Code:
alias converting {

set -u %chansection $1
set -u %scorefile wolfcoins.txt
filter -ffkn viewers.txt convert.cb
}
alias convert.cb writeini -n coins.ini %chansection $gettok($1,2,32) $read(%scorefile,tn,$gettok($1,1,32))
This should convert to coins.ini, type /converting <channel>, you now have a multi-channel script, a number of point is now per nick but also per channel.


Ps: that alias is an example illustrating why /var -gu would be useful

Last edited by Wims; 21/08/14 06:43 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2014
Posts: 36
T
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Jul 2014
Posts: 36
Okay so I have mIRC create an ini file with my information instead of the 2 text files.

Now can anyone help me code c+ to create an excel spreadsheet because my old one doesn't work now.

Code:
#include <iostream>

#include <fstream>

#include <string>

#include <vector>

#include <windows.h>



using namespace std;



int getNumLines(ifstream file);



struct viewer

{

	string name;

	int score;

};



void main()

{

	vector<viewer> viewerList;



	//read in viewers and add to viewer vector

	ifstream viewers("C:\\Users\\TylersGaming\\AppData\\Roaming\\mIRC\\viewers.txt");

	string readString = "";

	if (viewers.is_open())

	{

		while (getline(viewers, readString))

		{

			viewer tempViewer;

			tempViewer.name = readString;

			viewerList.push_back(tempViewer);

		}

	}



	//read in scores and add to viewer vector

	ifstream viewerscores("C:\\Users\\TylersGaming\\AppData\\Roaming\\mIRC\\wolfcoins.txt");



	if (viewerscores.is_open())

	{

		int i = 0;

		while (getline(viewerscores, readString))

		{

			char buffer[256];

			for (int j = 0; j < readString.size(); j++)

			{



				buffer[j] = readString[j];

			}

			viewerList[i].score = atoi(buffer);

			i++;

			memset(buffer, 0, 256);



		}

	}



	//sort highest to lowest

	for (int k = 0; k < viewerList.size(); k++)

	{

		for (int f = 0; f < viewerList.size(); f++)

		{

			if (viewerList[k].score > viewerList[f].score && k > f)

			{

				viewer temp = viewerList[f];

				viewerList[f] = viewerList[k];

				viewerList[k] = temp;

			}

		}

	}



	ofstream output;

	output.open("C:\\Users\\TylersGaming\\Dropbox\\Points.csv");

	//output << "Name,Score" << endl;

	for (int r = 0; r < viewerList.size(); r++)

	{

		output << viewerList[r].name << "," << viewerList[r].score << endl;

	}

	output.close();



	cout << viewerList.size() << " entries processed.\n";

	cout << "Highest viewer score: " << viewerList[0].score << "\n";



	Sleep(5000);



	return;

}

Last edited by TylersGaming; 22/08/14 03:38 AM.
Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Use mIRC, you don't need any C++ crap at all:
Code:
alias display_Points {
  if ($isid) aline @Points $gettok($1,1,61) $+ $chr(9) $+ $gettok($1,2,61)
  else {
    window -hMd -t80,50 @Points
    noop $read(coins.ini,tnw,$+([,$1,]))
    var %n $readn + 1,%n2 %n + $ini(coins.ini,$1,0)
    filter -fkrtue $+(%n,-,%n2) 2 61 coins.ini display_Points *
    window -a @Points
  }
}
Type /display_points <channel>


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
He's using the csv file to create a chart in excel

Joined: Jul 2006
Posts: 4,149
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Right, I didn't bother reading the code, at the end of the code, he can use /savebuf to save the content of the window to a file, then he can /bread that file into a binvar and use /breplace to replace all occurence of $chr(9) by a $chr(44) smile

Code:
alias display_Points {
  if ($isid) aline @Points $gettok($1,1,61) $+ $chr(9) $+ $gettok($1,2,61)
  else {
    window -hMd -t80,50 @Points
    noop $read(coins.ini,tnw,$+([,$1,]))
    var %n $readn + 1,%n2 %n + $ini(coins.ini,$1,0)
    filter -fkrtue $+(%n,-,%n2) 2 61 coins.ini display_Points *
    window -a @Points
    savebuf @Points Points.csv
    bread Points.csv 1 $lof(Points.csv) &a
    .remove Points.csv
    breplace &a 9 44
    bwrite Points.csv -1 -1 &a
  }
}

Last edited by Wims; 22/08/14 06:21 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard