Old 22nd December 2019, 22:56   #1
mhertz
Junior Member
 
Join Date: Dec 2019
Posts: 6
.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:
code:

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:
code:

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:
code:

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!
mhertz is offline   Reply With Quote
Old 23rd December 2019, 00:24   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,222
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:

PHP Code:
Function .onSelChange
This is not like radio buttonsboth can be unselected:
${If} $
= ${Section1}
${
AndIf} ${SectionIsSelected} ${Section1}
    !
insertmacro UnselectSection "${Section2}"
${ElseIf} ${SectionIsSelected} ${Section2}
    !
insertmacro UnselectSection "${Section1}"
${EndIf}
FunctionEnd 
PHP Code:
Function .onSelChange
Radio:
${If} $
= ${Section1}
    !
insertmacro SelectSection "${Section1}"
    
!insertmacro UnselectSection "${Section2}"
${Else}
    !
insertmacro SelectSection "${Section2}"
    
!insertmacro UnselectSection "${Section1}"
${EndIf}
FunctionEnd 

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 23rd December 2019, 20:23   #3
mhertz
Junior Member
 
Join Date: Dec 2019
Posts: 6
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!
mhertz is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump