Re: Jumping out & back within a time loop
Posted: Wed Feb 17, 2010 10:55 pm
by vtrbojevic
Hello BvG,
I have abandoned hope for a reply, hence late post-response. First, many thanks! You were right about my confusion and you ewill see why. I would like to have several objects doing various things at different times but running at the same time. To do that I have seen in one of the excamples the following "loop":
--get the start time in ticks
command showTime
-- get the current time in ticks
--subtract current-start to get the ellapsed time
--do things
showTime
end showTime
and if I go out of the loop, then I come back by using 'send "showTime", etc. My question is: is there a better way of diung this? My main loop is attached!
Kind regards,
Vladimir Trbojevic
PS. Did not like Word doc, so it is here below:
==============================================================Time loop
global timeT, begT, endT, curT, curTsec, curTmin
#
global a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20
global b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20
global c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20
global d1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d12, d13, d14, d15, d16, d17, d18, d19, d20
global e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15, e16, e17, e18, e19, e20
#
global m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11
global gmove
global tblurb, tin
global newcoords
global curDate, limDate, tMonth, tDay, tm
global tExpired, tExDate, cExpirationDate
global gStop
global wdir
#
global tChosenColor1, tChosenColor2, tChosenColor3
global tChangedColor1, tChangedColor2, tChangedColor3
# Event related
global gHEPlac, gHExpl, gHEp1, gHEp2, gHEp3, gHEinter
global gVCplac, gVCexpl, gVCp1, gVCp2, gVCp3, gVCp4, gVcentx, gVcenty
global gPFtime, gPFdura, gPFdia
global gTCrel, gTCdev, gTCdura, gTCdist, gTCentx, gTCenty
global gDataType, gHazType, gPropType, gEmerType, gScale
# Propagation related
global gPropRad1, gPropRad2, gPropRad3, gPropTim1, gPropTim2, gPropTim3
global gHaz1, gHaz2, gHaz3, gHaz4, gEsc1, gEsc2, gEsc3, gEme1, gEme2, gEme3, gEme4
# Emergency related
global gAmbTime1, gAmbTime2, gFireTIme1, gFireTime2, gPoliTime1, gPoliTime2, gArmyTime1, gArmyTime2
global gTime1, gTime2, gTime3, gTime4, gTime5, gTime6, gTime7, gTime8, gTime9, gTime10
global gTime11, gTime12, gTime13, gTime14, gTime15, gTime16, gTime17, gTime18, gTime19, gTime20
global gTime21, gTime22, gTime23, gTime24, gTime25, gTime26, gTime27, gTime28, gTime29, gTime30
# Copy object related
global nTank, nOffice, nIndustry, nHouse
# Initiator related
global gInitiator, gEscalator1, gEScalator2, gEscalator3, gVCesc, gTCesc, gVCloc, gTCloc
global gLoc1, gLoc2, gLoc3, gLoc4
global tGrc, xTank, xLoca, zVCtank, zTCtank, tDamTank
#
local tWang1, tWang2, tWang3, tIncre, tLoca, tBottom
local tLoops, k, xTime, yTime
#
#
# Initialise time
#
command setTime
put 0 into gStop
put the ticks into begT
put 0 into field "timer"
#
put "Chemical plant & tank farm (brown objects)" into line 1 of field "Board"
put "Housing Estate (dark green objects)" into line 2 of field "Board"
put "Industrial Estate (orange objects)" into line 3 of field "Board"
put "Time: midday" into line 5 of field "Board"
#
put gHEplac into line 1 of field "bb"
put gHExpl into line 2 of field "bb"
put gVCplac into line 3 of field "bb"
put gVCexpl into line 4 of field "bb"
put gPropTim2 into line 6 of field "bb"
put gTCdev into line 8 of field "bb"
#######
put 0 into tLoops
end setTime
#
# Show time
#
command showTime
put tLoops+1 into tLoops
put tLoops into field "test"
put the ticks into curT
put (curT - begT) into timeT
put (timeT/60/60) into curTmin
set the numberFormat to "0.00"
put curTmin into field "timer"
#############################
# Check for HE explosion as INITIATOR #
#############################
if gInitiator = 1 then
if curTmin > gHEplac then
if a1 = 0 then
put 1 into a1
put curTmin into field "timer"
put gLoc1 into tLoca
set the loc of button "terrorist" to tLoca
show button "terrorist"
end if
end if
# HE explosion (bang)
if curTmin > gHExpl then
if a2 = 0 then
put 1 into a2
put curTmin into field "timer"
set loc of grc "bang" to loc of button "terrorist"
hide button "terrorist"
show grc "bang"
----------
send "mouseUp" to button "Ininter"
----------
end if
end if
# Hide "bang"
if curTmin > gHExpl+0.005 then
if a3 = 0 then
put 1 into a3
hide grc "bang"
put gHExpl+0.005 into gTime5
end if
end if
end if -- End of Initiator=1
###########################################
# Check for Vapour Cloud release & explosion as INITIATOR #
###########################################
if gInitiator = 2 then
#
if curTmin > gVCplac then
if a1 = 0 then
put 1 into a1
put curTmin into field "timer"
put gLoc2 into tLoca
set the loc of button "VC release" to tloca
show button "VC release"
put line 1 of field "winDir" into tWang1
put (gVCexpl / 4) into gTime1
put gVCplac + gTime1 into gTime2
put gVCplac+gVCexpl into gTime3
----------
send "setMe tLoca" to button "VC release"
send "mouseUp" to button "Ininter"
----------
end if
end if
if curTmin > gVCplac+0.005 then
if a2 = 0 then
put 1 into a2
----------
send "displayMe gTime1, tWang1" to button "VC release"
----------
end if
end if
# VC explosion (bang)
if curTmin > gTime3 then
if a3 = 0 then
put 1 into a3
put curTmin into field "timer"
put gVCplac+gVCexpl+0.05 into gTime4
----------
send "displayPres" to button "VC release"
----------
end if
end if
# Remove bang
if curTmin > gTime4 then
if a4 = 0 then
put 1 into a4
put gTime4+0.005 into gTime5
----------
send "mouseUp" to button "Presinter"
send "hideMe" to button "VC release"
----------
end if
end if
end if --End of Initiator=2
##########################
# Check for Pool Fire as INITIATOR #
##########################
if gInitiator = 3 then
#
if curTmin > gPFtime then
if a1 = 0 then
put 1 into a1
put curTmin into field "timer"
put gLoc3 into tLoca
set the loc of button "Pool fire" to tLoca
show button "Pool fire"
----------
send "mouseUp" to button "Ininter"
----------
end if
end if
# Remove pool fire
if curTmin > gPFtime+gPFdura then
if a3 = 0 then
put 1 into a3
hide button "Pool fire"
put gPFtime+gPFdura+0.005 into gTime5
end if
end if
end if --End of Initiator=3
############################
# Check for Toxic Cloud as INITIATOR #
############################
if gInitiator = 4 then
#
if curTmin > gTCrel then
if a1 = 0 then
put 1 into a1
put curTmin into field "timer"
put gLoc4 into tLoca
set the loc of button "TC release" to tLoca
show button "TC release"
put line 2 of field "WinDir" into tWang2
put (gTCdev / 4) into gTime1
put gTCrel+gTCdev+gTCdura into gTime3
----------
send "setMe tLoca" to button "TC release"
----------
end if
end if
if curTmin > gTCrel+0.005 then
if a2 = 0 then
put 1 into a2
----------
send "displayMe gTime1, tWang2" to button "TC release"
----------
end if
end if
# Hide toxic clouds
if curTmin > gTime3+0.1 then
if a3 = 0 then
put 1 into a3
----------
send "hideMe" to button "TC release"
----------
put gTime3+0.005 into gTime5
end if
end if
end if --End of Initiator=4
#######################################
# Check for SUBSEQUENT (SECONDARY) EVENTS #####
#######################################
#
############################
# VC tank is SECONDARY ESCALATOR #
############################
if gEscalator1 = 1 then
if curTmin > gTime5 then
if b1 = 0 then
put 1 into b1
put curTmin into field "timer"
# Secondary VC release
put xLoca into tLoca
set the loc of button "VC release" to tLoca
set the loc of grc "inter2" to tLoca
show button "VC release"
put line 1 of field "WinDir" into tWang1
put (gVCexpl / 4) into xTime
put gTime5 + xTime into gTime6
----------
send "setMe tLoca" to button "VC release"
--send "displayMe xTime, tWang1" to button "VC release"
----------
end if
end if
if curTmin > gTime6 then
if b2 = 0 then
put 1 into b2
put curTmin into field "timer"
show grc "VCloud2"
put gTime6 + xTime into gTime7
end if
end if
if curTmin > gTime7 then
if b3 = 0 then
put 1 into b3
put curTmin into field "timer"
send "rotateMe tWang1" to grc "VCloud3"
show grc "VCloud3"
put gTime7 + xTime into gTime8
end if
end if
if curTmin > gTime8 then
if b4 = 0 then
put 1 into b4
put curTmin into field "timer"
send "rotateMe tWang1" to grc "VCloud4"
show grc "VCloud4"
put gTime8 + 0.001 into gTime9
end if
end if
----------
if curTmin > gTime9 then
if b5 = 0 then
put 1 into b5
put curTmin into field "timer"
put gTime9 + 0.001 into gTime10
----------
send "displayPres" to button "VC release"
----------
end if
end if
if curTmin > gTime10 then
if b6 = 0 then
put 1 into b6
put curTmin into field "timer"
put gTime10+(nTank-1)*gPropTim3 into gTime11
put gTime11 into gTime20
----------
send "mouseUp" to button "Presinter"
send "hideMe" to button "VC release"
put 1 into gVCesc
send "startEscalation" to button "Escinter"
----------
end if
end if
# Further escalation with TC clouds
if gTCesc = 1 then
if curTmin > gTime11 then
if b7 = 0 then
put 1 into b7
put curTmin into field "timer"
put line 3 of field "tankescal" into k
put "tank"&k into tGrc
put the loc of grc tGrc into tLoca
set the loc of button "TC release" to tLoca
show button "TC release"
put line 2 of field "WinDir" into tWang2
put (gTCdev / 4) into yTime
put gTime11 + yTime into gTime12
----------
send "setMe tLoca" to button "TC release"
----------
end if
end if
if curTmin > gTime12 then
if b8 = 0 then
put 1 into b8
put curTmin into field "timer"
----------
--send "displayMe yTime, tWang2" to button "TC release"
----------
put gTime12 + yTime into gTime13
end if
end if
if curTmin > gTime13 then
if b9 = 0 then
put 1 into b9
put curTmin into field "timer"
show grc "TCloud1"
put gTime13 + yTime into gTime14
end if
end if
----------
if curTmin > gTime14 then
if b10 = 0 then
put 1 into b10
put curTmin into field "timer"
send "rotateMe tWang2" to grc "TCloud2"
show grc "TCloud2"
put gTime14 + yTime into gTime15
end if
end if
if curTmin > gTime15 then
if b11 = 0 then
put 1 into b11
put curTmin into field "timer"
send "rotateMe tWang2" to grc "TCloud3"
show grc "TCloud3"
put gTime15 + 0.001 into gTime16
end if
end if
---------
if curTmin > gTime16 then
if b12 = 0 then
put 1 into b12
put curTmin into field "timer"
put curTmin into field "timer"
----------
send "hideMe" to button "TC release"
----------
put gTime16+0.001 into gTime20
end if
end if
end if
# End of further escalation by TC
end if
# End of VC as escalation
############################
# PF tank is SECONDARY ESCALATOR #
############################
if gEscalator1 = 2 then
if curTmin > gTime5 then
if c1 = 0 then
put 1 into c1
put curTmin into field "timer"
put xLoca into tLoca
set the loc of grc "inter3" to tLoca
show grc "inter3"
put gTime5+nTank*gPropTim3 into gTime6
---------
send "startEscalation" to button "Escinter"
---------
end if
end if
# Further escalation with VC clouds
if gVCesc = 1 then
if curTmin > gTime6 then
if c2 = 0 then
put 1 into c2
put curTmin into field "timer"
# Secondary VC release
put gVCloc into tLoca
set the loc of button "VC release" to tLoca
set the loc of grc "inter2" to tLoca
show button "VC release"
put line 1 of field "WinDir" into tWang1
put (gVCexpl / 4) into xTime
put gTime6 + xTime into gTime7
----------
send "setMe tLoca" to button "VC release"
--send "displayMe xTime, tWang1" to button "VC release"
----------
end if
end if
----------
if curTmin > gTime7 then
if c3 = 0 then
put 1 into c3
put curTmin into field "timer"
show grc "VCloud2"
put gTime7 + xTime into gTime8
end if
end if
if curTmin > gTime8 then
if c4 = 0 then
put 1 into c4
put curTmin into field "timer"
send "rotateMe tWang1" to grc "VCloud3"
show grc "VCloud3"
put gTime8 + xTime into gTime9
end if
end if
if curTmin > gTime9 then
if c5 = 0 then
put 1 into c5
put curTmin into field "timer"
send "rotateMe tWang1" to grc "VCloud4"
show grc "VCloud4"
put gTime9+0.001 into gTime10
end if
end if
----------
if curTmin > gTime10 then
if c6 = 0 then
put 1 into c6
put curTmin into field "timer"
put gTime10 + 0.03 into gTime11
----------
send "displayPres" to button "VC release"
----------
end if
end if
if curTmin > gTime11 then
if c7 = 0 then
put 1 into c7
put curTmin into field "timer"
put gTime11 + 0.001 into gTime20
----------
send "mouseUp" to button "Presinter"
send "hideMe" to button "VC release"
put 1 into gVCesc
--send "startEscalation" to button "Escinter" -- alrady done at the start!
----------
end if
end if
# End of further escalation by VC
end if
# Further escalation with TC clouds
if gTCesc = 1 then
if curTmin > gTime6+0.01 then
if c8 = 0 then
put 1 into c8
put curTmin into field "timer"
put line 3 of field "tankescal" into k
put "tank"&k into tGrc
put the loc of grc tGrc into tLoca
set the loc of button "TC release" to tLoca
show button "TC release"
put line 2 of field "WinDir" into tWang2
put (gTCdev / 4) into yTime
put gTime6 + yTime into gTime12
----------
send "setMe tLoca" to button "TC release"
----------
end if
end if
if curTmin > gTime12 then
if c9 = 0 then
put 1 into c9
put curTmin into field "timer"
----------
--send "displayMe yTime, tWang2" to button "TC release"
----------
put gTime12 + yTime into gTime13
end if
end if
----------
if curTmin > gTime13 then
if c10 = 0 then
put 1 into c10
show grc "TCloud1"
put gTime13 + yTime into gTime14
end if
end if
if curTmin > gTime14 then
if c11 = 0 then
put 1 into c11
send "rotateMe tWang2" to grc "TCloud2"
show grc "TCloud2"
put gTime14 + yTime into gTime15
end if
end if
if curTmin > gTime15 then
if c12 = 0 then
put 1 into c12
send "rotateMe tWang2" to grc "TCloud3"
show grc "TCloud3"
put gTime15 + gTCdura into gTime16
end if
end if
----------
if curTmin > gTime16 then
if c13 = 0 then
put 1 into c13
put curTmin into field "timer"
----------
send "hideMe" to button "TC release"
----------
put gTime16 + 0.01 into gTime20
end if
end if
end if
# End of further escalation by TC
end if
# End of PF as escalator
############################
# TC tank as SECONDARY ESCALATOR #
############################
if gEScalator1 = 3 then
if curTmin > gTime5 then
if b12 = 0 then
put 1 into b12
put curTmin into field "timer"
---------
--TC clouding
---------
end if
end if
end if
#######################
# Check Emergency Response #
#######################
if gEme1 = 1 then
if gAmbTime1 <> 0 then
if curTmin > gAmbTime1 then
if d1 = 0 then
put 1 into d1
put "Amb1 on its way" into line 15 of field "Board"
send "mouseUp" to img "amb1"
end if
end if
end if
if gAmbTime2 <> 0 then
if curTmin > gAmbTime2 then
if d2 = 0 then
put 1 into d2
send "mouseUp" to img "amb2"
end if
end if
end if
end if
#
#
--if curTmin > gTime23 then
if curTmin > 2 then
if d10 = 0 then
put 1 into d10
stopTime
end if
end if
#
# Main time driver
#
wait 200 millisec with messages
showTime
#
end showTime
###############################################################
command stopTime
send "mouseUp" to button "stop"
end stopTime
###############################################################