|
prajna
|
prajna
|
i would really like to see a case statement (similar to that found in pascal coding) added to the mirc script in the future. i think that would cut down alot on coding that is used over and over again by many scripters. a case statement works like the following:
case (%somevar) of someresult1 : { do this } someresult2 : { do that } someresult3 : { do these things } end case
that could make it easier for situations instead of building large if-then-else statements.
~ prajna
|
|
|
|
codemastr
|
codemastr
|
I would much rather see it implemented as a C switch() statement. Pascal has very ackward syntax.
switch (%var) { case 3: echo -a it's a 3 break case 4: echo -a it's a 4 break default: echo -a I don't know what it is }
|
|
|
|
Joined: Dec 2002
Posts: 1,893
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,893 |
Or to be simplified
switch (value) {
x { commands }
y { commands }
default { commands }
}
|
|
|
|
prajna
|
prajna
|
yes, a switch statement would do it fine as well (i can handle the c++ type structure), anything that would make a "case" type statement would really help out tremendously. bulky if-then-else statements, though the heart of any logic put forth in coding or scripting, can become alot more confusing afterwards than a plan "case" or "switch" type statement.
~ prajna
p.s, this is off subject, but, hash tables are nice, but a strait up friggin array system would be the best. i have to make these identifiers and use (use to be tokenize arrays turned hash tables now), to simulate an array, and i cant assign to them easily that way...
i can do an array this way: %myvar = $myarray(1)
but i cant $myarray(1) = 17...
if the time was made to just implement a true array system, that would really help out on the simplicities of scripting, yet allow more much more complex scripts themselves..
~ prajna
|
|
|
|
Joined: Dec 2002
Posts: 1,253
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,253 |
That's because identifiers like $myArray( ) return a value. Write your myArray alias to react to /myArray <index> <value> as well as $myArray(<index>). Here are three methods (you can pick one or develop something similar yourself) to work with $myArray() and /myArray.
; $myArray(N)
;
; Usage: $myArray(N) - returns the value from the Nth array element
; $myArray(0) - returns the total number of elements in myArray
;
; /myArray [-rcsl] [index] [value]
;
; Usage: /myArray N value - sets the Nth array element equal to value
; /myArray -r N - removes the value from the Nth array element
; /myArray -c - clears all the data from myArray
; /myArray -s - saves the current to the data file
; /myArray -l - loads myArray with previously saved data from the data file
;
; -=[ Implemented using a hash table ]=-
;
alias myArray {
if ($isid) {
if ($$1 > 0) $&
return $hget(myArray,$1)
elseif ($1 == 0) $&
return $hget(myArray,0).item
}
elseif (($1 == -r) && ($$2 > 0)) $&
hdel myArray $$2
elseif (($1 == -c) && ($hget(myArray)) $&
hfree myArray
elseif (($1 == -s) && ($hget(myArray)) $&
hsave -o myArray myArray.dat
elseif ($1 == -l) {
if ((!$isfile(myArray.dat)) && ($show)) $&
echo $color(info) -esbflirt * /myArray: no data file previously stored.
else {
if ($hget(myArray)) $&
.hfree myArray
hmake myArray 10
hload myArray myArray.dat
}
}
elseif ($$1 > 0) $&
hadd -m myArray $1 $$2
}
;
; -=[ Implemented using an INI file ]=-
;
alias myArray {
if ($isid) {
if ($$1 > 0) $&
return $readini(arrays.ini, myArray, $+(n,$1))
elseif ($1 == 0) $&
return $ini(arrays.ini, myArray, 0)
}
elseif (($1 == -r) && ($$2 > 0)) $&
remini arrays.ini myArray $+(n,$$2)
elseif ($1 == -c) $&
remini arrays.ini myArray
elseif ($istok(-s:-l,$1,58)) $&
return
elseif ($1 > 0) $&
writeini arrays.ini myArray $+(n,$1) $$2-
}
;
; -=[ Implemented using variables ]=-
;
alias myArray {
if ($isid) {
if ($$1 > 0) $&
return $eval($+(%,myArray.,$$1)
elseif ($1 == 0) $&
return $var(%myArray.*,0)
}
elseif (($1 == -r) && ($$2 > 0)) $&
.unset $+(%,myArray.,$$2)
elseif ($1 == -c) $&
.unset %myArray.*
elseif ($istok(-s:-l,$1,58)) $&
return
elseif ($$1 > 0) $&
set $+(%,myArray.,$1) $$2-
}
Now then, having said all that - personally, I think it would be much more efficient to script the actual array handler as $array(arrayName,N) and /array arrayName N value. You could script $arrayName() to use $array, thus hiding it from your script and reducing typing.
alias array {
if ($isid) {
if ($$2 > 0) $&
return $hget(arrays,$+($1,.,$2))
elseif ($2 == 0) $&
return $hfind(arrays,$+($1,.*),0,w)
}
elseif (($1 == -r) && ($$3 > 0)) $&
hdel arrays $+($2,.,$$3)
elseif (($1 == -c) && ($hfind(arrays,$+($2,.*),0,w))) $&
hdel -w arrays $+($2,.*)
elseif (($1 == -s) && ($hget(arrays))) $&
hsave -o arrays arrays.dat
elseif ($1 == -l) {
if ((!$isfile(arrays.dat)) && ($show)) $&
echo $color(info) -esbflirt * /array: no data file previously stored.
else {
if ($hget(arrays)) $&
.hfree arrays
hmake arrays 10
hload arrays arrays.dat
}
}
elseif ($$2 > 0) $&
hadd -m arrays $+($1,.,$2) $$3
}
alias myArray {
if ($isid) $&
return $array(myArray,$$1)
elseif ($left($$1,1) == -) $&
array $1 myArray $$2-
else $&
array myArray $1-
}
$myArray and /myArray would work exactly the same way as first described. The difference is that you could define multiple arrays using the same structure and use them the same way throughout your script without having to rescript each one because they all use $array and /array, thus they are all managed from the same array. You could replace the array alias with another method without hindering the performance of the rest of your script.
|
|
|
|
StriderGU
|
StriderGU
|
Yes a:
switch (variable) { x { commands } y { commands } default { commands } }
Would be cool, but I also miss do-while and for loops.
|
|
|
|
|