Hi Sparrowhawk
smallg is correct the "current time" was never being reset/updated each cycle, so it was basically a "starting time"
I edited your code with comment to show you what was happening, it also works now.
I already had the other script, for some flashing lights, I just changed it to suit your needs..
Note: When you hide an entity its physical mesh is still on the map, so if the entity its large enough it will obstruct the player and other ai entites. That is, it will act like a barrier that you cannot get passed. So if you don't want this you need to turn its collision off when you hide it, and back on when you show it again, like I did in the first script.
Cheers.
-- Skip First Loop Run
theOneFirstLoop = 1
-- time variable
timeRead = 0
timeBeforeChange = 5000
-- state
State =1
function thetwo_init(e)
end
function thetwo_main(e)
if theOneFirstLoop == 1 then
theOneFirstLoop = 0
return
end
runAlgorithm()
end
function runAlgorithm()
if timeRead == 0 then
timeRead = g_Time -- This was only being set on startup
end
if State ==1 then
if g_Time - timeRead > timeBeforeChange then -- So here your checking if current time > delay (5000)
Hide(25)
Show (26)
State = 2
end
end
if State == 2 then
-- if g_Time - timeRead > timeBeforeChange then -- So here your checking if current time > delay (5000). this was already true as soon as the first state 1 was true so it would go straight back to state 1. as the current time was not being reset. ie: timeRead = g_Time
if g_Time - timeRead > timeBeforeChange*2 then -- So here we are now checking if current time > delay times 2 (10000).
Hide(26)
Show (25)
State = 1
timeRead = g_Time -- Here we are now resetting timeRead to the current g_Time, so state 1 will now wait 5 seconds before it is true again.
-- timeRead = 0 -- will do the same thing as the above line, you can use this one or the above one.
end
end
-- Prompt(g_Time.. " : " ..timeRead) -- I find using prompts really helps with debugging, just comment them out when you are finished.
end
Here is another way it could be done..
-- Skip First Loop Run
theOneFirstLoop = 1
-- time variable
timeRead = 0
timeBeforeChange = 5000
-- state
State =1
function thetwo_init(e)
end
function thetwo_main(e)
if theOneFirstLoop == 1 then
theOneFirstLoop = 0
return
end
runAlgorithm()
end
function runAlgorithm()
if timeRead == 0 then
timeRead = g_Time -- This was only being set on startup, and now after state 2 has been completed.
end
if State ==1 then
if g_Time - timeRead > timeBeforeChange then -- So here your checking if current time > delay (5000)
Hide(25)
Show (26)
State = 2
timeRead = g_Time -- resetting timeRead to the current g_Time. (This cannot be timeRead = 0 as it wont update for the 2nd state)
end
end
if State == 2 then
if g_Time - timeRead > timeBeforeChange then -- So here we are now checking if current time > delay (5000).
Hide(26)
Show (25)
State = 1
--timeRead = g_Time -- Here we are now resetting timeRead to the current g_Time, so state 1 will now wait 5 seconds before it is true again.
timeRead = 0 -- will do the same thing as the above line, you can use this one or the above one.
end
end
--Prompt(g_Time.. " : " ..timeRead) -- I find using prompts really helps with debugging, just comment them out when you are finished.
end
Desktop: Intel(R) Core(TM) i7-4790 CPU @ 3.60GHz (8 CPUs), ~3.6GHz, Windows 8.1 64-bit, 16 GB Ram, NVIDIA GeForce GTX 750 Ti, Display Memory: 4018 MB. Resolution 1360x768, Passmark 3528.
Laptop: Pavilion dv6 Notebook, Intel(R) Core(TM) i5-2410M CPU @ 2.30 GHz, Win 7 64 bit, 16 GB Ram, Radeon (TM) HD 6490M, 2336 MB Memory. Resolution 1366x768, Intel(R) HD Graphics 3000. (WEI 5.8)