mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Will this work to delete 1/2 of the old (first added) data values in an item?

original:
item data1 data2 data3 data4 data5 data6

Code:
alias adjust {
  if ($1) { set %hash $1 }
  else {
    set %hash $$?1="Hash?"
    set %item $$?2="Item?"
  }
  set %itemdata $hget(%hash,%item)
  set %totnumtok $numtok(%itemdata,32)
  set %half $calc(%totnumtok / 2)
  set %a %half
  echo -s In %hash %item originally had %totnumtok data values: %itemdata
  while (%half) {
    set %itemdata $deltok(%itemdata,1,32)
    dec %half
  }
  .hadd %hash %item %itemdata
  echo -a In %hash %item deleted %a of %totnumtok data values: %itemdata
}

result:
item data4 data5 data6


I registered; you should too.
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
imho, there's no need for a while loop deleting the N last tokens, you might use gettok instead: $gettok(tokens,N1-,C)
after setting %hash and %item, try something like:
Code:
echo -a old data for item %item of table %hash : $hget(%hash,%item)
hadd %hash %item $gettok($hget(%hash,%item),$+($int($calc($numtok($hget(%hash,%item),32) /2 +1)),-),32)
echo -a new data of item %item of table %hash : $hget(%hash,%item)

$deltok also supports N1-[N2], and you may use negative numbers to delete the last tokens, e.g.:
$deltok(a b c d e f g,-1--3,32)
or
$deltok(a b c d e f g,-3-,32)

Last edited by Horstl; 09/06/08 11:04 PM.
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
When $addtok adds a token to an item, it adds it ad the end (right side), right? So those are the newest data values?

So, what you are saying, is if can just use $deltok to delete the first (several) token (left side, oldest).

EX: item data1 data2 data3 data4 data5 data6

$deltok(%itemdata,1-3,32)

end result: item data4 data5 data6

Also, is there a limit to the number of token for an item?


I registered; you should too.
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Of course you can use e.g. $deltok(%itemdata,1-3,32) instead of $gettok(%itemdata,4-,32).
The negative N was to illustrate that there are multiple ways to get some tokens... And there is no token limit but a length limit: prior to mIRC 6.32 it's been aprox. 940 chars (name of hash table + name of item + data of item), mIRC 6.32 extended it to aprox. 4140 chars.

Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
Originally Posted By: Horstl
Of course you can use e.g. $deltok(%itemdata,1-3,32) instead of $gettok(%itemdata,4-,32).
The negative N was to illustrate that there are multiple ways to get some tokens... And there is no token limit but a length limit: prior to mIRC 6.32 it's been aprox. 940 chars (name of hash table + name of item + data of item), mIRC 6.32 extended it to aprox. 4140 chars.


Excellent. Thanks for your help.


I registered; you should too.

Link Copied to Clipboard