reaper7
05-04-10, 03:23 PM
I need some help with a script. I require to monitor the period of time in the Day eg Dawn, Dusk Day or Night (Well really I only need the Night).
I have got that part of the code working (Tested it by linking the code to a button so when pressed it checked the time and activated the item respectively).
But I can't get the game to update the item by its self. I have looked through the Dev's and TheDarkWraiths scripts at the timer code but can't seem to get it to work (The script editor doesn't throw up any errors).
Following ip the relevant timer section from my script, can anyone tell me why this part does not seem to be reached;
d = Game.CurrentGameDateTime
if d.Hour in [ 22,23,0,1,2,3,4,5, ]:
ScriptManagerManaged.ShowPythonError("Night Time")
Pageobsperiscope_ObsGraticule.Visible = True
else:
ScriptManagerManaged.ShowPythonError("Not Night Time")
Pageobsperiscope_ObsGraticule.Visible = False
Like I said if I use the above attached to a button it works, but in the timer code when I enter a station it does not seem to ever go into that part of the code:
#Page obs periscope.py
TimerID_CheckTime = 299000001
RefreshTimerDuration = 0.5
from menu import *
from game import Game
def InitializeScript():
pass
def Menu_PageActivated( page ):
ScriptManagerManaged.ShowPythonError("Page Activated")
if page == Pageobsperiscope:
Pageobsperiscope.AnimationStopped += Pageobsperiscope_AnimationStopped
Pageobsperiscope.StopAnimationsOfType( MenuItemWrapper.AnimationTypes.Timer )
Pageobsperiscope.StartAnimation( MenuItemWrapper.AnimationTypes.Timer, 1, RefreshTimerDuration ).ID = TimerID_CheckTime
def Pageobsperiscope_AnimationStopped( Animation ):
ScriptManagerManaged.ShowPythonError("AnimationStopped")
if animation.ID != TimerID_CheckTime:
Pageobsperiscope.StartAnimation( MenuItemWrapper.AnimationTypes.Timer, 1, RefreshTimerDuration ).ID = TimerID_CheckTime
if not Menu.IsInMission:
return
d = Game.CurrentGameDateTime
if d.Hour in [ 22,23,0,1,2,3,4,5, ]:
ScriptManagerManaged.ShowPythonError("Night Time")
Pageobsperiscope_ObsGraticule.Visible = True
else:
ScriptManagerManaged.ShowPythonError("Not Night Time")
Pageobsperiscope_ObsGraticule.Visible = False
def StartGame():
pass
def Menu_PageDeactivated( page ):
ScriptManagerManaged.ShowPythonError("Page Deactivated")
if page == Pageobsperiscope:
Pageobsperiscope.StopAnimationsOfType( MenuItemWrapper.AnimationTypes.Timer )
Pageobsperiscope.AnimationStopped -= Pageobsperiscope_AnimationStopped
def EndGame():
pass
def UnloadScript():
pass
Here is the full script in case it makes more sence:
#Page obs periscope.py
TimerID_CheckTime = 299000001
RefreshTimerDuration = 0.6
from menu import *
from game import Game
# Globals
AttackDiscShown = True
RAOBFShown = True
def InitializeScript():
ScriptManagerManaged.ShowPythonError("InitalizeScript")
Pageobsperiscope_ShipContext_LockButton.Visible = False
Pageobsperiscope_ShipContext_UpArrow.Visible = False
Pageobsperiscope_ShipContext_DownArrow.Visible = False
Pageobsperiscope_LockToggle.Clicked += LockToggle
Pageobsperiscope_RAOBFToggle.Visible = True
#Pageobsperiscope_RAOBFToggle.ToolTip = "Range & Angle on Bow Finder"
Pageobsperiscope_RAOBFToggle.Clicked += RAOBFToggle
Pageobsperiscope_AttackDiscToggle.Visible = True
#Pageobsperiscope_AttackDiscToggle.ToolTip = "Attack Disc"
Pageobsperiscope_AttackDiscToggle.Clicked += AttackDiscToggle
RAOBFToggle( None )
AttackDiscToggle( None )
LockToggle( None )
def Menu_PageActivated( page ):
ScriptManagerManaged.ShowPythonError("Page Activated")
if page == Pageobsperiscope:
Pageobsperiscope.AnimationStopped += Pageobsperiscope_AnimationStopped
Pageobsperiscope.StopAnimationsOfType( MenuItemWrapper.AnimationTypes.Timer )
# start the polling
Pageobsperiscope.StartAnimation( MenuItemWrapper.AnimationTypes.Timer, 1, RefreshTimerDuration ).ID = TimerID_CheckTime
def Pageobsperiscope_AnimationStopped( Animation ):
ScriptManagerManaged.ShowPythonError("AnimationStopped")
if animation.ID != TimerID_CheckTime:
Pageobsperiscope.StartAnimation( MenuItemWrapper.AnimationTypes.Timer, 1, RefreshTimerDuration ).ID = TimerID_CheckTime
if not Menu.IsInMission:
return
d = Game.CurrentGameDateTime
if d.Hour in [ 22,23,0,1,2,3,4,5, ]:
Pageobsperiscope_ObsGraticule.Visible = True
ScriptManagerManaged.ShowPythonError("NightTime")
else:
Pageobsperiscope_ObsGraticule.Visible = False
ScriptManagerManaged.ShowPythonError("DayTime")
def StartGame():
ScriptManagerManaged.ShowPythonError("StartGame")
Pageobsperiscope_RAOBF.Visible = False
Pageobsperiscope_AttackDisc.Visible = False
pass
def LockToggle( sender ):
ScriptManagerManaged.ShowPythonError("lockToggle")
Game.SubmarineCommands.ExecuteCommand( "Toggle_lock_target" )
def RAOBFToggle( sender ):
ScriptManagerManaged.ShowPythonError("RAOBFToggle")
global RAOBFShown
RAOBFShown = not RAOBFShown
Pageobsperiscope_RAOBF.Visible = RAOBFShown
#Pageobsperiscope_RAOBFGraticule.Visible = RAOBFShown
#Pageobsperiscope_RAOBFGraticuleBkg.Visible = RAOBFShown
#This is the part were it works as tied to a button
d = Game.CurrentGameDateTime
if d.Hour in [ 22,23,0,1,2,3,4,5, ]:
ScriptManagerManaged.ShowPythonError("NightTime")
Pageobsperiscope_RAOBFGraticuleBkg.Visible = RAOBFShown
Pageobsperiscope_RAOBFGraticule.Visible = RAOBFShown
else:
ScriptManagerManaged.ShowPythonError("DayTime")
Pageobsperiscope_RAOBFGraticuleBkg.Visible = RAOBFShown
def AttackDiscToggle( sender ):
ScriptManagerManaged.ShowPythonError("AttackDiscToggle")
global AttackDiscShown
AttackDiscShown = not AttackDiscShown
Pageobsperiscope_AttackDisc.Visible = not AttackDiscShown
def Menu_PageDeactivated( page ):
ScriptManagerManaged.ShowPythonError("Page Deactivated")
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
Any suggestions. :-?
I have got that part of the code working (Tested it by linking the code to a button so when pressed it checked the time and activated the item respectively).
But I can't get the game to update the item by its self. I have looked through the Dev's and TheDarkWraiths scripts at the timer code but can't seem to get it to work (The script editor doesn't throw up any errors).
Following ip the relevant timer section from my script, can anyone tell me why this part does not seem to be reached;
d = Game.CurrentGameDateTime
if d.Hour in [ 22,23,0,1,2,3,4,5, ]:
ScriptManagerManaged.ShowPythonError("Night Time")
Pageobsperiscope_ObsGraticule.Visible = True
else:
ScriptManagerManaged.ShowPythonError("Not Night Time")
Pageobsperiscope_ObsGraticule.Visible = False
Like I said if I use the above attached to a button it works, but in the timer code when I enter a station it does not seem to ever go into that part of the code:
#Page obs periscope.py
TimerID_CheckTime = 299000001
RefreshTimerDuration = 0.5
from menu import *
from game import Game
def InitializeScript():
pass
def Menu_PageActivated( page ):
ScriptManagerManaged.ShowPythonError("Page Activated")
if page == Pageobsperiscope:
Pageobsperiscope.AnimationStopped += Pageobsperiscope_AnimationStopped
Pageobsperiscope.StopAnimationsOfType( MenuItemWrapper.AnimationTypes.Timer )
Pageobsperiscope.StartAnimation( MenuItemWrapper.AnimationTypes.Timer, 1, RefreshTimerDuration ).ID = TimerID_CheckTime
def Pageobsperiscope_AnimationStopped( Animation ):
ScriptManagerManaged.ShowPythonError("AnimationStopped")
if animation.ID != TimerID_CheckTime:
Pageobsperiscope.StartAnimation( MenuItemWrapper.AnimationTypes.Timer, 1, RefreshTimerDuration ).ID = TimerID_CheckTime
if not Menu.IsInMission:
return
d = Game.CurrentGameDateTime
if d.Hour in [ 22,23,0,1,2,3,4,5, ]:
ScriptManagerManaged.ShowPythonError("Night Time")
Pageobsperiscope_ObsGraticule.Visible = True
else:
ScriptManagerManaged.ShowPythonError("Not Night Time")
Pageobsperiscope_ObsGraticule.Visible = False
def StartGame():
pass
def Menu_PageDeactivated( page ):
ScriptManagerManaged.ShowPythonError("Page Deactivated")
if page == Pageobsperiscope:
Pageobsperiscope.StopAnimationsOfType( MenuItemWrapper.AnimationTypes.Timer )
Pageobsperiscope.AnimationStopped -= Pageobsperiscope_AnimationStopped
def EndGame():
pass
def UnloadScript():
pass
Here is the full script in case it makes more sence:
#Page obs periscope.py
TimerID_CheckTime = 299000001
RefreshTimerDuration = 0.6
from menu import *
from game import Game
# Globals
AttackDiscShown = True
RAOBFShown = True
def InitializeScript():
ScriptManagerManaged.ShowPythonError("InitalizeScript")
Pageobsperiscope_ShipContext_LockButton.Visible = False
Pageobsperiscope_ShipContext_UpArrow.Visible = False
Pageobsperiscope_ShipContext_DownArrow.Visible = False
Pageobsperiscope_LockToggle.Clicked += LockToggle
Pageobsperiscope_RAOBFToggle.Visible = True
#Pageobsperiscope_RAOBFToggle.ToolTip = "Range & Angle on Bow Finder"
Pageobsperiscope_RAOBFToggle.Clicked += RAOBFToggle
Pageobsperiscope_AttackDiscToggle.Visible = True
#Pageobsperiscope_AttackDiscToggle.ToolTip = "Attack Disc"
Pageobsperiscope_AttackDiscToggle.Clicked += AttackDiscToggle
RAOBFToggle( None )
AttackDiscToggle( None )
LockToggle( None )
def Menu_PageActivated( page ):
ScriptManagerManaged.ShowPythonError("Page Activated")
if page == Pageobsperiscope:
Pageobsperiscope.AnimationStopped += Pageobsperiscope_AnimationStopped
Pageobsperiscope.StopAnimationsOfType( MenuItemWrapper.AnimationTypes.Timer )
# start the polling
Pageobsperiscope.StartAnimation( MenuItemWrapper.AnimationTypes.Timer, 1, RefreshTimerDuration ).ID = TimerID_CheckTime
def Pageobsperiscope_AnimationStopped( Animation ):
ScriptManagerManaged.ShowPythonError("AnimationStopped")
if animation.ID != TimerID_CheckTime:
Pageobsperiscope.StartAnimation( MenuItemWrapper.AnimationTypes.Timer, 1, RefreshTimerDuration ).ID = TimerID_CheckTime
if not Menu.IsInMission:
return
d = Game.CurrentGameDateTime
if d.Hour in [ 22,23,0,1,2,3,4,5, ]:
Pageobsperiscope_ObsGraticule.Visible = True
ScriptManagerManaged.ShowPythonError("NightTime")
else:
Pageobsperiscope_ObsGraticule.Visible = False
ScriptManagerManaged.ShowPythonError("DayTime")
def StartGame():
ScriptManagerManaged.ShowPythonError("StartGame")
Pageobsperiscope_RAOBF.Visible = False
Pageobsperiscope_AttackDisc.Visible = False
pass
def LockToggle( sender ):
ScriptManagerManaged.ShowPythonError("lockToggle")
Game.SubmarineCommands.ExecuteCommand( "Toggle_lock_target" )
def RAOBFToggle( sender ):
ScriptManagerManaged.ShowPythonError("RAOBFToggle")
global RAOBFShown
RAOBFShown = not RAOBFShown
Pageobsperiscope_RAOBF.Visible = RAOBFShown
#Pageobsperiscope_RAOBFGraticule.Visible = RAOBFShown
#Pageobsperiscope_RAOBFGraticuleBkg.Visible = RAOBFShown
#This is the part were it works as tied to a button
d = Game.CurrentGameDateTime
if d.Hour in [ 22,23,0,1,2,3,4,5, ]:
ScriptManagerManaged.ShowPythonError("NightTime")
Pageobsperiscope_RAOBFGraticuleBkg.Visible = RAOBFShown
Pageobsperiscope_RAOBFGraticule.Visible = RAOBFShown
else:
ScriptManagerManaged.ShowPythonError("DayTime")
Pageobsperiscope_RAOBFGraticuleBkg.Visible = RAOBFShown
def AttackDiscToggle( sender ):
ScriptManagerManaged.ShowPythonError("AttackDiscToggle")
global AttackDiscShown
AttackDiscShown = not AttackDiscShown
Pageobsperiscope_AttackDisc.Visible = not AttackDiscShown
def Menu_PageDeactivated( page ):
ScriptManagerManaged.ShowPythonError("Page Deactivated")
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
Any suggestions. :-?