Tutorial Posted February 25, 2008 Report Share Posted February 25, 2008 Tokenized lists Description: Tokenized lists are simple lists that can be used for a limited number of items. We’ll use a %variable that will contain a list of items separated by a character—C. I’ll show as an example a list separated with spaces (character 32). Advantages: Easy to use, direct access to the items, simple sorting, use of simple %variables, uses built in sort and search functions. The list can be sent as a parameter to an alias, and can be easily accesses with $1,$2,$N after using the /tokenize command. Disadvantages: Limited number of items due to the use of the %variables and their limits. (about 900 characters). Storage: If the %variable is a global variable, it is stored in mIRC’s variables list. %variable = list of items Initializing a list: /set %list Adding an Item: /set %list $+(%list,$chr©,New_Item) Or /set %list $addtok(%list,New_Item,C) C is the value of the separating character, 32 (space) in our case. Deleting an Item: /set %list $deltok(%list,N-N2,C) N-N2 is the range of items to be deleted, or the position of the item. /set %list $remtok(%list,Item,N,C) Removes the Nth matching item. Inserting items: /set %list $instok(%list,New_Item,N,C) Will insert a token to the position N, without overwriting the Nth item. /set %list $puttok(%list,New_Item,N,C) Will replace the Nth token/item with the new item. /set %list $reptok(%list,Item,New_Item,N,C) Replaces the Nth matching item with the new item. (You can use $reptokcs for case sensitive) Searching for items: /set %bool $istok(%list,Item,C) Returns $true if the item exists, or $false if it doesn’t (useful in IF sentences). (You can use $istokcs for case sensitive) /set %position $findtok(%list,item,C) Returns the position of the item in the list. (You can use $findtokcs for case sensitive) /set %item $matchtok(%list,SubString,N,C) Returns the Nth match of an item containing the Sub String. (You can use $matchtokcs for case sensitive) /set %item $wildtok(%list,*match*text*,N,C) Returns the Nth item that matches the match text. (You can use $wildtokcs for case sensitive) Sorting the list: /set %list $sorttok(%list,C,[ncra]) This will sort the list, depending on the specification: n = numeric sort, c = channel nick prefix sort, r = reverse sort, a = alphanumeric sort You can use $sorttokcs for case sensitive. Retrieving size: /set %num $numtok(%list,C) This will give you the number of items in the list. Example: Load this in your remotes, and select a few nicks in a channel. menu nicklist { Tokenized list: { var %nicks = $1- echo -a I've selected $numtok(%nicks,32) nicks in the nick list: %nicks echo -a First nick: $gettok(%nicks,1,32) ... Last nick: $gettok(%nicks,-1,32) tokenize 32 %nick if ($2) echo -a Second nick: $2 if ($wildtok(%nicks,$me,1,32)) echo -a I've chosen myself else { var %nicks = $addtok(%nicks,$me,32) } var %nicks = $sorttok(%nicks,32,r) echo -a Reversed list of nicks: %nicks } } Link to comment Share on other sites More sharing options...
Recommended Posts