www.IRC-Junkie.org Forum Index
Advanced Scripting Tips - by Yochai Timmer
Goto page 1, 2??Next
?
Post new topic???Reply to topic ???www.IRC-Junkie.org Forum Index -> Articles
View previous topic :: View next topic ?
Author Message
Asmo
Site Admin


Joined: 26 Oct 2004
Posts: 663
Location: Undernet

PostPosted: Sat May 07, 2005 2:02 pm?? ?Post subject: Advanced Scripting Tips - by Yochai Timmer Reply with quote

Discuss the article Advanced Scripting Tips - by Yochai Timmer here.
_________________
Asmo

webmaster www.IRC-Junkie.org


Last edited by Asmo on Mon Aug 08, 2005 11:23 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website



katsklaw



Joined: 03 Nov 2004
Posts: 128
Location: irc.nfinate-irc.org

PostPosted: Sat May 07, 2005 3:12 pm?? ?Post subject: Reply with quote

I'd like to add to this if I may.

One tip is that you should use portable code as often as possible. Portable meaning it's reusable elsewhere. The below example is portable, I can search any file for any text, not just the file that I originally wrote it for and $listmatchs becomes a custom identifier.

Code:

alias listmatches {
? var %_i 1
? var %_f $1
? var %_w $2-
? while (%_i <= $lines(%_f)) {
? ? return $read(%_f,w, %_w, %_i)
? ? inc %_i
? }
}




Second tip is the use if $iif where ever possible. This not only reduces the number of lines in your scipt but the number of characters as well, making your code as small as possible.

Code:

$iif(!%_var,do this,do that)


versus

Code:


if (%_var == $null) {
? ? ? do this
else {
? ? ? do that
?}
}


Both examples above do the exact same thing yet the first is much smaller.

There is literally an endless supply of tips on being a better scripter but I think 2 is enough for now Wink


Last edited by katsklaw on Sat May 07, 2005 5:34 pm; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
Yochai



Joined: 31 Mar 2005
Posts: 5

PostPosted: Sat May 07, 2005 5:15 pm?? ?Post subject: Reply with quote

I've already mentioned using the /var command (it's like using /set -l but shorter.):

Quote:

Use only local variables with the /var command instead of /set or just %var = value.
Remember that if the user has a full script, it might have used most of the common variable names you would like to use.
Because of this, remember to create the variable before you do a Boolean check on it, example:

_________________
#mirc
Undernet
Back to top
View user's profile Send private message
katsklaw



Joined: 03 Nov 2004
Posts: 128
Location: irc.nfinate-irc.org

PostPosted: Sat May 07, 2005 5:31 pm?? ?Post subject: Reply with quote

my apologies.
Back to top
View user's profile Send private message Visit poster's website
mite



Joined: 30 Oct 2004
Posts: 107

PostPosted: Sun May 08, 2005 10:26 am?? ?Post subject: Reply with quote

Good tutorial for newbies. However I disagree with the following:

Yochai wrote:
Don't use the | separator !


Would you rather

Code:
alias 123 {
? echo -at 1
? echo -at 2
? echo -at 3
}
OR
Code:
alias 123 { echo -at 1 | echo -at 2 | echo -at 3 }


?

| is great for small aliases like this.
Back to top
View user's profile Send private message
Asmo
Site Admin


Joined: 26 Oct 2004
Posts: 663
Location: Undernet

PostPosted: Sun May 08, 2005 10:29 am?? ?Post subject: Reply with quote

Its a very black & white world for some, isnt it, ... mite? :P
_________________
Asmo

webmaster www.IRC-Junkie.org
Back to top
View user's profile Send private message Visit poster's website
mite



Joined: 30 Oct 2004
Posts: 107

PostPosted: Sun May 08, 2005 10:30 am?? ?Post subject: Reply with quote

Also, I like using $iif like this...

Code:
on *:load:{ $iif($version != 6.16,return) }


You don't even need the $false param Smile
Back to top
View user's profile Send private message
SebDE



Joined: 30 Oct 2004
Posts: 34

PostPosted: Sun May 08, 2005 12:03 pm?? ?Post subject: Re: Advanced Scripting Tips - by Yochai Timmer Reply with quote

Yeah yeah the old story about | ... I don't comment on that any further :p

Maybe I overread it, cause there isn't much new for me :rolleyes: but I don't saw any hint that variables created with var are fully local and can contain an other value than a global variable with the same name...

Quote:
Code:
If ($4) && ($5) { }
Uh I wonder why is this even work at all :S
Well anyway setting braces in an if statement speed things up... & setting some around the whole statement is part of that ;)

Only a little story about to less braces... (in conjunction with var):
(It's not against var or leaving the { } for a single cmd away, it's about setting ( ) for every statement in if constructs! ;) )
Code:

alias /test {
? set %test global
? if ((!$2) && $1 == doh) var %test = local
? echo -a %test
? unset %test
}

This will only work with ($1 == doh) or with { var %test = local } ;)

(I didn't reported this, so don't expect it to be gone in the next version :) )

Well I really having problems to describe the good things in my comments... It's not that isn't a nice tutorial after all ;)
_________________
IRC is an Addiction with No cure
Back to top
View user's profile Send private message
katsklaw



Joined: 03 Nov 2004
Posts: 128
Location: irc.nfinate-irc.org

PostPosted: Sun May 08, 2005 4:02 pm?? ?Post subject: Reply with quote

Unfortunately what one scripter thinks or believe is best is countered by at least 1 other. The tutorial says /var is better than using /set -l for local %vars. Personally I don't see any problems with set, I've used /set -l since it was added to mIRC. yes, "/var %var = blah" is 1 character shorter than "/set -l %var blah" but does that really make it better? Is it best for me to change a 10 year old habit so i can save 100 characters?

Same is true with doctors, that's why we get second opinions. Doctor X says eggs are not healthy. Doctor Y says rubbish! eggs are the healthiest thing in the world next to potatoes!. Sadly for us .. both have an armory of proof.

I think what makes a tutorial good is it's an attempt to teach someone something. Not tell you what's "better".


Remember, beauty in in the eye of the beer holder.

------------------------------------------------------------------------------------
PS: mite, you don't need a $true either ;P

Code:

$iif(%var,,run like hell!)


it looks like crap and could be written differently .. but it works!


Last edited by katsklaw on Thu May 12, 2005 9:25 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Fenris_Wolf



Joined: 02 Feb 2005
Posts: 6

PostPosted: Thu May 12, 2005 1:54 am?? ?Post subject: Reply with quote

nice tutorial.....
I disagree with not using | expecially when theres lots of lines.....sure it may make the code more confusing, but thats why I dont use the | until I'm finished with that peice of code...then I compress onto one line with |
If I ever need to edit that code again, I remove the |'s
If you have 30 aliases with 10 lines each...thats 300 lines you need to go through to find the alias you're working on. If you've used | and compressed them to one line each....you only need to look through 30 lines to find the alias (yes I'm aware there is a "find" button...but it makes it easier on the eyes)
as for the /var vs. /set commands......../var's are created locally, and run in the system's memory (assuming Khaled coded mirc properly).../set variables however, are stored in a file (remotes.ini) and each time it sets or read that variable, it needs to open the file, then find the line it's looking for, using even more resources. Rarely do I use /set....only when the information is needed to be saved....even when passing to another alias, I'd rather use a /var and pass it like so..... /alias.being.called %var....and have the %var become $$1
but hey...good work on the tutorial...expecially the section on optimizing for speed.. Very Happy
Back to top
View user's profile Send private message
katsklaw



Joined: 03 Nov 2004
Posts: 128
Location: irc.nfinate-irc.org

PostPosted: Thu May 12, 2005 7:07 am?? ?Post subject: Reply with quote

Quote:

as for the /var vs. /set commands......../var's are created locally, and run in the system's memory (assuming Khaled coded mirc properly).../set variables however, are stored in a file (remotes.ini) and each time it sets or read that variable, it needs to open the file, then find the line it's looking for, using even more resources.


When you use the -l (lower case L) switch in set it makes the %var local .. just like /var. Smile If you have a small script like mine (62k), then there isn't a notable size difference because I don't use alot of %vars.

Both the following are local %vars. The only difference is that /set -l is 1 character longer.

Code:

/var %var = blah
/set -l %var blah
Back to top
View user's profile Send private message Visit poster's website
SebDE



Joined: 30 Oct 2004
Posts: 34

PostPosted: Fri May 13, 2005 12:38 pm?? ?Post subject: Reply with quote

Fenris_Wolf wrote:
I disagree with not using | ...
Please don't start this endless discussion in an IRC related forum... Wouldn't you agree that there is enough of such discussion already elsewhere? ;)
Quote:
If you have 30 aliases with 10 lines each...thats 300 lines you need to go through to find the alias
That's a joke isn't it?
Quote:
(yes I'm aware there is a "find" button...but it makes it easier on the eyes)
oh thank god
Quote:
in the system's memory
omg I hope you mean in the memory mIRC allocated... :D
Quote:
(assuming Khaled coded mirc properly)
I doubt that...
...Khaled need to code (the whole) mIRC properly for that :rolleyes:
*scnr*
Quote:
/set variables however, are stored in a file (remotes.ini) and each time it sets or read that variable, it needs to open the file
Ok enough of that sarcasm stuff, not even Khaled would do that without caching ;)
Ok maybe in 0. or 1. versions it was that way, but do you've watched the file changes of the ini where the global variables are saved? Yeah obviously not - it's updated about all 10secs or so and only if any variable has changed... ;)
Quote:
then find the line it's looking for, using even more resources.
Well despite of that global vars are usually more in count, I doubt that global variables arn't organized in any tables to easy look them up.
_________________
IRC is an Addiction with No cure
Back to top
View user's profile Send private message
Fenris_Wolf



Joined: 02 Feb 2005
Posts: 6

PostPosted: Fri May 13, 2005 5:12 pm?? ?Post subject: Reply with quote

SebDE:
on the global variables, your right, I did error there. (btw...the update time seems longer then 10 seconds).
and no, that wasnt a joke....I'd much rather open my scripts and beable to see all the aliases in there at a glance, without having to use the find button.
Quote:

Please don't start this endless discussion in an IRC related forum.

I have no intention of starting a endless discussion ANYWHERE.
I have better things to do with my time Smile
however, I thought the whole point of this thread was to comment on the tutorial, and things we agreed with, or disagreed with. Maybe I was wrong there too?
Back to top
View user's profile Send private message
Yochai



Joined: 31 Mar 2005
Posts: 5

PostPosted: Fri May 13, 2005 11:49 pm?? ?Post subject: /set against /var Reply with quote

ok, lets end this debate here.
What I ment was using local variables for addons instead of global vars.
Doesn't really matter if you use /var or /set -l ...
Though I think the /set -l command actually works a bit faster then /var (if we're already on the CPU saving topic.)
_________________
#mirc
Undernet
Back to top
View user's profile Send private message
SebDE



Joined: 30 Oct 2004
Posts: 34

PostPosted: Sat May 14, 2005 10:14 am?? ?Post subject: Reply with quote

Fenris_Wolf wrote:
(btw...the update time seems longer then 10 seconds)
whatever, I just wanted to point out that it is cached... :)
Quote:
and no, that wasnt a joke....
So you really have no idea why I wrote alias bold... Doesn't even made you curious? :D
Ah well maybe you don't even use the build in mIRC scrips editor... cause there you have all aliases (from the aliases tab) listed in the main menu ;)

Ok ok that's just for aliases (in the aliases tab)... I guess you do that with most of other scripts too...

Quote:
I have no intention of starting a endless discussion ANYWHERE.
kk & it's not just for you... I wanted to make my point on that discussion really clear this time: as long as there will be such possibilities in a scripting/programming language there will be scripters/programmers who do it one way and other who do it the other way... & always there will be some of one group or the other who can't stop argue about one or the other possibility :S
guess that would fit better on var vs. set -l in this thread o.0
but it's still the same old story...
_________________
IRC is an Addiction with No cure
Back to top
View user's profile Send private message
Display posts from previous: ??
Post new topic???Reply to topic ???www.IRC-Junkie.org Forum Index -> Articles All times are GMT + 1 Hour
Goto page 1, 2??Next
Page 1 of 2

?
Jump to:??
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB ? 2001, 2002 phpBB Group

Hudson Hotel New York | Madrid Hotels | Loans | Free Ringtones | Bordeaux Hotels