Author Topic: UIToggle Starting State (is driving me nuts)  (Read 4045 times)

sonicviz

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 58
    • View Profile
UIToggle Starting State (is driving me nuts)
« on: June 14, 2014, 08:11:18 AM »
I have a settings panel with a number of checkboxes using UIToggle (NGUI 3.6.2) to control showing/hiding some gui elements

for example: UIToggle keyboardToggle

I have set up delegates to accept value changes but not really using it as they are set on a settings panel that is accessed via a screen button.
User then hits a back button to go back to the main play scene with the new settings controlling what is shown.

I am checking keyboardToggle.value when the apps main view is shown when going back to the scene from the settings panel.
It is also checked the very first time when going from a loading info screen with a big play button.

Issue:
If I set the starting transition to unchecked the keyboardToggle.value = true when I go the main scene the very first time.
I checked this via a Debug in a start method.
But...when I go to the settings panel it gets flipped to false (reflecting the correct starting state) and also correctly shows unchecked without me doing anything.

It's driving me nuts. Why isn't it getting set to false initially when it should be?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIToggle Starting State (is driving me nuts)
« Reply #1 on: June 15, 2014, 03:42:31 AM »
Your description is not quite clear... first you say "when I go to the settings panel it gets flipped to false (reflecting the correct starting state)" then "why isn't it getting set to false"?

If the starting state is false, it will always start as false. There is nothing to "flip" it. It's just how it starts. Note that if you use groups (non-zero group ID) then your checkboxes become radio buttons instead.

sonicviz

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 58
    • View Profile
Re: UIToggle Starting State (is driving me nuts)
« Reply #2 on: June 15, 2014, 06:21:16 AM »
Your description is not quite clear... first you say "when I go to the settings panel it gets flipped to false (reflecting the correct starting state)" then "why isn't it getting set to false"?

If the starting state is false, it will always start as false. There is nothing to "flip" it. It's just how it starts. Note that if you use groups (non-zero group ID) then your checkboxes become radio buttons instead.

That's funny, I thought it was pretty clear.

I have a Debug.log message in a start method that shows the UIToggle is false, when it should be true.
I even put the UIToggle up the top of the script execution order list and it still shows true.
It's only when I accessed a panel that actually has the widget with said UIToggles on it does it get set to false - without me actually touching it.


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIToggle Starting State (is driving me nuts)
« Reply #3 on: June 15, 2014, 06:39:56 AM »
The toggle's state before its Start() function actually runs is in "startsActive" rather than 'value'. I'm guessing this is what you're running into? Try changing the UIToggle's value property to this:
  1.         public bool value
  2.         {
  3.                 get
  4.                 {
  5.                         return mStarted ? mIsActive : startsActive;
  6.                 }
  7.                 set
  8.                 {
  9.                         if (!mStarted) startsActive = value;
  10.                         else if (group == 0 || value || optionCanBeNone || !mStarted) Set(value);
  11.                 }
  12.         }

sonicviz

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 58
    • View Profile
Re: UIToggle Starting State (is driving me nuts)
« Reply #4 on: June 16, 2014, 01:58:19 AM »
The toggle's state before its Start() function actually runs is in "startsActive" rather than 'value'. I'm guessing this is what you're running into? Try changing the UIToggle's value property to this:
  1.         public bool value
  2.         {
  3.                 get
  4.                 {
  5.                         return mStarted ? mIsActive : startsActive;
  6.                 }
  7.                 set
  8.                 {
  9.                         if (!mStarted) startsActive = value;
  10.                         else if (group == 0 || value || optionCanBeNone || !mStarted) Set(value);
  11.                 }
  12.         }

Yes, that fixes it thank you!

Will this become part of next release? I'd hate to have to re-add every time I update.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIToggle Starting State (is driving me nuts)
« Reply #5 on: June 16, 2014, 08:28:39 AM »
Already a part of 3.6.4b released yesterday. ;)