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

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 05-04-10, 03:23 PM   #1
reaper7
sim2reality
 
Join Date: Jun 2007
Location: AM 82
Posts: 2,280
Downloads: 258
Uploads: 30
Default [TEC] Need Help with a script

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:

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:

Code:
#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.
reaper7 is offline   Reply With Quote
 


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 11:30 AM.


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