Difference between revisions of "$ini"
From Scriptwiki
m (Missing space between while and ()) |
(Thank bindi for noticing and testing :)) |
||
Line 23: | Line 23: | ||
var %j = 1 | var %j = 1 | ||
; lets begin to loop through all items in the current topic | ; lets begin to loop through all items in the current topic | ||
− | while (%j <= $ini($1,%i,0)) { | + | while (%j <= $ini($1,$ini($1,%i),0)) { |
; echo all items in this topic | ; echo all items in this topic | ||
− | ; $ini($1,%i,%j) returns the item name of the %j's item in the %i's section. | + | ; $ini($1,$ini($1,%i),%j) returns the item name of the %j's item in the %i's section. |
; $ini($1,%i) returns the %i's section name | ; $ini($1,%i) returns the %i's section name | ||
− | echo -a -- $ini($1,%i,%j) => [[$readini]]($1,$ini($1,%i),$ini($1,%i,%j)) | + | echo -a -- $ini($1,$ini($1,%i),%j) => [[$readini]]($1,$ini($1,%i),$ini($1,$ini($1,%i),%j)) |
; increase looping variable | ; increase looping variable | ||
inc %j | inc %j |
Latest revision as of 19:35, 25 January 2013
Returns the name/Nth position of the specified topic/item in an ini/text file.
$ini(file,topic/N,item/N)
Note that the item/N parameter is optional. If you specify N = 0, it returns the total number of topics/items.
Example
echo -a $ini(mirc.ini,0)
Echos the total number of topics in your mirc.ini.
echo -a $ini(mirc.ini,mirc,0)
Echos the total number of items in the topic mirc in your mirc.ini
The following, more complex example shows howto loop through an entire ini file.
; We want to have an alias called showini. At the end, it will be /showini <inifile> alias showini { ; echos ini name echo -a $1 var %i = 1 ; We begin to loop through all topics. $ini($1,0) returns the total number of topics while (%i <= $ini($1,0)) { ; echos the name of the current topic echo -a - $ini($1,%i) ; set a new looping-variable var %j = 1 ; lets begin to loop through all items in the current topic while (%j <= $ini($1,$ini($1,%i),0)) { ; echo all items in this topic ; $ini($1,$ini($1,%i),%j) returns the item name of the %j's item in the %i's section. ; $ini($1,%i) returns the %i's section name echo -a -- $ini($1,$ini($1,%i),%j) => $readini($1,$ini($1,%i),$ini($1,$ini($1,%i),%j)) ; increase looping variable inc %j } ; increase first looping-variable inc %i } }