mIRC Home    About    Download    Register    News    Help

Print Thread
/hmake -s <name> <N> <file> #232155 21/05/11 09:38 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Originally Posted By: "/hmake -s <Name> <N> <File>"

When the table is made:
  • Load file to table if file exists.
  • ELSE still create table but error message in status that file doesn't exist.
  • If this hash table gets closed, save to filename.
  • If 2nd parameter is not a number, then table is default size and 2nd parameter is treated as file path.

Maybe don't auto save if table is closed by script command /hfree, but save if disconnected or exit, etc.


What do you think? This sounds reasonable and beneficial, doesn't it?

Re: /hmake -s <name> <N> <file> [Re: DJ_Sol] #232159 21/05/11 10:49 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
About the only thing I see useful there is an auto-save on disconnect/exit. However, that's also very easy to code.


Invision Support
#Invision on irc.irchighway.net
Re: /hmake -s <name> <N> <file> [Re: Riamus2] #232160 21/05/11 10:51 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
It saves having to code loading each saved hash table and saving each hash table.

Re: /hmake -s <name> <N> <file> [Re: DJ_Sol] #232162 22/05/11 01:22 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
That's so easy to do and doesn't take much code that it's not really worth adding a new switch, imo.


Invision Support
#Invision on irc.irchighway.net
Re: /hmake -s <name> <N> <file> [Re: DJ_Sol] #232163 22/05/11 01:58 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Code:
on *:start:{
  if (!$hget(table)) hmake table 60
  if ($file(lists\table.txt).shortfn) hload table $qt($ifmatch)
}
alias h_save {
  if ($hget(table)) hsave -o table lists\table.txt
}
on *:exit:h_save
on *:disconnect:h_save
on me:*:quit:h_save


Add 3 lines for every additional hash table or make a list with a loop. Sure it's manageable, I just thought it would be nice and possibly not too difficult to have mIRC handle loading & saving hash tables.

Re: /hmake -s <name> <N> <file> [Re: DJ_Sol] #232164 22/05/11 03:02 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
So make a custom hsave alias that does it if you have many tables to work with. One short alias can do all of that regardless of the number of tables.


Invision Support
#Invision on irc.irchighway.net
Re: /hmake -s <name> <N> <file> [Re: Riamus2] #232166 22/05/11 06:09 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Maybe you can stop trying to shit on my idea which is perfectly reasonable and logical.

Re: /hmake -s <name> <N> <file> [Re: DJ_Sol] #232167 22/05/11 07:11 AM
Joined: Apr 2010
Posts: 959
F
FroggieDaFrog Offline
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 959
I'm with Riamus2 on this one.

Mainly because to do what you wish to do can be easily scripted. The overhead of keeping track of which tables need to be saved to what files and when is best left to scripting rather than added switches to a currently existing command.


I am SReject
My Stuff
Re: /hmake -s <name> <N> <file> [Re: DJ_Sol] #232168 22/05/11 09:21 AM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Create a directory called "Hashtables" in your script's directory (or modify the $hashdir identifier) and use this:

Code:
alias -l hashdir { return $scriptdirHashtables\ }
alias -l _hload {
  if (nli_* !iswm $nopath($1-)) {
    var %hash = $nopath($deltok($1-,-1,46))
    if (!$hget(%hash)) { hmake %hash 50 }
    hload %hash $qt($1-)
  }
}

alias hloadall { noop $findfile($scriptdirHashtables\,*.hsh,0,_hload $1-) }
alias hsaveall {
  if (!$isdir($hashdir)) { mkdir $qt($hashdir) }
  var %i = 1, %hash
  while ($hget(%i)) {
    %hash = $v1
    if (tmp_* !iswm %hash) { hsave %hash $qt($+($hashdir,$mkfn(%hash),.hsh)) }
    inc %i
  }
}

on *:start:{ hloadall }
on *:exit:{ hsaveall }


Easy peasy. No modification of the script required. A lot of the time even though it's easier to script initially, hard coding things creates more work for you in the long run. You may as well just use a script like the one above to have everything done automatically.

If you want to create a table that doesn't get saved, just call it "tmp_<something>" (which stands for temporary)

If you want to create a table that is saved, but not loaded on start, then just call it "nli_<something>" (not loaded initially)

Re: /hmake -s <name> <N> <file> [Re: DJ_Sol] #232171 22/05/11 01:59 PM
Joined: Jul 2006
Posts: 3,764
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,764
I like the "load" suggestion, but it shouldn't be implemented with /hmake, rather /hload: we have hadd -m, why not having hload -m ?

I'm not sure why someone would want that but creating an hashtable and reporting an error for the same command isn't consistent etc, it wouldn't help people, rather confuse them.

And about auto saving the file, /hsave could indeed have a new switch, but when would it save the data, after each modification ? only when exiting mirc (remember an hash table isn't related to a connection) ? a switch for each behavior ?


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: /hmake -s <name> <N> <file> [Re: DJ_Sol] #232177 23/05/11 01:44 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
About the:
Quote:
on *:disconnect:h_save
on me:*:quit:h_save
they're not really necessary, because the hash tables can only be lost when mIRC is exited or closed. An exit event should take care of the tables to be saved. Like hixxy has shown, two events needed are basically the start and exit.

Last edited by Tomao; 23/05/11 01:46 AM.
Re: /hmake -s <name> <N> <file> [Re: Tomao] #232180 23/05/11 10:17 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Personally, I prefer saving tables when they change instead of when you exit. That way, if mIRC or Windows ever crashes, your data is still saved. But, if the data isn't that important, then on exit is fine.


Invision Support
#Invision on irc.irchighway.net
Re: /hmake -s <name> <N> <file> [Re: Riamus2] #232182 23/05/11 11:16 AM
Joined: Jul 2007
Posts: 1,129
T
Tomao Offline
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,129
Originally Posted By: Riamus2
Personally, I prefer saving tables when they change instead of when you exit. That way, if mIRC or Windows ever crashes, your data is still saved.
I always thought the change would take effect immediately when the new data is stored, which overwrites the old one.

Last edited by Tomao; 23/05/11 11:18 AM.
Re: /hmake -s <name> <N> <file> [Re: Tomao] #232183 23/05/11 02:06 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
It isn't saved until you do the command hsave.

Where does my suggestion say that you cant save your hash table whenever you feel like it?

The idea is you /hmake your table. If there is a file associated with the hash table it loads it. If there is an error with loading the file the hash table is still made, since the /hmake syntax was correct, but an error can be put in the status window. IF YOU DONT LIKE THE ERROR USE .hmake like you do with all the other ones you dont like.

After this mIRC does nothing unless the table gets closed by methods other than the /hfree command.

Yes with mIRC there are thousand ways to do the same thing. Yes you can write a handfull of code to handle this, but as you add hash tables the code grows.

I'm surprised that there is so much opposition to this since it wouldn't change your experience whatsoever EXCEPT that if you happened to want mirc to handle the loading and saving of your hash table, you just have to add the filename to the /hmake command.

If you used the command this way you wouldn't have to worry about saving your hash table after every entry since mIRC would make sure, unless there was a bad error or loss of power, etc, that your hash table is saved when it is closed.

Re: /hmake -s <name> <N> <file> [Re: DJ_Sol] #232184 23/05/11 02:57 PM
Joined: Dec 2002
Posts: 344
D
drum Offline
Pan-dimensional mouse
Offline
Pan-dimensional mouse
D
Joined: Dec 2002
Posts: 344
Personally I see the value in what you are proposing. It's just a matter of making hash tables easier to use. I don't personally subscribe to the opinion that anything that can be scripted easily should not be implemented directly into mIRC.

Regarding the error message: I think the main reason for opposition to that is because of calling it an "error". I wouldn't call it an error -- it's just a notification that the file was created because it didn't exist. It's like if you use /write with a file that doesn't exist, that doesn't give you an error. It just automatically creates the file for you.

Re: /hmake -s <name> <N> <file> [Re: DJ_Sol] #232186 23/05/11 05:57 PM
Joined: Sep 2005
Posts: 2,881
H
hixxy Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Just to let you know, I wasn't opposing your idea, just showing a script that can manage hashtables on your behalf in the meantime smile

Re: /hmake -s <name> <N> <file> [Re: DJ_Sol] #232207 23/05/11 10:12 PM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
And I didn't say that your suggestion said a person couldn't save whenever they wanted. I was replying to Tomao, not you. smile


Invision Support
#Invision on irc.irchighway.net
Re: /hmake -s <name> <N> <file> [Re: drum] #232329 30/05/11 03:44 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Ok cool, I misunderstood, sorry. smile

Yeah I get you Hixxy, it's just the point of this post was to do away with that code and to not have to write 5 or more lines of code if I wanted to use a hash table.

@Drum: Good point. I think that's a better idea. If the file doesn't exist mIRC wouldn't hload the table, but hsave it to that file name when it closed.

I proposed the error/notice message because it's a lot easier and faster to just write an error and halt than to manage errors and work around them. I figured the more intricate and detailed the request got, the less chance of actually seeing it in a future version of mIRC.