SUBSIM Radio Room Forums



SUBSIM: The Web's #1 resource for all submarine & naval simulations since 1997

Go Back   SUBSIM Radio Room Forums > Silent Hunter 3 - 4 - 5 > SH5 Mods Workshop
Forget password? Reset here

Reply
 
Thread Tools Display Modes
Old 04-20-10, 07:51 PM   #1
reaper7
sim2reality
 
Join Date: Jun 2007
Location: AM 82
Posts: 2,288
Downloads: 262
Uploads: 31
Default [TEC] Help from the Scripters

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
Anything obvious
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.
reaper7 is offline   Reply With Quote
Old 04-21-10, 08:51 AM   #2
reaper7
sim2reality
 
Join Date: Jun 2007
Location: AM 82
Posts: 2,288
Downloads: 262
Uploads: 31
Default

Bump: Highlighted the part of code to do with the switch to make it easier to read.
reaper7 is offline   Reply With Quote
Old 04-21-10, 09:58 AM   #3
TheDarkWraith
Black Magic
 
Join Date: Jun 2007
Posts: 11,959
Downloads: 147
Uploads: 5


Default

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.
TheDarkWraith is offline   Reply With Quote
Old 04-21-10, 12:26 PM   #4
reaper7
sim2reality
 
Join Date: Jun 2007
Location: AM 82
Posts: 2,288
Downloads: 262
Uploads: 31
Default

EDIT: Just tried it out and my code was useless, but the same code for the switch works perfectly.


CODE]
Quote:
Originally Posted by TheDarkWraith View Post
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.

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
reaper7 is offline   Reply With Quote
Reply

Thread Tools
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


All times are GMT -5. The time now is 09:11 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Copyright © 1995- 2026 Subsim®
"Subsim" is a registered trademark, all rights reserved.