Ok Changed the Code to the following (Alot cleaner now

): No errors, but still only the part thats codded to change to a button press responds.
Have Coloured the lines in Red that activate the controls that are made visible/hidden depending on the timecheck. This one
Pageobsperiscope_ObsGraticule.Visible = GetCurrentGameDateTime() needs to update itself without user action (Timer can be every minute - doesn't need to be every second would that be
RefreshTimerDuration = 60.0)
The other instance works on a button press:
Timecheck = GetCurrentGameDateTime()
if Timecheck == True:
Pageobsperiscope_RAOBFGraticuleBkg.Visible = RAOBFShown
Pageobsperiscope_RAOBFGraticule.Visible = RAOBFShown
and this works perfectly but only if the user presses the button.
How can I set an action to initiate a function once the timer is reached
e.g call the
GetCurrentGameDateTime() every minute while Page is open.
Code:
#Page obs periscope.py
# Globals
AttackDiscShown = True
RAOBFShown = True
TimerID_CheckTime = 299000001
RefreshTimerDuration = 1.0
from menu import *
from game import Game
def InitializeScript():
Pageobsperiscope_ShipContext_LockButton.Visible = False
Pageobsperiscope_LockToggle.Clicked += LockToggle
Pageobsperiscope_RAOBFToggle.Visible = True
Pageobsperiscope_RAOBFToggle.Clicked += RAOBFToggle
Pageobsperiscope_AttackDiscToggle.Visible = True
Pageobsperiscope_AttackDiscToggle.Clicked += AttackDiscToggle
Pageobsperiscope_ObsGraticule.Visible = GetCurrentGameDateTime()
RAOBFToggle( None )
AttackDiscToggle( None )
LockToggle( None )
def Menu_PageActivated( page ):
if page == Pageobsperiscope:
Pageobsperiscope.AnimationStopped += Pageobsperiscope_AnimationStopped
Pageobsperiscope.StopAnimationsOfType( MenuItemWrapper.AnimationTypes.Timer )
Pageobsperiscope.StartAnimation( MenuItemWrapper.AnimationTypes.Timer, 1, RefreshTimerDuration ).ID = TimerID_CheckTime
Pageobsperiscope_ObsGraticule.Visible = GetCurrentGameDateTime()
def Pageobsperiscope_AnimationStopped( Animation ):
if not Menu.IsInMission:
return
if animation.ID == TimerID_CheckTime:
Pageobsperiscope.StartAnimation( MenuItemWrapper.AnimationTypes.Timer, 1, RefreshTimerDuration ).ID = TimerID_CheckTime
def StartGame():
Pageobsperiscope_RAOBF.Visible = False
Pageobsperiscope_AttackDisc.Visible = False
pass
def GetCurrentGameDateTime():
d = Game.CurrentGameDateTime
if d.Hour in [ 22,23,0,1,2,3,4,5, ]:
return True
else:
return False
def LockToggle( sender ):
Game.SubmarineCommands.ExecuteCommand( "Toggle_lock_target" )
def RAOBFToggle( sender ):
global RAOBFShown
RAOBFShown = not RAOBFShown
Pageobsperiscope_RAOBF.Visible = RAOBFShown
Timecheck = GetCurrentGameDateTime()
if Timecheck == True:
Pageobsperiscope_RAOBFGraticuleBkg.Visible = RAOBFShown
Pageobsperiscope_RAOBFGraticule.Visible = RAOBFShown
else:
Pageobsperiscope_RAOBFGraticuleBkg.Visible = RAOBFShown
def AttackDiscToggle( sender ):
global AttackDiscShown
AttackDiscShown = not AttackDiscShown
Pageobsperiscope_AttackDisc.Visible = not AttackDiscShown
def Menu_PageDeactivated( page ):
if page == Pageobsperiscope:
Pageobsperiscope.StopAnimationsOfType( MenuItemWrapper.AnimationTypes.Timer )
Pageobsperiscope.AnimationStopped -= Pageobsperiscope_AnimationStopped
def EndGame():
pass
def UnloadScript():
Pageobsperiscope_LockToggle.Clicked -= LockToggle
Pageobsperiscope_RAOBFToggle.Clicked -= RAOBFToggle
Pageobsperiscope_AttackDiscToggle.Clicked -= AttackDiscToggle
pass
Thanks for all your help DW, hope all my questions on scripting aren't taking you away from your own work. But its great that we have Code Geniuses to help us noobes

.