![]() |
SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997 |
04-20-10, 07:51 PM
|
#1 |
|
sim2reality
![]() Join Date: Jun 2007
Location: AM 82
Posts: 2,288
Downloads: 262
Uploads: 31
|
Hi trying to get a switch to toggle an item hidden/visible.
But having no luck, I can get the switch to make the item visible but can't get it to toggle again (Item stays visible - button doesn't change state). Here' my code: Code:
#Page attack periscope.py from menu import * # Globals AOBFswitch = False def InitializeScript(): Menu.PageActivated += Menu_PageActivated Menu.PageDeactivated += Menu_PageDeactivated Menu_PageActivated( Pageattackperiscope ) Pageattackperiscope_RAOBF.Visible = False Pageattackperiscope_AOBFToggle.Visible = True Pageattackperiscope_AOBFToggle.Clicked += AOBFToggle AOBFToggle( None ) #pass def StartGame(): pass def AOBFToggle( sender ): global AOBFswitch AOBFswitch = not AOBFswitch Pageattackperiscope_RAOBF.Visible = AOBFswitch def UnloadScript(): Menu.PageActivated -= Menu_PageActivated Menu.PageDeactivated -= Menu_PageDeactivated Pageattackperiscope_AOBFToggle.Clicked -= AOBFToggle pass def Menu_PageActivated( page ): if page == Pageattackperiscope: from PageTDC import PageTDC PageTDC.Visible = True def Menu_PageDeactivated( page ): if page == Pageattackperiscope: from PageTDC import PageTDC PageTDC.Visible = False def EndGame(): pass My guess is I'm doing something wrong here: def AOBFToggle( sender ): global AOBFswitch AOBFswitch = not AOBFswitch Pageattackperiscope_RAOBF.Visible = AOBFswitch Last edited by reaper7; 04-21-10 at 08:48 AM. |
|
|
04-21-10, 08:51 AM
|
#2 |
|
sim2reality
![]() Join Date: Jun 2007
Location: AM 82
Posts: 2,288
Downloads: 262
Uploads: 31
|
Bump: Highlighted the part of code to do with the switch to make it easier to read.
|
|
|
04-21-10, 09:58 AM
|
#3 |
|
Black Magic
![]() |
try this for debugging purposes:
def AOBFToggle( sender ): global AOBFswitch AOBFswitch = not AOBFswitch # show the state of the switch for debugging purposes ScriptManagerManaged.ShowPythonError( "AOBFswitch=" + str(AOBFswitch) ) Pageattackperiscope_RAOBF.Visible = AOBFswitch this will show a dialogbox saying AOBFswitch= either true or false so you can see if the switch is really toggling or not. |
|
|
04-21-10, 12:26 PM
|
#4 | |
|
sim2reality
![]() Join Date: Jun 2007
Location: AM 82
Posts: 2,288
Downloads: 262
Uploads: 31
|
EDIT: Just tried it out and my code was useless, but the same code for the switch works perfectly.
![]() CODE] Quote:
Was just coming to post to say I got it working when I seen your reply theDarkWraith. There was nothing wrong with the code at all .It was my layers order in the Menu Editor the Switch Toggle Button was under the actual Dial layer. That meant when the switch was toggled the Dial appeared but as the button was under the Dial layers tranparent section, it was basically masked of from being clicked again .Wasted a full day trying to figure that one out. ![]() Thanks for the debug code, I was just using basic messages in debug code to show what part of the script i'm in didn't relise you make it display the actual string: ("AOBFswitch=" + str(AOBFswitch) ) Will make use of that in the future. Cheers ![]() @TheDarkWraith While this code works for a Toggle button [Bt] - The switch will always defauls to it standard graphic state If one wanted to do a on/off buttonn you would need to use a checkbox [Ck] instead of a button so then: 1st click on - (Display on state Graphic) 2nd click off -(Display off state Graphic)....etc What type code would be needed for that? would it be similar to above. Eg. Code:
def AOBFToggle( sender ): if AOBFToggle = True: Pageattackperiscope_RAOBF.Visible = True elif AOBFToggle = False: Pageattackperiscope_RAOBF.Visible = False Last edited by reaper7; 04-21-10 at 01:49 PM. Reason: Solution found |
|
|
|
![]() |
|
|
