|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
OP
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
I'd like to be able to use groups in the middle of blocks of code (aliases, events, etc) so you can enable/disable a block of code in the middle of an alias or event. alias mycoolalias {
#coolfeature1 off
echo -a 1
#coolfeature2 end
echo -a 2
echo -a 3
} Turning #coolfeature1 on would echo 1, as well as 2 and 3. This could also be added without breaking most aliases beginning with # by only treating the line as a group if the second word is on, off or end. Although suggested numerous times, nested groups would also be nice.
|
|
|
|
Joined: Oct 2004
Posts: 73
Babel fish
|
Babel fish
Joined: Oct 2004
Posts: 73 |
I'm guessing you meant for both group names for off and end in that example to be #coolfeature1 I can see the benefit of this, perhaps they could even be included inside popup menus.
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
OP
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
I did I tried to edit the post earlier but the edit time had already expired.
|
|
|
|
Joined: Oct 2005
Posts: 54
Babel fish
|
Babel fish
Joined: Oct 2005
Posts: 54 |
instead in the script that turns it on and off use like menu menubar { Cool Stuff .Turn on Cool Feature : /set %coolthing1 1 .Turn off Cool Feature : /set %coolthing1 0 } then for your script: alias mycoolalias {
$iif(%coolthing1 == 1, echo -a 1)
echo -a 2
echo -a 3
}
Chat NSNMy Server: sleepystickman.ircxpro.com
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
OP
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
I'm not looking for workarounds, I already know many. Thanks though.
|
|
|
|
Joined: Apr 2003
Posts: 701
Hoopy frood
|
Hoopy frood
Joined: Apr 2003
Posts: 701 |
This can get really complex (or just plain wrong) very easily. People will start using groups containing parts of control structures, and then find it strange the script doesn't do what they think it should do. Here's an easy example: alias test {
#group off
if ($something) {
#group end
echo hey, it's something!
}
echo hey it's nothing
} But now consider cases where a group is partially over a while loop and partially over a trigger etc. It gets messy... Is the possibility of making errors with it a reason not to implement it? Not really, but keep it in mind. ps: you won't want the below code either I presume? #coolfeature off
#coolfeature end
alias mycoolalias {
if ($group(#mycoolfeature) == on) echo -a 1
echo -a 2
}
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
I think the idea merits as a great one, maybe difficult to implement into the script pharser, but still would allow a new method of coding. example (which uses something like what you felt would be the problem with it)... ; $1 = start line to show
; $2 = end line to show
; $3 = file1
; $4 = file2 (optional)
; $5 = file3 (optional)
; * should any file have a blank line/eof then end all showing. *
alias showstuff {
.disable #showfile1
.disable #showfile12
.disable #showfile123
if ($5) { .enable #showfile123 }
elseif ($4) { .enable $showfile12 }
else { .enable #showfile1 }
var %c = $1
#showfile1 off
while ((%c <= $2) && ($read($3,%c))) {
var %line = $read($3,%c)
#showfile1 end
#showfile12 off
while ((%c <= $2) && ($read($3,%c)) && ($read($4,%c))) {
var %line = $read($3,%c) $read($4,%c)
#showfile12 end
#showfile123 off
while ((%c <= $2) && ($read($3,%c)) && ($read($4,%c)) && ($read($5,%c))) {
var %line = $read($3,%c) $read($4,%c) $read($5,%c)
#showfile123 end
;
; --- other code that does something to %line then displays it ---
;
inc %c
}
} Based on whats passed , the while loop control is selected from within 3 groups. each group specific to the needs.
|
|
|
|
Joined: Feb 2005
Posts: 681
Fjord artisan
|
Fjord artisan
Joined: Feb 2005
Posts: 681 |
This suggestion & groups inside of groups would be great.
|
|
|
|
Joined: Oct 2004
Posts: 8,330
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,330 |
Hm... DaveC... From your example, I don't really see how it's useful. I mean, using that method, you could just as easily put the condition for enabling the groups right into your while statements. I'm not saying the idea wouldn't be good in some way, but from your example, I just really don't see how it helps.
Invision Support #Invision on irc.irchighway.net
|
|
|
|
Joined: Sep 2005
Posts: 2,881
Hoopy frood
|
OP
Hoopy frood
Joined: Sep 2005
Posts: 2,881 |
Here's an easy example: alias test {
#group off
if ($something) {
#group end
echo hey, it's something!
}
echo hey it's nothing
} alias test {
#group on
if ($something) echo hey, it's something!
#group end
echo hey it's nothing
} Not adding a feature because a user might use it incorrectly is silly if you ask me. ps: you won't want the below code either I presume? #coolfeature off
#coolfeature end
alias mycoolalias {
if ($group(#mycoolfeature) == on) echo -a 1
echo -a 2
} That's the method I'm using now. The reason I suggested this feature is that groups are the easiest, quickest and most descriptive way of turning a block of code on or off. I don't see why they should work any differently inside an event/alias/etc to what they do outside of one.
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
It was an example it was be design simplistic, just to show how a groups feature desecribed could be used. Using conditional checks inside & within the condition of the while loop is wasteful, if those conditions well never change. Some conditional checks (not the ones shown in my example) can take huge sums of time to return a result, if one of these are encountered once in a script the script can carry on without any noticable delay, having that condition checked a few 100 times as the while loop loops back, is going to be unacceptable. These are the conditions i would be far more likely to actually implement the feature idea in.
|
|
|
|
Joined: Feb 2004
Posts: 206
Fjord artisan
|
Fjord artisan
Joined: Feb 2004
Posts: 206 |
Or another example (for better or worse?)
alias a1 {
echo -a This is the first thingy
#somegroup on
echo -a this is the conditional thingy
}
alias a2 {
echo -a This is the a2 first thingy that may or may not exist
#somegroup end
echo -a wouldn't it be funny if you ran a1 and all of a sudden a2 ran!
}
and then you could nest groups, because of parsing - so some groups would only appear if other groups are enabled. Can lead to all sorts of interesting issues (and ideas)! Cheers, DK
Darwin_Koala
Junior Brat, In-no-cent(r)(tm) and original source of DK-itis!
|
|
|
|
Joined: Jul 2003
Posts: 655
Fjord artisan
|
Fjord artisan
Joined: Jul 2003
Posts: 655 |
I can see how groups inside events/aliases could be useful, as well as nested groups. Personally i think it could make the code very messy and a pain to read and debug. In any case, if it were to be implemented, i think a few enhancements/restrictions to the script editors built in syntax checker would be in order, fex... (that is, the bracket mismatch finder should also detect bad grouping layouts)
Probably the most important of which would be.. A group must end where it started :: That is, a group started globally (outside of any event/alias/etc) must also end globally, and in the same fashion groups started locally (inside of any event/alias/etc) must also end locally (in the same event/alias/etc that it started).
Should nested groups be cross-level? (refering to the example where only the function part and opening brace of the while was within the group, group start at top level, group end at 2nd level.. within while).
Depending on how hard and how much work this could be good or bad (the idea as a whole). If it adds too much to the script parser then it may infact caused it to be less efficient, rather than more efficient which seems to be part of the reason behind the suggestion.
This would probably confuse and frustrate a lot of new scripters using it incorrectly and not being able to figure out the problem in there scripts, as they would likely overlook the grouping tags as the possible problem. But as mentioned already this really is no good reason against it.
A simple example of where multi-level grouping could be useful...
some event { #group1 on while (something - something) { #group1 end #group2 off while (something - something) { #group2 end #group3 off while (something - something) { #group3 end some code here } final code? } something simple like this has both pro's and con's imo, there would be no restriction on having just one group enabled, more than one would instantly cause major problems. While at the same time if setup and initiated properly could be quite a useful alternative to a bunch of if statements and with inbedded while loops. (or several if statements used to set the conditions in the while)
Sorry guess i rambled on almost incoherantly, but those are my thoughts...
Basically i can see both the pro's and con's, personally i think the con's outweigh the pro's and would likely not use it a lot in my own scripts. But i would definately say that some code issue detection stuff for groups be added to the '{}' button in the scripts editor, which should check and report groups that do end and start at the same level. (outside event/alias/etc could be level 0, inside 1, and so on when inside of whiles/ifs/etc). My initial thoughts would be that by not allowing messy multi-level groups all over the place it would prevent most of the con's of the feature from occuring, however i guess it would also restrict the use somewhat.
I have to admit i have found myself on the odd occasion wishing i could use a group inside an event, but i can honestly say using it across 'mulitple levels' has never crossed my mind.
ok, ill stop typing now.
"Allen is having a small problem and needs help adjusting his attitude" - Flutterby
|
|
|
|
|