mIRC Home    About    Download    Register    News    Help

Print Thread
#17271 28/03/03 06:52 PM
Joined: Mar 2003
Posts: 272
C
Fjord artisan
OP Offline
Fjord artisan
C
Joined: Mar 2003
Posts: 272
Okay, i encountered this problem just now and frankly it's rather hard to explain. I'm editing a script for someone (with author's permissions, of course) and she wants me to add an user-specific auto greet (specific greet for specific users) section in the main dialog of the said script. Until there, there's no problem. I make a her a sweet little new tab with all she needs. That includes the following:
1) A text field describing how to use the whole thing
2) A 'sentence' that looks like When user <editbox> joins my trivia channel, greet him with the message <editbox>.
3) A 'Add' button (To add the stuff input'd above)
4) A dropdown where all existing (already set) greets target (users) are being displayed and
5) An editbox to allow modification of #4.


So until there, there's no real problem, but hang on, it's coming. The whole thing goes fine until i reach the dropdown, here's the code, i'll explain it afterwards (139 is the ID of the 'Add' button described at #3 above, 126 is the nickname editbox and 131 is the actual greet editbox):
Code:
On 1:DIALOG:trivset:SCLICK:139:{
  if ($did($dname,126).text) || ($did($dname,131).text) {
    set %cF.greet. [ $+ [ $did($dname,126).text ] ] 1
   set %cF.greetz.message. [ $+ [ $did($dname,131).text ] ]
    .reloadcombo
  }
}


So what this basically does, is when the user fills the form described above as #2, it sets %cF.greet.<nickname> to 1 where <nickname> is what the user wrote in the nickname editbox. It then sets %cF.greetz.message.<nickname> <message>, that's pretty self explanative, but you'll understand why i use %cF.greetz instead of %cF.greet later on.

The problem is with the reloadcombo alias. The user adds a new nickname, therefore the combo should reload to make sure all the nicknames are included if the user wants to edit what he previously made as the message. Here's the reloadcombo alias:

Code:
alias -l reloadcombo {
  did -rac trivset 133 Nicknames
  var %totvar = $var(%cF.greet.*,0), %i = 1
  while (%i &lt;= %totvar) {
    var %varname = $var(%cF.greet.*,%i)
    did -a trivset ... | inc %i
  }
}

What the above does is simple....
1) Clears the dropdown and adds 'Nicknames' at the top (selected)
2) Sets %totvar to the number of %cF.greet.* aliases and %i to 1 (%cF.greet.* will equal the number of nicknames the user added)
3) It then goes in a while loop and and as long as %i (which gets increased afterwards) is lower or equal to the number of nicknames (see #2 above), it should add SOMETHING to the dialog's dropdown.

The problem's right there, take a minute to try to predict what i'm trying to do. Done? Good. Here's what i'm trying to do:
/did -a trivset $gettok($eval(%cF.greet.nickname,0),3,46)
Anyone understands that?
Well for those of you who do, you'll realize that done this way, it's pretty much impossible for the following reasons:
I set %totvar to the total number of variables beginning by %cF.greet.*
Then i set %varname to $eval($var(%cF.greet.*,%i),0) which will return what? Right, $var(%cF.greet.*,%i)!!

Done that way, it's an endless circle. Thought i'd share my little mid-day brainstorm with all of you, mainly because i'm curious at what you guys are going to reply grin


- cF
Dedicated helper for rent.
#17272 28/03/03 07:10 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Have you even thought of using /did -a trivset $gettok($var(%cF.greet.*,%i),3,46) ? :tongue:

Also... why are you using a loop in the first place? Why are you reloading the entire combo instead of only /did -a-ing the newly added user to it?


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#17273 28/03/03 07:12 PM
Joined: Mar 2003
Posts: 272
C
Fjord artisan
OP Offline
Fjord artisan
C
Joined: Mar 2003
Posts: 272
I know, i know i fixed all that already, this is just what i came across when i first scripted it.


- cF
Dedicated helper for rent.

Link Copied to Clipboard