mIRC Home    About    Download    Register    News    Help

Print Thread
Page 2 of 2 1 2
Re: Local variables [Re: Kardafol] #171327 22/02/07 10:20 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Hash tables are very easy to use and work with once you learn them. They are quick to set up and very easy to access. I don't see how an array is really any easier. If you find hash tables difficult, then you may want to work with them a bit and learn how they are used. Then, you'll see that they are really very easy to use.

As for $gettok conflicting based on the deliminator, if you the data being used may contain certain characters, then you just use a weird character as the deliminator, such as as that's rarely used in anything else. If you know for sure that it will never have a comma, then you can just stick to that. But when you're unsure, then you just set the script up to use a weird character that is unlikely to ever be used. Or, when you add text to your list that you'll use $gettok on, you can $replace the deliminator with something weird and then $replace it back later.

For example, when I need to deal with spaces, I may do something like:

Code:
alias test {
  var %test = $replace($$?="Enter data",$chr(32),_)
  var %test = %test $replace($$?="Enter more data",$chr(32),_)
  echo -a $replace($gettok(%test,1,32),_,$chr(32))
}


That's a weird example, but it shows how you can store your data using $replace and output it using $replace if that's necessary. Still, just changing the deliminator helps.


Invision Support
#Invision on irc.irchighway.net
Re: Local variables [Re: Riamus2] #171333 22/02/07 10:59 PM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
If you can be certain a character won't appear then tokens might make sense, if not then they definitely shouldn't be used. A bug with a one in a thousand chance of happening is still a bug. There's no reason to rely on chance when there are ways that guarantee success every time.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Re: Local variables [Re: Riamus2] #171334 22/02/07 11:18 PM
Joined: Jan 2007
Posts: 259
K
Kardafol Offline OP
Fjord artisan
OP Offline
Fjord artisan
K
Joined: Jan 2007
Posts: 259
I like having scripts that are bug-free, and don't use weird characters that have the potential for someone to abuse it.
I use hash tables, however it would be somewhat irritating to keep making a new hash table for each use.


Those who can, cannot. Those who cannot, can.
Re: Local variables [Re: starbucks_mafia] #171336 22/02/07 11:30 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Name the variable the nick so it wont be duplicated.

/test info1 info2 info3

alias test {
$1 = info1
$2 = info2
$3 = info3
}
Yes this is nice to do with aliases. I use this a lot, but what if $1 or $3 is data seperated by spaces? Gettok would be the best for this.

/test info1,info2,info3
alias test {
info1 = $gettok($1,1,44)
etc.
}

I sometimes create temporary hash tables named after the nickname to store a few lines of data. Then when all is finished I hfree the table.

Re: Local variables [Re: Kardafol] #171343 22/02/07 11:53 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
It all depends on what you're doing. For example, if the input was a path/filename, you can just use the : as a deliminator because it cannot be used in a filename/path. It is usually easy to look at your project and determine what is going to be used and what is not going to be used. The chance that a person would use the deliminator can be easily remedied using a check if you really feel like it could be an issue.

I don't know what you mean about making a table for each use. Each use of what? Unless you free it (or close mIRC), you can use it over and over. If you're using an array, you also can use it over and over. In both cases, you have to make the table/array. In both cases, you can use it as long as it's still made. I can't see any difference in how one is more "irritating" to use. If you have a *real* example rather than just something made up that shows how one is significantly better than the other, I'd like to see it. As I've said, I have not seen any examples of what someone might actually use (not these things that say "blah blah" or whatever) that show any significant differences.


Invision Support
#Invision on irc.irchighway.net
Page 2 of 2 1 2