Skip to content
⌘ NSIS Forum Archive

.onSelChange question of unselectsection etc.

3 posts

mhertz#

.onSelChange question of unselectsection etc.

I'm sorry, this is a beginner slash stupid question, but kindly bear with me please.

I have issue with when conditionally wanting one checkbox to unselect another and vice-versa, it only works one way but never the other? I'm sure though i'm misunderstanding something obvious.

Let's take a simple example, two checkboxes section1 and section2, where the first is selected by default. When selecting section2, then I want section1 to be unticked, and vice-versa. However with my tries it never works like that, and only works one way, but never the other, and neither when having more dynamic checkboxes than in my simple example here:

Section "foo" Section1
SectionEnd

Section /o "bar" Section2
SectionEnd

Function .onSelChange
${If} ${SectionIsSelected} ${Section1}
!insertmacro UnselectSection "${Section2}"
${EndIf}
${If} ${SectionIsSelected} ${Section2}
!insertmacro UnselectSection "${Section1}"
${EndIf}
Or:

Section "foo" Section1
SectionEnd

Section /o "bar" Section2
SectionEnd

Function .onSelChange
${If} ${SectionIsSelected} ${Section1}
!insertmacro UnselectSection "${Section2}"
${Else}
${If} ${SectionIsSelected} ${Section2}
!insertmacro UnselectSection "${Section1}"
${EndIf}
${EndIf}
Or simply:

Section "foo" Section1
SectionEnd

Section /o "bar" Section2
SectionEnd

Function .onSelChange
${If} ${SectionIsSelected} ${Section1}
!insertmacro UnselectSection "${Section2}"
${Else}
!insertmacro UnselectSection "${Section1}"
${EndIf}
Or with e.g. ${OrIf} instead it's the same, and I just don't get it sorry, while of course knowing i'm an idiot here and fully missing something completely obvious, for anybody else than me though 🙂

Thank you so much in advance!
Anders#
In NSIS 2 you probably have to keep some state, take a look at Examples\one-section.nsi

In NSIS 3 the index of the changed section is in $0:

Function .onSelChange
; This is not like radio buttons, both can be unselected:
${If} $0 = ${Section1}
${AndIf} ${SectionIsSelected} ${Section1}
    !insertmacro UnselectSection "${Section2}"
${ElseIf} ${SectionIsSelected} ${Section2}
    !insertmacro UnselectSection "${Section1}"
${EndIf}
FunctionEnd 
Function .onSelChange
; Radio:
${If} $0 = ${Section1}
    !insertmacro SelectSection "${Section1}"
    !insertmacro UnselectSection "${Section2}"
${Else}
    !insertmacro SelectSection "${Section2}"
    !insertmacro UnselectSection "${Section1}"
${EndIf}
FunctionEnd 
mhertz#
Thanks alot Anders for your kind help once again! 🙂 I always thought checkboxes and radiobuttons where the same just different shaped lol, now I understand the distinction, which i'm happy to utilise hence forward, but just for now i'm sticking to checkboxes untill I get the hang of it more/fully.

I honestly don't get why a state is needed when making a comparisson, and if both checkboxes are unticked then obviously the comparissons all should just return void and unmatched(as code run on every change happening), but what do I know.

Anyway, i'm really glad I know now that I have to utilize that $0 then(i'm on NSIS3 latest), I did saw that before but never thought it was actually needed.

Testing your first example of course works beatifully, what a nice feeling seeing something finally working as intended! Especially after so many failings.

Thank you so much again!