Log in

View Full Version : [TEC] Help from the Scripters


reaper7
04-20-10, 07:51 PM
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:

#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 :nope:
My guess is I'm doing something wrong here:

def AOBFToggle( sender ):
global AOBFswitch
AOBFswitch = not AOBFswitch
Pageattackperiscope_RAOBF.Visible = AOBFswitch

reaper7
04-21-10, 08:51 AM
Bump: Highlighted the part of code to do with the switch to make it easier to read.

TheDarkWraith
04-21-10, 09:58 AM
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.

reaper7
04-21-10, 12:26 PM
EDIT: Just tried it out and my code was useless, but the same code for the switch works perfectly. :rock:


CODE]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 :nope:.
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 :88).
Wasted a full day trying to figure that one out. :har:

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

@TheDarkWraith

While this code works for a Toggle button - 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.


def AOBFToggle( sender ):
[B]if AOBFToggle = True:
Pageattackperiscope_RAOBF.Visible = True
elif AOBFToggle = False:
Pageattackperiscope_RAOBF.Visible = False