-- set globals
-- assumes the first frame is named Frame_0
gNextFrame = 0;
-- the maximum number of frames, remember we are 0 based
-- so if there are ten frames then the last frame
-- would be Frame_9
MAX_FRAMES = 10;
-- number of seconds to wait till showing the next frame
INTERVAL_SEC = 3
-- initialize, always needed
function Initialise()
SetFrame( 0 );
end
-- update, always needed
function Update( time )
SetFrame( time );
end
-- this is where all the heavy lifting is done
function SetFrame( currTime )
-- loop through each frame every three seconds
-- if the current time is 0 then we are initializing the model
if (math.mod(math.floor(currTime), INTERVAL_SEC) == 0 or currTime == 0) then
local index = 0;
while (index < MAX_FRAMES) do
-- if the frame is equal to the index then turn it on
if (index == gNextFrame) then
-- Call( "*:ActivateNode", "1_1000_Frame_" .. index .. "_fx_day", 1 );
Call( "*:ActivateNode", "1_1000_Node" .. index, 1 );
else -- turn the frame off
-- Call( "*:ActivateNode", "1_1000_Frame_" .. index .. "_fx_day", 0 );
Call( "*:ActivateNode", "1_1000_Node" .. index, 0 );
end
index = index + 1;
end
-- if we cycled through all the frames then reset to the first frame
if (gNextFrame < MAX_FRAMES) then
gNextFrame = gNextFrame + 1;
else
gNextFrame = 0;
end
end
end
PapaXpress wrote:That could be true Mike, but the code that snippet it originated from is working fine on the GP40. In fact I am wrote two more variations of it on our digital speedo.

-- set globals
-- assumes the first frame is named Frame_0
-- however it appears we need to work backwards??
gNextNode = 9;
-- the maximum number of frames, remember we are 0 based
-- so if there are ten frames then the last frame
-- would be Frame_9
MAX_NODES = 10;
-- number of seconds to wait till showing the next frame
INTERVAL_SEC = 2;
-- use this to determine if the interval has passed
gNextTime = 0.0;
-- initialize, always needed
function Initialise()
Call( "BeginUpdate" )
end
-- update, always needed
function Update( time )
SetNode( );
end
-- this is where all the heavy lifting is done
function SetNode()
-- first get the time, then find out if the interval has passed (test for 0)
local currTime = Call("*:GetSimulationTime", 0);
-- there is a trick here because this function is called several times
-- per second, not on the second, so we need to build a semaphore to
-- guard it from cycling though all the frames within the span of
-- one second
if (currTime > gNextTime) then
local index = 0;
while (index < MAX_NODES) do
-- if the frame is equal to the index then turn it on
if (index == gNextNode) then
Call( "*:ActivateNode", "Node_" .. index, 1 );
else -- turn the frame off
Call( "*:ActivateNode", "Node_" .. index, 0 );
end
index = index + 1;
end
-- if we cycled through all the frames then reset to the first frame
-- remember that we seem to need to flip through the frames backwards
if (gNextNode ~= 0) then
gNextNode = gNextNode - 1;
else
gNextNode = MAX_NODES - 1;
end
-- set the semaphore
gNextTime = currTime + INTERVAL_SEC;
end
end
-- set globals
-- assumes the first frame is named Node_0
-- however it appears we need to work backwards??
gNextNode = 9;
-- the maximum number of nodes, remember we are 0 based
-- so if there are ten nodes then the last node
-- would be Node_9
MAX_NODES = 10;
-- number of seconds to wait till showing the next frame
INTERVAL_SEC = 2;
-- use this to determine if the interval has passed
gNextTime = 0.0;
-- initialize, always needed
function Initialise()
Call( "BeginUpdate" )
end
-- update, always needed
function Update( time )
SetNode( );
end
-- this is where all the heavy lifting is done
function SetNode()
-- first get the time, then find out if the interval has passed (test for 0)
local currTime = Call("*:GetSimulationTime", 0);
-- there is a trick here because this function is called several times
-- per second, not on the second, so we need to build a semaphore to
-- guard it from cycling though all the frames within the span of
-- one second
if (currTime > gNextTime) then
local index = 0;
while (index < MAX_NODES) do
-- if the frame is equal to the index then turn it on
if (index == gNextNode) then
Call( "*:ActivateNode", "Node_" .. index .. "_fx_night", 1 );
else -- turn the frame off
Call( "*:ActivateNode", "Node_" .. index .. "_fx_night", 0 );
end
index = index + 1;
end
-- if we cycled through all the frames then reset to the first frame
-- remember that we seem to need to flip through the frames backwards
if (gNextNode ~= 0) then
gNextNode = gNextNode - 1;
else
gNextNode = MAX_NODES - 1;
end
-- set the semaphore
gNextTime = currTime + INTERVAL_SEC;
end
end
if (currTime > gNextTime) thenPapaXpress wrote:...I forgot to add the very important function 'Call( "BeginUpdate" )' in the Initialise. Without that Update() will be called only once (if memory serves)....

Chacal wrote:Sure, in this line
- Code: Select all
if (currTime > gNextTime) then
just add a test for the current time being between, say, 8PM and 8 AM.
I don't quite remember the syntax but I'm sure Papa does.
dogrokket wrote:Here's the night: https://www.youtube.com/watch?v=rTUG0C2coO0

Users browsing this forum: No registered users and 34 guests