Time Control Scenario

View previous topic View next topic Go down

Time Control Scenario

Post by bwansy on Fri Nov 05, 2010 1:51 am

This is a scenario I wrote to freeze time in RC so that I could do high-speed analysis. Don't worry, I'm not using some CPU-intensive processes to slow it down. Instead, there are scenario-specific functions _PAUSE() and _PLAY().

How to use:

To switch it on:
There are 2 ways to activate time control: manually, you can press H. But in some cases, e.g. gun firing, human reaction is just not precise enough. Therefore, there's the "model-activated switch". To make it work, create a VAL called "STEPTIMESWITCH" in your model with default = 0. When this VAL is set to 1 (by KEY, RCScript or Lua), the scenario will be activated instantly. To deactivate the scenario, however, you can only press H.

While activated, press N to simulate one frame, or hold M to simulate in real-time.

Code:
require("Bernard/Basic.lua")

function OnInit()
   pauseflag = 0
   stepflag = 0
   runflag = 0
   timeframe = 0
   timer = 0
   _PLAY()
end

function OnReset()
   OnInit()
end

function startpause()
   pauseflag = 1
   _PAUSE()
   timeframe = 0
   timer = 0
end

function OnFrame()
   if pauseflag == 0 and (STEPTIMESWITCH or 0) > 0 then
      startpause()
      STEPTIMESWITCH = 0

   end
   if _SKEYDOWN(0) > 0 then
      if pauseflag == 0 then
         startpause()
      else
         pauseflag = 0
         _PLAY()
      end
   end
   if pauseflag > 0 then
      if runflag == 0 then
         if stepflag > 0 then
            _PAUSE()
            stepflag = 0
         elseif _SKEYDOWN(2) > 0 then
            stepflag = 1
            _PLAY()
         end
      end
      if _SKEYDOWN(3) > 0 then
         _PLAY()
         runflag = 1
      elseif _SKEYUP(3) > 0 then
         _PAUSE()
         runflag = 0
      end
      if runflag+stepflag > 0 then
         timeframe = timeframe+1
         timer = timer+_DT()*10
      end
   end
   out(0,"Time Manipulator by Bernard")
   out(1,"[H] switch")
   out(2,"[N] Step [M] hold to play")
   out(4,string.format("Frame: %3i",timeframe))
   out(5,string.format("Time: %10s",num2time(timer)))
   out(6,STEPTIMESWITCH)
end

_________________
A.K.A. Bernard

bwansy
Admin

Posts : 170
Join date : 2010-07-15

View user profile http://rigidchips.forum-motion.com

Back to top Go down

Re: Time Control Scenario

Post by DanielLC on Fri Nov 05, 2010 3:47 pm

It's just making the game crash when I run it.

DanielLC
Tank
Tank

Posts : 78
Join date : 2010-10-23

View user profile

Back to top Go down

Re: Time Control Scenario

Post by JHaskly on Fri Nov 05, 2010 6:43 pm

Bwansy, have you updated your libraries lately? The library I have is missing 'num2time'.

_________________
Previously (and currently) known as Juz.

Please do not write "LUA", beause it's "Lua". It's Moon in Portuguese, not a Limited User Account, Last Universal Ancestor, or the Lukla Airport in Nepal.

JHaskly
Admin

Posts : 235
Join date : 2010-07-16
Age : 21
Location : Brisbane

View user profile

Back to top Go down

Re: Time Control Scenario

Post by bwansy on Sat Nov 06, 2010 3:54 am

Whoops. Updated.

_________________
A.K.A. Bernard

bwansy
Admin

Posts : 170
Join date : 2010-07-15

View user profile http://rigidchips.forum-motion.com

Back to top Go down

Re: Time Control Scenario

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum