Not signed in (Sign In)

Discussion Tag Cloud

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthorDibDibs
    • CommentTimeAug 27th 2016 edited
     
    Hi, I am trying to get a delay for some block brakes using a script, I have tried many methods such as this one...

    but they all lag out the game and cause it to not respond.

    I thought of this one by myself, but it still lags the game out...
    for (int t=1; t<=2000; t++){
    System.out.println("Waiting");
    }

    All I need is a bit of code that will sleep for 2 seconds before releasing the brakes. Thanks in advance for any help :)
    • CommentAuthorDelay
    • CommentTimeAug 27th 2016
     
    If it is what I think, you don't even need a script to do so.

    If a brake is defined to be a block brake and the train stops there (by checking the box), you can define the time the train stand still for (in seconds).
    • CommentAuthorDibDibs
    • CommentTimeAug 27th 2016
     
    so if I add a delay to the block brake, I can still script when they are engaged. I am using a script to engage them when the train hits a trigger, then to disengage them and turn the transports on backwards.
    •  
      CommentAuthorHafizBazzi
    • CommentTimeAug 27th 2016 edited
     
    If your talking about making the train stop in a block, than leave the block backwards, use the script generator, its download is somewhere on the fourms.
    Edit: http://forum.nolimits-exchange.com/comments.php?DiscussionID=3345
    • CommentAuthorDibDibs
    • CommentTimeAug 27th 2016 edited
     
    I am aware of that but I just want to know how to do delays.
    If only NL2 used real java, then we'd have access to loads of useful packages.
    •  
      CommentAuthorHafizBazzi
    • CommentTimeAug 27th 2016
     
    What do you mean by delay, if you mean the train comes to a complete stop in the block before moving on, than just press complete stop in the type settings menu and the amount of time. Just saying how to do a delay is very vauge.
    •  
      CommentAuthorbestdani
    • CommentTimeAug 27th 2016 edited
     
    Posted By: DibDibsthen we'd have access to loads of useful packages.

    Which one are you missing for this?

    You don't need a for loop, as you normaly process the block script in the onNextFrame(float tick) method that is called by the internal script handler before a new frame will be rendered where tick is the time difference (in seconds) between the last and the upcoming frame you can just sum the ticks when the train is in the block section like this pseudo code shows:


    import com.nolimitscoaster.*;

    public class MyCoasterScript extends Script{
    private static final float WAIT_TIME = 2.f;
    private float waitTimer = 0.f;
    private bool isTrainInWaitBlock = false;

    // ...

    public void onNextFrame(float tick){
    // ...

    if(isTrainInWaitBlock){
    if(waitTimer >= WAIT_TIME){
    // waited for WAIT_TIME seconds, move train out of the block.

    setTrainLeaveBlock(); //assumed to set isTrainInWaitBlock = false
    waitTimer = 0.f;
    }else{
    //waiting, sum up ticks

    waitTimer += tick;
    }
    }
    }
    }