mIRC Homepage
Posted By: raZOR dialog init - 10/05/06 07:11 PM
to not post whole dialog + code i jump on important...

everything that i have in init event ~20 lines of code/events work exept this one (any only one that wont work)

if ( $lines($mircdirsystem\spam_channels.txt) = 0 ) { .did -m protect 49 }

and it doesnt matter if i put it on begining of init or whereever...

but when i try it debug like this:

//if ( $lines($mircdirsystem\spam_channels.txt) = 0 ) //echo -a empty | else //echo -a not empty

it works...
so why wont it disable ID in dialog init if it is correct syntax ?
Posted By: MikeChat Re: dialog init - 10/05/06 07:27 PM
where you have if ( $lines($mircdirsystem\spam_channels.txt) = 0 ) { .did -m protect 49 }

did you mean if ( $lines($mircdirsystem\spam_channels.txt) == 0 ) { dialog -m protect 49 }
Posted By: SladeKraven Re: dialog init - 10/05/06 07:31 PM
Make sure it's an edit box you're trying to disable.

/did -b Will disable ID's.
Posted By: raZOR Re: dialog init - 10/05/06 07:42 PM
oh god... im so stupid
lol

answer was in -b =)

/me hides

thanks heh
Posted By: MikeChat Re: dialog init - 10/05/06 07:47 PM
try this to test, in the init section put
echo -a file test: $lines($mircdirsystem\spam_channels.txt)

if that line comes back with nothing after the "file test" then its $null

then this should work

if ( $lines($mircdirsystem\spam_channels.txt) == $null ) { did -m protect 49 }

-b disable id
-m disables editbox

Posted By: raZOR Re: dialog init - 10/05/06 08:40 PM
yeah =)
i messed up with editbox where i should use ID
(not -m but -b)

also i wish to ask, what code should it go for LIST control
that for example when it is empty (nothing is SELECTED) id is disabled, and when there is something SELECTED that ID becomes enabled.

because for now i have dialog on init to check if file.txt is empty or not, and same goes in dialog sclick events
but kinda looks stupid to have ID (Button) enabled if nothing is selected (i use dialog thru which user can add something to list(.txt file) and remove things from same)

i can post full code if it is needed
Posted By: Pia007 Re: dialog init - 10/05/06 09:09 PM
hey guys
Posted By: hixxy Re: dialog init - 11/05/06 03:19 AM
Code:
on *:dialog:[color:red]name[/color]:init:*: did -b $dname [color:red]ID_OF_BUTTON[/color]
on *:dialog:[color:red]name[/color]:sclick:[color:red]ID_OF_LISTBOX[/color]: did -e $dname [color:red]ID_OF_BUTTON[/color]


Half of this stuff is explained in the help file.. Feel free to read it some time smile
Posted By: Abstract Re: dialog init - 11/05/06 02:20 PM
Using this thread... could someone tell me if it is possible to define many Default buttons, one per tab?

I have something like that:

Code:
  button "Add", 7, 112 40 20 10, flat default tab 1
  button "Add", 14, 112 40 20 10, flat default tab 2


And so on... but it doesn't seem to work, I only get the first button like default, ignoring the rest of declarations. Any idea?

Thanx!
Posted By: qwerty Re: dialog init - 11/05/06 02:30 PM
You need to do it at runtime: use the sclick event to watch for tab clicks and the /did -t command to dynamically set the default button.
Posted By: raZOR Re: dialog init - 11/05/06 04:03 PM
Quote:
Code:
on *:dialog:[color:red]name[/color]:init:*: did -b $dname [color:red]ID_OF_BUTTON[/color]
on *:dialog:[color:red]name[/color]:sclick:[color:red]ID_OF_LISTBOX[/color]: did -e $dname [color:red]ID_OF_BUTTON[/color]


Half of this stuff is explained in the help file.. Feel free to read it some time smile


yes i understand those events :P
but i dont understand what should i write in List SCLICK
so it detects if LIST is empty or not ?

i have this code:

if ($did = 46) {
if ($did(46).lines == 0) { .did -b protect 49 }
}

where 46 is list control and 49 is button
and when list control is clicked on (and has no lines)
button does NOT become disabled
Posted By: hixxy Re: dialog init - 11/05/06 04:08 PM
The sclick event isn't fired unless an item is selected in the listbox, so your script will never run.
Posted By: raZOR Re: dialog init - 11/05/06 04:09 PM
so in other words, this is impossible what i need ?
Posted By: hixxy Re: dialog init - 11/05/06 04:26 PM
Yes but you could work around it. Check out this example:

Code:
dialog t {
  title ""
  size -1 -1 300 300
  option dbu
  list 1, 0 0 300 270, vsbar
  button "clear", 2, 270 270 20 20
  button "add item", 3, 240 270 20 20
}
on *:dialog:t:mouse:*:{
  if ($did(2).enabled) && (!$did(1).lines) did -b $dname 2
  elseif ($did(1).lines) && (!$did(2).enabled) did -e $dname 2
}
on *:dialog:t:sclick:2: did -r $dname 1
on *:dialog:t:sclick:3: did -a $dname 1 test
Posted By: qwerty Re: dialog init - 11/05/06 04:55 PM
Or you could employ a different logic altogether: since your script always knows when text is added/removed (assuming the user doesn't type /did -a/-r himself!), you can do what you want at those moments. More specifically

[*]Open your dialog with the button disabled.
[*]Whenever the sclick event for that listbox fires, it means a (non-empty) line was selected, so enable the button.
[*]Whenever something is removed from the listbox, check $did().sel (either $did(id,0).sel or $did(id,1).sel). If it's 0, disable the button.
[*]Whenever the listbox is overwritten with text (eg a file is loaded over any existing text), disable the button.
Posted By: raZOR Re: dialog init - 11/05/06 05:00 PM
nice =)
thanks

@qWerty

will try =)
thanks
Posted By: raZOR Re: dialog init - 11/05/06 05:30 PM
well now i have this
Code:
  
  if ($did = 49) { 
    if ($did(46,1).sel) { 
 some code that re-loads contents of .txt into list
    }
    if ($did(46,0).sel) { .did -b protect 49 }
  ;this is where it should disable button 49
  }



but its not working
Posted By: hixxy Re: dialog init - 11/05/06 05:33 PM
Code:
    if ([color:red]![/color]$did(46,0).sel) { .did -b protect 49 }
Posted By: SladeKraven Re: dialog init - 11/05/06 05:36 PM
Try

Code:
  if ([color:red]![/color]$did(46,0).sel) { .did -b protect 49 }


Edit: hixxy beat me to it.
Posted By: qwerty Re: dialog init - 11/05/06 05:37 PM
if ($did(46,0).sel) { .did -b protect 49 }

This will disable the button if nothing is selected in the listbox. Isn't that the opposite of what you want? Also, if you reload a .txt by overwriting the listbox (and not by appending to it), no line will be selected after the file is reloaded, so you can just disable the button without checking anything.

Edit: SladeKraven beat me to it :tongue:
Posted By: raZOR Re: dialog init - 11/05/06 05:41 PM
uh uh
now i am confused

isnt ,0 = no line
and ,1 = some line ?

and my goal is to button disable ONLY if there is nothing in listbox

coz when i remove all from list, the button is still enabled
Posted By: SladeKraven Re: dialog init - 11/05/06 05:49 PM
1 is true, 0 is false.

You're checking to see if the control does have a value. When you should be checking to see if the control doesn't have a value.
Posted By: qwerty Re: dialog init - 11/05/06 05:55 PM
No, you should read the help file on $did().sel (and in fact the entire page on dialogs). Also, when you don't know what something does exactly, USE /echo. Bold cannot stress this enough, /echo is the best way to figure out how stuff works.

$did(name,id,0) -> total number of selected lines
$did(name,id,1) -> index of 1st selected line
$did(name,id,2) -> index of 2nd selected line

Inside an on DIALOG event $did(name,id,N) can be $did(id,N)
Posted By: raZOR Re: dialog init - 11/05/06 05:55 PM
so then

this : if (! $did(46,0 ).sel) { .did -b protect 49 }
is equal to this?
if ($did(46,1 ).sel) { .did -b protect 49 }

?
Posted By: raZOR Re: dialog init - 11/05/06 05:58 PM
"$did(name,id,0) -> total number of selected lines"

then by some logic it should be

if ($did(name,id,0) == 0) { disable coz it has no lines }
no?

anyways that code by hixxy (last) and Slade works.
i just now want to figure out this logic coz it has no
sence to me
Posted By: qwerty Re: dialog init - 11/05/06 06:00 PM
Yes.
if ($did(name,id,0) == 0)
is the same as
if (!$did(name,id,0))

which is what hixxy used
Posted By: raZOR Re: dialog init - 11/05/06 06:08 PM
ehm i just noticed that code actually doesnt work for me smirk

@qwerty
so if that is true:

if ($did(name,id,0) == 0)

then why my button does NOT get disabled
when nothing is in list control ?
Posted By: hixxy Re: dialog init - 11/05/06 06:35 PM
Code:
if ($did(name,id,0)[color:red].sel[/color] == 0)


Sometimes, people on here make mistakes in their posts or assume you know what to do and write shorthand versions. It's ok to try and correct things yourself sometimes.
Posted By: qwerty Re: dialog init - 11/05/06 06:38 PM
Oops, I guess I copied raZOR's mistake, thanks.
Posted By: hixxy Re: dialog init - 11/05/06 07:07 PM
Np smile Happens to everyone.
Posted By: raZOR Re: dialog init - 11/05/06 07:20 PM
hmm
there is 1 odd thing happen
when i click on list but not ON content (like if i have added 3 lines of something, so i click below them) list PASSIVE selects some line and on execution (button) button get disabled confused

yes, it works when ACTIVE selected line, but why it disables on PASSIVE select ?
Posted By: hixxy Re: dialog init - 11/05/06 07:21 PM
Eh? Could you rephrase that?
Posted By: raZOR Re: dialog init - 11/05/06 07:26 PM


when listbox is PASSIVE selected and i click on remove button, button is disabled and ofcourse nothing is removed from list . so why this happen (disables button) if i didnt selected anything ?
Posted By: hixxy Re: dialog init - 11/05/06 07:31 PM
Because nothing is selected. One of the items has focus, but it's not selected.
Posted By: raZOR Re: dialog init - 11/05/06 07:33 PM
uh oh...

so while trying to have checkup if no lines are in list
it disables button but in same time if nothing is selected
even there are things to select it disables button again...

lol?

so is this like.. only way it can be ?
Posted By: hixxy Re: dialog init - 11/05/06 07:35 PM
I don't get you.
Posted By: MikeChat Re: dialog init - 11/05/06 08:12 PM
Quote:
uh oh...

so while trying to have checkup if no lines are in list
it disables button but in same time if nothing is selected
even there are things to select it disables button again...

lol?

so is this like.. only way it can be ?


I would say no it doesnt require that something be selected, I have not tested it though.

post your code here and one of will have a solution.

However I think you cant check to see if ID 46 has any lines
on :dialog:NAME:sclick:46:{
if ($did(!$dname,46).lines) { did -b $dname 49 }
else {
did -e $dname 49
code to do something with $did(46).seltext
}
Posted By: raZOR Re: dialog init - 11/05/06 10:22 PM
well if it cannot be done, then i dont wish to bug people :P
ill choose then most fitting solution form all previous givent codes and suggestions.

so i say thanks to all who helped me here smile

thank you.
Posted By: MikeChat Re: dialog init - 12/05/06 12:02 AM
does this do what you want to do?

sample
Code:
dialog list {
  title "List Box"
  size -1 -1 200 100
  option dbu
  list 100, 20 20 160 60
  button "Add", 900, 30 75 60 10
  button "Remove", 901, 110 75 60 10
}

;; disable the remove button when starting
on *:dialog:list:init:0:{
  did -b list 901
}

;; Add something to the listbox, 
;; and if something is added, enable the remove button
on *:dialog:list:sclick:900:{
  if ($cb(0)) { 
    did -a list 100 $cb 
    did -e list 901 
  }
} 

;; Remove a line from the list
;; if the list is empty, disable the remove button
on *:dialog:list:sclick:901:{
  did -d list 100 $did(list,100).sel
  if (!$did(list,100).lines) { did -b list 901 }
} 
Posted By: raZOR Re: dialog init - 12/05/06 02:15 PM
yes exactly that, and it works except i get error
/did invalied parameters for

did -d something 100 $did(list,100).sel

when list control is passive selected
Posted By: MikeChat Re: dialog init - 12/05/06 05:40 PM
Qwerty said:
Quote:

You need to do it at runtime: use the sclick event to watch for tab clicks and the /did -t command to dynamically set the default button.


so test with this
Code:

alias list dialog -m list list

dialog list {
  title "List Box"
  size -1 -1 200 100
  option dbu
  tab "One", 1, 0 0 200 100
  tab "Two", 2
  list 100, 20 20 160 60, tab 1
  button "Add", 900, 30 75 60 10, tab 1
  button "Remove", 901, 110 75 60 10, tab 1
  list 101, 20 20 160 60, tab 2
  button "Add", 902, 30 75 60 10, tab 2
  button "Remove", 903, 110 75 60 10, tab 2
}
on *:dialog:list:init:0:{
  did -b list 901,903
}
on *:dialog:list:sclick:1:{
  did -t list 100 1
}
on *:dialog:list:sclick:2:{
  did -t list 101 1
}
on *:dialog:list:sclick:900:{
  if ($cb(0)) { 
    did -a list 100 $cb 
    did -e list 901 
  }
}  
on *:dialog:list:sclick:901:{
  did -d list 100 $did(list,100).sel
  if (!$did(list,100).lines) { did -b list 901 }
}

on *:dialog:list:sclick:902:{
  if ($cb(0)) { 
    did -a list 101 $cb 
    did -e list 903 
  }
}  
on *:dialog:list:sclick:903:{
  did -d list 101 $did(list,101).sel
  if (!$did(list,101).lines) { did -b list 903 }
}
Posted By: raZOR Re: dialog init - 12/05/06 05:46 PM
it does same errors :P
Posted By: MikeChat Re: dialog init - 12/05/06 06:02 PM
I have tested it here again, and i get no errors
what are the errors you get??
did you paste my code or are you adapting yours and still getting errors there?
Posted By: raZOR Re: dialog init - 12/05/06 06:19 PM
i copy/pasted YOUR code (last) and only changed dialog name coz it fux up when i call /list

i get errors on this lines:

for tab 1
did -d listme 100 $did(listme,100).sel

for tab 2
did -d listme 101 $did(listme,101).sel

to repeat i get in passive click this errors, not in active
Posted By: MikeChat Re: dialog init - 12/05/06 06:44 PM
whether passive or active (and the sclick for the tab ID should stop passive)
I get no errors
Code:
alias listme dialog -m listme listme

dialog listme {
  title "listme Box"
  size -1 -1 200 100
  option dbu
  tab "One", 1, 0 0 200 100
  tab "Two", 2
  list 100, 20 20 160 60, tab 1
  button "Add", 900, 30 75 60 10, tab 1
  button "Remove", 901, 110 75 60 10, tab 1
  list 101, 20 20 160 60, tab 2
  button "Add", 902, 30 75 60 10, tab 2
  button "Remove", 903, 110 75 60 10, tab 2
}
on *:dialog:listme:init:0:{
  did -b listme 901,903
}
on *:dialog:listme:sclick:1:{
  did -t listme 100 1
}
on *:dialog:listme:sclick:2:{
  did -t listme 101 1
}
on *:dialog:listme:sclick:900:{
  if ($cb(0)) { 
    did -a listme 100 $cb 
    did -e listme 901 
  }
}  
on *:dialog:listme:sclick:901:{
  did -d listme 100 $did(listme,100).sel
  if (!$did(listme,100).lines) { did -b listme 901 }
}

on *:dialog:listme:sclick:902:{
  if ($cb(0)) { 
    did -a listme 101 $cb 
    did -e listme 903 
  }
}  
on *:dialog:listme:sclick:903:{
  did -d listme 101 $did(listme,101).sel
  if (!$did(listme,101).lines) { did -b listme 903 }
}


renamed it all
Posted By: raZOR Re: dialog init - 12/05/06 06:49 PM
now tried on clean mirc 6.17
i get same errors for same lines.

ehm... weird case ?
Posted By: MikeChat Re: dialog init - 12/05/06 06:58 PM
Since I don't get the error, maybe someone else can tell you what is causing the error and how to get rid of it.
Posted By: MikeChat Re: dialog init - 12/05/06 07:07 PM
you could try changing these lines
on *:dialog:listme:sclick:1:{
did -t listme 100 1
}
on *:dialog:listme:sclick:2:{
did -t listme 101 1
}

to
on *:dialog:listme:sclick:1:{
did -t listme 900
}
on *:dialog:listme:sclick:2:{
did -t listme 902
}
Posted By: raZOR Re: dialog init - 12/05/06 07:19 PM
same errors
Posted By: hixxy Re: dialog init - 13/05/06 07:36 AM
If you're using the same definition of 'passive' as the screenshot earlier, I told you, nothing is actually selected there, so .sel will always be 0.
Posted By: raZOR Re: dialog init - 13/05/06 10:54 AM
well if .sel is always 0
then why doesnt this code prevent it ?

if ($did(listme,100).sel == 0) { did -b listme 901 }

or it is impossible to have this kind of "detection" :P ?

sorry for being dumb smile
Posted By: hixxy Re: dialog init - 13/05/06 03:14 PM
Where abouts is that if statement?
Posted By: raZOR Re: dialog init - 13/05/06 03:55 PM
on *:dialog:listme:sclick:901:{
did -d listme 100 $did(listme,100).sel
if ($did(listme,100).sel == 0) { did -b listme 901 }
if (!$did(listme,100).lines) { did -b listme 901 }
}

i put it before line detection
Posted By: hixxy Re: dialog init - 13/05/06 04:24 PM
Try this:

Code:
on *:dialog:listme:sclick:901:{
  if (!$did(100).sel) || (!$did(100).lines) { 
    did -b listme 901 
    return
  }
  did -d listme 100 $did(100).sel
  did -b listme 901
}


It's not very logical to try and delete the selected item and THEN check if there's one selected :tongue:
Posted By: raZOR Re: dialog init - 13/05/06 04:53 PM
now it dont give errors but it disables in passive remove
and when clicked on item (that IS there) it isnt enabled anymore :P

"It's not very logical to try and delete the selected item and THEN check if there's one selected"

sure is, if you want to see if there is anything left or not.
Posted By: hixxy Re: dialog init - 13/05/06 05:01 PM
Quote:
now it dont give errors but it disables in passive remove
and when clicked on item (that IS there) it isnt enabled anymore :P


Code:
on *:dialog:listme:sclick:100: did -e listme 901


Quote:
sure is, if you want to see if there is anything left or not.


Yeah, I was talking about error prevention though.
Posted By: raZOR Re: dialog init - 13/05/06 06:01 PM
thank you so much, to all of you !
this work perfect now !!!

/me buys cookies to all
© mIRC Discussion Forums