mIRC Home    About    Download    Register    News    Help

Print Thread
#84419 28/05/04 06:57 PM
Joined: Feb 2004
Posts: 714
Z
Hoopy frood
OP Offline
Hoopy frood
Z
Joined: Feb 2004
Posts: 714
Hi smile
Code:
ctcp +1000:DEL Perform*:*: {
  var %net = $3
  var %com = $4-
  var %check.perf
  var %i = $ini(Perform.ini,perform,0)
  while (%i) {
    var %net2 = $gettok($readini(Perform.ini,perform,$ini(perform.ini,perform,%i)),1,44)
    var %com2 = $gettok($readini(Perform.ini,perform,$ini(perform.ini,perform,%i)),2,44)
    if (%net == $net2) && (%com == %com2) {
      remini Perform.ini perform $ini(perform.ini,perform,%i)
      inc %check.perf
    }    
    dec %i
  }
  if (%check.perf) { .notice $nick Removed perform %com from %net . }
  if (!%check.perf) { .notice $nick Perform command %com of %net does not exist. | halt }
}
I have this in my bot. I am able to add performs to the bot, but i can't seem to remove them. That code is what i have to remove the perform, but it is not working. I get the Perform command does not exist message.

What's wrong with it?

Thanks, Zyzzy smile


"All we are saying is give peace a chance" -- John Lennon
#84420 28/05/04 08:42 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Hi,

it's cuz of a typo.

if (%net == $net2) should be %net2


Btw the /tokenize command could be interesting for you. /help /tokenize

For example:
Code:
var %net2 = $gettok($readini(Perform.ini,perform,$ini(perform.ini,perform,%i)),1,44)   
var %com2 = $gettok($readini(Perform.ini,perform,$ini(perform.ini,perform,%i)),2,44)   
if (%net == $net2) && (%com == %com2) {

could be changed to:
Code:
 
tokenize 44 $readini(Perform.ini,perform,$ini(perform.ini,perform,%i))
if (%net %com == $1-2) {


Just a suggestion smile


Greets

Last edited by FiberOPtics; 28/05/04 08:48 PM.

Gone.
#84421 28/05/04 09:16 PM
Joined: Feb 2004
Posts: 714
Z
Hoopy frood
OP Offline
Hoopy frood
Z
Joined: Feb 2004
Posts: 714
Lol.. thanks! laugh Those typos haunt me :P

I've seen the /tokenize around a lot, and tried to pick it up on the /help file, but I'm still not pretty sure how to use it smile

Thanks again!
Zyzzy.


"All we are saying is give peace a chance" -- John Lennon
#84422 28/05/04 09:35 PM
Joined: Nov 2003
Posts: 2,327
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,327
It fills $1, $2, $3 etc with the specified tokens seperated by the specified asc value.

/tokenize 32 1 2 3
$1 = 1, $2 = 2, $3 = 3

/tokenize 32 1 2.2 3.4684
$1 = 1, $2 = 2.2, $3 = 3.4684

/tokenize 46 1 2.2 3.4684
$1 = 1 2, $2 = 2 3, $3 = 4684


New username: hixxy
#84423 28/05/04 10:33 PM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Yw,

regarding /tokenize, its pretty easy and very helpful once you get the hang of it.
As you know in a string, you have tokens seperated from each other by a delimiter.


1. Basic token/delimiter explanation

String: this is a test | delimiter = a space or $chr(32)

String: this,is,a,test | delimiter = a comma or $chr(44)

Since you are already used to using $gettok and other token identifiers this is not new to you.


2. Tokenizing a string

/tokenize 44 this,is,a,test

The tokenize command searched for tokens seperated by commas, and stored them in the identifiers $1, $2, ....$N

$0 -> total amount of tokens: 4
$1 -> first token: this
$2 -> second token: is
$3 -> third token: a
$4 -> fourth token: test
$1- -> this is a test

As you see, tokenizing a string based on a certain delimiter (comma in our example), the tokens are "saved" in parameters $N which can be easily retrieved. As shown, the delimiters are gone in the tokenized string!

var %string = this,is,a,test

$gettok(%string,0,44) is the same as $0
$gettok(%string,1,44) is the same as $1
$gettok(%string,2-4,44) is the same as $2-4
...


3. Consequences of tokenizing a string

A] When tokenizing a string for a specific delimiter, mIRC will analyse the string, and will fill the $N parameters with the tokens seperated by the chosen delimiter. Attention, one $N identifier can contain multiple words as shown in this example:

/tokenize 44 this, is a test

Mirc sees that there are 2 tokens (that's right, 2 tokens, not 4) seperated by a comma.

$1 --> this
$2 --> _is a test (the _ is a space in this example)
$0 --> 2

B] Very important!

When tokenizing a string, the $N parameters are filled as stated earlier, though this means that the previous contents of those $N identifiers are removed! So if you know you're going to tokenize, then you're best off, with putting the original $1- in a variable.

To explain what I mean here's an example:
Code:
 
/test1 auto identify
 [color:red]  [/color] 
alias test1 {
 [color:red]  [/color] 
  ; input string passed to the alias : "auto identify" stored in %input
  var %input = $1-
 [color:red]  [/color] 
  tokenize 44 $readini(perform.ini,perform,command)
 [color:red]  [/color] 
  ; due to the tokenizing, the original values $1 = auto, and $2 = identify, are now 
  ; overwritten with the values that were returned by the $readini
 [color:red]  [/color] 
  ...
}


4. Sexy usage of /tokenize

A]
There is this really nifty identifier $* that can be used along with /tokenize like this:

//tokenize 32 one two three four five | echo -a $*

This will show the following on your screen:

one
two
three
four
five

In other words, the $* identifier puts each delimited token on a new line.

B]
Here's an example of how to get the value of $N in a loop:
Code:
  
alias test2 {
  tokenize 46 1.2.3.4.5.6.7.8.9.10
  var %x = $0
  while (%x) { echo -a $($+($,%x),2) | dec %x }
}

This will echo on each line the value of $N identifier, so $10, then $9, $8, ...

However, if you payed attention, then you could just have achieved the same thing by doing:
Code:
 
alias test3 { 
  tokenize 46 $sorttok(1.2.3.4.5.6.7.8.9.10,46,rn) 
  echo -a $*
}


Anyway, there might still be a couple of things to mention about /tokenize but this pretty much covers it. Hope you now fully understand the functionality of /tokenize

Greets


Last edited by FiberOPtics; 28/05/04 10:45 PM.

Gone.
#84424 28/05/04 10:49 PM
Joined: Feb 2004
Posts: 714
Z
Hoopy frood
OP Offline
Hoopy frood
Z
Joined: Feb 2004
Posts: 714
Thanks very much FiberOPtics & tidy_trax! laugh

I'll try using /tokenize in some scripts wink

Thanks a bunch,
Zyzzy


"All we are saying is give peace a chance" -- John Lennon

Link Copied to Clipboard