Board index Roller Coaster Games NoLimits Coaster 2 NoLimits Coaster 2 Scripting Scripting a Delay

Scripting a Delay

Post your Nolimits 2 scripts here! Also any discussion regarding scription for NoLimits Coaster 2 should be placed in this forum

Post July 15th, 2016, 5:35 pm

Posts: 14
Points on hand: 1,326.00 Points
Location: Leverkusen, Germany
Hello Everyone,

I recently build a nice Coaster and used the Script Generator to make it run nice :D

Now there's one Problem that I have.

There's a Switch which is changing its direction a little bit too early and the only thing i want to do, is to add a Delay in this Line.
else{
              Switch3Switch.setSwitchDirection(1);               
            }


Just about a Pause or Interruption of the Script for about 2 seconds.

Hope you Guys can help me.

Post July 18th, 2016, 1:58 pm
herman116 User avatar
Premium Member
Premium Member

Posts: 636
Points on hand: 7,471.00 Points
Location: The Netherlands
I took a quick look at the API but I can't find a delay (maybe I'm looking on the wrong place or maybe there really is no delay function).

However, there is a way to create a delay of 2 seconds with the following code (I haven't tested this code so it might not work directly):

public static int TimeStartDelay;
// your main code

else{
  TimeStartDelay = System.currentTimeMillis();
  if (TimeStartDelay + 2000 < System.currentTimeMillis()) {
    Switch3Switch.setSwitchDirection(1);
  }
}


What this code basically does is save the current time when the switch would be switched. Then it will wait until the saved time + 2000 milliseconds (2 seconds) is passed. Then it will execute the switch.

Post July 26th, 2016, 10:07 am

Posts: 8144
Points on hand: 13,491.00 Points
Herman you indeed are the "Second" Code Master. :)
-- I was happy to be with NL1 - [:')] --

Post July 26th, 2016, 2:31 pm

Posts: 14
Points on hand: 1,326.00 Points
Location: Leverkusen, Germany
I think it would work well, but No Limits gives the Error that an integer is expected but it found a long "possible loss of precision" and won't start up the Coaster

when "TimeStartDelay" is changed to be a long, it works, but switches again too early

Post July 29th, 2016, 2:05 pm
herman116 User avatar
Premium Member
Premium Member

Posts: 636
Points on hand: 7,471.00 Points
Location: The Netherlands
That's weird... I looked through the script again and I've seen a small bug. But the weird part is that the bug should prevent the coaster from switching instead of making it switch at the normal time... This is the code with the bug solved:

public static double TimeStartDelay = 0;
// your main code

else{
  if (TimeStartDelay == 0) {
    TimeStartDelay = System.currentTimeMillis();
  }
  if (TimeStartDelay + 2000 < System.currentTimeMillis()) {
    Switch3Switch.setSwitchDirection(1);
    TimeStartDelay = 0;
  }
}


But if this doesn't work, you can PM me the code file, then I can have a quick look to see whats wrong.


Return to NoLimits Coaster 2 Scripting

 


  • Related topics
    Replies
    Views
    Last post