mIRC Home    About    Download    Register    News    Help

Topic Options
#174357 - 06/04/07 03:09 PM search and del script
chump Offline
Ameglian cow

Registered: 24/09/06
Posts: 35
hi i am after a lil script that when sum1 types for example
!addnewquote sweet monkey
it adds to a txt file i have called quotes.txt but if it already exists it msg chan it already exists

also the abilty to del a quote such as
!delquote sweet monkey and again it msg chan quote deleted

any help would be much appreciated..thx guyz

Top
#174361 - 06/04/07 05:45 PM Re: search and del script [Re: chump]
Spitfire3292 Offline
Babel fish

Registered: 28/03/07
Posts: 60
Loc: MD, United States
Just the simple use of /write and $read

Code:
on *:TEXT:!addnewquote *:#:{
if ($read(quotes.txt,w,$2-)) { msg $chan This quote already exists!
halt
}
else {
/write quotes.txt $2-
msg $chan The Quote has been successfully added.
}
}

on *:TEXT:!delquote *:#:{
if (!$read(quotes.txt,w,$2-)) { msg $chan This quote doesn't exist!
halt
}
else {
/write -ds $+ $2-
msg $chan The Quote has been successfully deleted.
}
} 
_________________________
"In order to succeed, your desire for success should be greater than your fear of failure."

Top
#174365 - 06/04/07 06:40 PM Re: search and del script [Re: Spitfire3292]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
Don't HALT a script if you don't need to. Also, don't use HALT unless you're trying to halt everything that happens... use RETURN instead.

Also, you forgot the filename in the delete section and $readn works fine to avoid another search of the file.

Code:
on *:TEXT:!addnewquote *:#:{
  if ($read(quotes.txt,w,$2-)) {
    msg $chan This quote already exists!
  }
  else {
    write quotes.txt $2-
    msg $chan The Quote has been successfully added.
  }
}

on *:TEXT:!delquote *:#:{
  if (!$read(quotes.txt,w,$2-)) {
    msg $chan This quote doesn't exist!
  }
  else {
    write -dl $readn quotes.txt
    msg $chan The Quote has been successfully deleted.
  }
} 
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#174381 - 06/04/07 11:27 PM Re: search and del script [Re: Riamus2]
chump Offline
Ameglian cow

Registered: 24/09/06
Posts: 35
thx guys just what i was looking 4 smile

just out off interest how would you do it using ini file insteas of txt file?

Top
#174382 - 07/04/07 12:13 AM Re: search and del script [Re: chump]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
You wouldn't want to use an INI file for quotes. That's not a good format for them.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#174384 - 07/04/07 12:14 AM Re: search and del script [Re: Riamus2]
Kardafol Offline
Fjord artisan

Registered: 08/01/07
Posts: 259
You could do it with a hash table, however that would mean that mIRC would use loads of memory if there are a lot of quotes.
_________________________
Those who can, cannot. Those who cannot, can.

Top
#174385 - 07/04/07 12:17 AM Re: search and del script [Re: Kardafol]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
And there wouldn't be a performance improvement, so there's no need. Hash tables should only be used for data that is being used frequently. Quotes aren't generally used very often.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#174387 - 07/04/07 12:23 AM Re: search and del script [Re: Riamus2]
Kardafol Offline
Fjord artisan

Registered: 08/01/07
Posts: 259
There should be a slight performance improvement, however you probably won't notice it (memory access time VS HDD seek + read). wink
_________________________
Those who can, cannot. Those who cannot, can.

Top
#174403 - 07/04/07 03:52 AM Re: search and del script [Re: Kardafol]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
And at the same time, an increase in unnecessary memory usage. In the end, your system's performance will drop (insignificantly, of course, but it's still a drop due to increased memory usage) for the entire time the script is running just to gain a once-in-a-great-while insignificant performance increase in the script.

It's miniscule from the standpoint of the system and the script. What's a few milliseconds difference in a script that's called once every few hours or even days on average? There's not point wasting memory over something like that.

Invision is like that... it has a lot of hash tables that are nothing but settings that are checked rarely. It causes Invision to take 3-5% CPU resources instead of mIRC's typical 0%. That's something I need to work on... replacing many of the hash tables with normal settings file reads/writes.

Hash tables should be used when they can improve performance on items that run regularly. For things that run very rarely, hash tables are a waste of resources unless you're going to unload them after use. And I'm sure that loading the table, checking it, then unloading it will take longer than just reading a settings or quote file once every few hours or few days.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#174478 - 08/04/07 03:01 PM Re: search and del script [Re: Riamus2]
sdgsgsdgsgsd Offline
Nutrimatic drinks dispenser

Registered: 07/04/07
Posts: 8
on *:text:!*quote*:#:{ quotehandle $1- }
on *:input:*:{ quotehandle $1- }
alias quotehandle {
if $1 == !quote {
var %n = $iif($2 isnum,$2,$rand(1,$lines(quotes.txt)))
msg $chan %n $+ . $read(quotes.txt,%n)
}
if $1 == !addquote && $2 { write quotes.txt $2- | msg $chan Quote added! }
if $1 == !delquote && $2 isnum { write -dl $+ $2 quotes.txt | msg $chan Quote $2 deleted! }
if $1 == !quotes { msg $chan $calc($lines(quotes.txt)) quotes in database! }
if $1 == !quotesearch { msg $chan $iif($read(quotes.txt, w, * $+ $2- $+ *),$ifmatch,No matches) }
}

Top
#174549 - 09/04/07 05:30 PM Re: search and del script [Re: sdgsgsdgsgsd]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
A few things...

First, use ELSEIF instead of repeated IF's for something like that. Second, you don't need $calc when getting $lines. Third, you don't need $+ after -dl and before $2. Just -dl $2 is fine.

And I'd suggest some form of error checking. If someone types the command incorrectly, the script won't do anything and he/she will not know why it's not working without some form of error message.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top