mIRC Home    About    Download    Register    News    Help

Print Thread
#13862 03/03/03 03:23 AM
Joined: Mar 2003
Posts: 50
C
Babel fish
OP Offline
Babel fish
C
Joined: Mar 2003
Posts: 50
I'd love to have the ability to store information in arryas and perhaps even have for and foreach loops. A little example of this could be something like:

var %array[]
%array[1] = coolspot
%array[2] = mirc
%array[3] = array

Or perhaps being able to set an array in 1 line instead of 3 seperate statements via comma delimiters. For example:

var %array[] = coolspot, mirc, array

Which in turn %array[1] would be coolspot, %array[2] would be mirc and %array[3] is array. This could apply for both local and non-local variables. It would also be nice if you could specify:

var %array[100]

This way the %array variable has a defined amount of static values. So once 100 items are in the array, no more can be defined, perhaps for speed or efficiency. And then perhaps the index of 0 to return the amount of items in the array, such as:

%array[0] would return the amount of items in the array.
OR if this wouldnt be an option lets use something like:

$array(ArrayName).count returns the total number of items

The array identifier could be used also to see if an array exists, or to find a specific value in an array such as:

$array(1) would return the name of the first array
$array(0) would return the total number of arrays
$array(ArrayName,1) would return the first item in the array
$array(ArrayName,*coolspot*,N) would do a wildcard searh starting at Nth position in the array.
$array(ArrayName).items could be used to populate a refernece to all the items in an array used in a foreach loop.

ArrayName would be the text inbetween % and [] when an array is set. An example would be %moo[], moo would be the arrayname to reference using the $array identifier.

Theres probably more that could be done with this, however its just a general idea of what it could be used for.

Then perhaps for loop support would be great, and even perhaps foreach as well. Such as the following as an example using some arrays:

for (%i = 0, %i <= $array(moo).count, %i++) {
echo $array(moo,%i)
}

And heres an example of a foreach loop:

foreach ($array(moo).items in $array(moo)) {
echo $array(moo,$for(moo))
}
This would echo each item in the moo array

Or, another example, using a differnet format:

foreach ($array(moo).items in %moo[]) {
echo %moo[$for]
}

The $for identifier would be similar to the behavior of $readn, in which $for is automatically incremented each time the foreach loop is triggered. The N parameter of $for would reference the ArrayName so that $for can keep track of multiple nested foreach loop triggers. This way $for could keep track of multiple foreach statements that may be nested within one another without conflict. Or even, if $for is used within $array,.. $for automatically returns a result based on the ArrayName givin in the $array statement, this way no parameter (ArrayName) would be needed. Or could be based on the name of the givin array. Heres 2 examples:

foreach ($array(moo).items in %moo[]) {
echo %moo[$for]
}

$for knows to retreieve the current count for %moo since it is incased in the %moo[] array. Or perhaps:

foreach ($array(moo).items in $array(moo)) {
echo $array(moo,$for)
}

Would do the same as stated above but its a little more code.

Array's could be stored in the variables.ini file as follows:

%moo[1] coolspot
%moo[2] testing
%moo[3] array

or perhaps this way:

%moo[
coolspot
testing
array
]

The []'s indicated the start and end of the array values. Or if a static array size was indicated when created the array, it could be something like:

%moo[3,1] coolspot
%moo[3,2] testing
%moo[3,3] array

or:

%moo[3
coolspot
testing
array
]

Which would tell mirc that the array has been allocated for 3 values. If more items are created, it will fail since the array was defined as having a maxium size of 3.

It would also be nice to be able to use /hsave to save the values to a hash table if need be, then the user could repopulate his arrays via /hload. And the values in the hash would be stored like normal hash table data, however /hload would look for %*[] text patterns as the named item in the hashtable to indicate that it needs to be repopulated as an array to give access to the $array() identifer. Once loaded arrays are stored in memory for the duration of mirc being open. And if the user chooses, can /hsave them upon closing. Of course this would apply to local arrays only since non-local arrays are stored in variables.ini respectivly.

Ok, I'm done now, sorry for the long post, just thought it may be worth while. Hope to see these features in later versions. Keep up the great work! Oh and one last little tidbit, it'd be nice if $scriptline would return a value regardless if an event was triggered or not so it can be used within an alias and the latter. Take care everyone! smile

Last edited by coolspot; 03/03/03 03:52 AM.
#13863 03/03/03 05:27 AM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
If you script it, $array() is already not only possible, but fairly simple - and has been for quite some time (with a creative use of $readini and /writeini - and now with hash tables, it's even easier; but, in order to create/modify/free the array, you'd use /array and just use $array() to retrieve the values. I think I might even have written up a method or two already on these forums.

For and ForEach aren't currently possible. ForEach would be potentially handy for iterating over a hash table. smile


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#13864 03/03/03 06:11 AM
Joined: Mar 2003
Posts: 50
C
Babel fish
OP Offline
Babel fish
C
Joined: Mar 2003
Posts: 50
Yeah I realize hash tables are basically there for what I just mentioned however I feel if this was incorporated, it'd be much easier to use and access and cutdown on code. I like hash tables, though its more or less dictionaires or collections then hash tables. But a native implementation would be nice eh? cool

#13865 04/03/03 06:47 AM
Joined: Jan 2003
Posts: 14
A
Pikka bird
Offline
Pikka bird
A
Joined: Jan 2003
Posts: 14
Hammer, you have of course, as usually a point. since some time now, many things can be scripted, and there exist some DLL's out there as well. but this is still a suggestion forum. admiring your knowledge, i still must say that sometimes you are a bit too ... uh ... traditionalist. mIRC is a chatting program after all. no offense intended, but you could chat with mIRC 3.0 almost as well as you can now. what i mean is, that Khaled does a good job in constantly changing and upgrading/evolving his application.

mIRC has a great scripting language, and support for many many things. still a few things would be really good, for loops is one of them, as well as more dialog controls, which are up-to-date to the windows versions. even with the mdx dll out there, it should be handled by mIRC itself, and not by a DLL, IMNRHO

*smile*


Sentinel scripter ( current version X, alpha )
#13866 04/03/03 07:06 AM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
When I post a workaround for an idea someone has posted, I only do so to perhaps provide them with a way to do what they would like to do, as closely as I can to the format they want it in, prior to Khaled's deciding to implement it in mIRC natively (if he wants to add it, that is). Indeed, most of the scripts I've posted here were never really meant to be "Here, use this." Rather, I would prefer that whoever reads the answer learns at least ONE way (the way(s) I have described in that post, quite possibly with example code) to accomplish what they want to do - and then codes it however they like, using their own coding style. There are a lot of excellent coders out there, some of whom have the audacity to use a different coding style than I do! *gasp* laugh I would like to think that, at least for the more complex scripting algorithms presented here, the questioner understands the steps involved and then codes it themselves...that's part of the fun of coding in the first place. One of the very cool things (for me, at least) is that you can frequently see several equally valid conceptual approaches to solving "the problem." I frequently learn things from these forums, either from someone else's solutions or from going through the process of finding a workable solution to someone's problem myself.

However, this in no way means I disagree with the idea being added. If that's what I mean, I specifically say so. laugh I might STILL provide the workaround - but if I feel adding it to mIRC is a waste of time, I have no problems stating my opinion, just like everyone else.

I'm waiting for access to all the common windows controls, just like everyone else...and just as impatiently, too! :P For loops would be a great boon because MOST of the loops we write turn out to be for loops.
Code:

;  While loop
 
on ^*:NICK:{
  var %i = 1
  while $comchan($newnick, %i) {
    echo $color(nick) -bflirt $ifmatch * $nick is now $newnick
    inc %i 
  }
  halt
}
 
;  For loop
 
on ^*:NICK:{
  for (var %i = 1; $comchan($newnick, %i); inc %i) echo $color(nick) -bflirt $ifmatch * $nick is now known as $newnick
  halt
}

Obviously, the for loop is cleaner. cool


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#13867 04/03/03 08:14 PM
Joined: Dec 2002
Posts: 117
R
Vogon poet
Offline
Vogon poet
R
Joined: Dec 2002
Posts: 117
Is it me, or are people already making typo's in features that aren't even added to mIRC? :[b][/b]-)


$input(Me like stars, You too?)
#13868 04/03/03 10:58 PM
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
If it's not yet implemented, how can I have made a typo? The hypothetical syntax has yet to be decided on, hypothetically.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
#13869 04/03/03 11:18 PM
Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
I personally would suggest for (initializer, conditional, incrementer)

Reason is... this way it works just like all other mIRC functions. In C/C++ it is different because , means you are including 2 things for 1 parameter. But mIRC already has | for that, so:

for (var %i = 0 | var $j = 1, %i < %j, inc %i)
{
}

Just figure why not keep with the traditional mIRC syntax?


Link Copied to Clipboard