Controlling two checkboxes against each other


#1

I need two checkboxes where only one can be enabled and checked. I found a way to do it with if statements but would there be a different (correct!?) way to do it?

try destroyDialog gui catch()

rollout gui "checkboxes" (
	
	checkbox ckbx0 "checkbox 0" checked:true align:#left orient:#vertical across:2
	checkbox ckbx1 "checkbox 1" align:#left enabled:false

	on ckbx0 changed state do (
		if ckbx0.checked == true then (
			ckbx1.enabled = false
		) else (
			ckbx1.enabled = true
		)
	)
	
	on ckbx1 changed state do (
		if ckbx1.checked == true then (
			ckbx0.enabled = false
		) else (
			ckbx0.enabled = true
		)
	)
)

createDialog gui 200 25

thanks for any help on this.


#2
try destroyDialog gui catch()

rollout gui "checkboxes" (
	
	checkbox ckbx0 "checkbox 0" checked:true align:#left orient:#vertical across:2
	checkbox ckbx1 "checkbox 1" align:#left enabled:false

	on ckbx0 changed state do (
			ckbx1.enabled = not state
	)
	
	on ckbx1 changed state do (
			ckbx0.enabled = not state
	)
)

createDialog gui 200 25

#3

Thanks miauu,

I was close to this at one point but didn’t know about being able to place a not before state.

much cleaner :smiley: