Board index Roller Coaster Games NoLimits Coaster 2 NoLimits Coaster 2 Scripting Tools.switchRampC2() problem

Tools.switchRampC2() problem

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

Post September 25th, 2014, 2:06 pm

Posts: 242
Points on hand: 493.00 Points
Bank: 2,138.00 Points
Location: France
Hi guys i registered on this forum because i've got a problem that nobody could have corrected :cry:

here is the error :

Exception: invalid arguments
at public static native double com.nolimitscoaster.Tools.switchRampC2(double,double,double,double)
at public void HTH.onNextFrame(float)
at public final void com.nolimitscoaster.Script.run()


pls can you help me ?

BTW i'm frensh sorry for the erros :?

Post September 25th, 2014, 8:15 pm
TTD03 User avatar
True Addicts
True Addicts

Posts: 7307
Points on hand: 738.00 Points
Bank: 111,265.11 Points
No problem!
We have a few people on here that know scripting, and I will bring this to their attention on your behalf to see if they can try to help!

Post September 26th, 2014, 2:56 pm

Posts: 191
Points on hand: 764.00 Points
All i can say at the moment is:

at public static native double com.nolimitscoaster.Tools.switchRampC2(double,double,double,double)


You have used the double.. maybe too much or wrong or both. Without the script it will be hard to find the issue! ;) But i believe you??????ve used the switchRamp function wrong.

Nice greetings.

Post September 26th, 2014, 4:45 pm

Posts: 242
Points on hand: 493.00 Points
Bank: 2,138.00 Points
Location: France
I used only floats:

import com.nolimitscoaster.*;
import nlvm.math3d.*;

public class HTH extends Script
{
  private SceneObject m_sco;
  private SceneObjectElement m_car;
 
  float Time;
 
  private static final float fWaitTime = 30.0f;
  private static final float fMoveUp1 = 5.0f;
  private static final float fMoveUp2 = 20.0f;
  private static final float fMoveDown1 = 5.0f;
  private static final float fMoveDown2 = 20.0f;
  private static final float fStay1 = 20.0f;
  private static final float fStay2 = 5.0f;
  private static final float fUpTime = 3.5f;
  private static final float fDownTime = 2.0f;
  private static final float fTotalTime = fWaitTime + fMoveUp1 + fMoveDown1 + fStay2;
 
  private static final float fCarHeight = 0.0f;
 
 
 
   private Vector3f m_carTrans;
 
  private static SceneObjectElement loadSOE(SceneObject sco, String name)
  {
    SceneObjectElement elem = sco.getElementForName(name);
    if (elem == null)
    {
      System.err.println(name + " not found");
      System.exit(-1);
    }
    return elem;
  }
 
  public bool onInit()
  {
    m_sco = sim.getSceneObjectForEntityId(getParentEntityId());
   
    m_car = loadSOE(m_sco, "CAR");
   
   m_carTrans = new Vector3f();
   
    return true;
  }
 
  public void onNextFrame(float tick)
  {
   Time += sim.getCurSimulationTickSec();
   
   
   if (Time <= fTotalTime)
    {
      if (Time < fMoveUp1)
      {
      m_carTrans.y = fCarHeight + (float)Tools.switchRampC2(fMoveUp1 ,fMoveUp1 ,fUpTime, Time);
      }
      else if (Time < fStay2)
      {
      m_carTrans.y = 5;
      }
      else if (Time < fMoveDown1)
      {
      m_carTrans.y = fCarHeight - (float)Tools.switchRampC2(fMoveDown1 ,fMoveDown1 ,fDownTime, Time);
      }
      else
      {
      m_carTrans.y = 0;
      
      Time = 0;
      }
      
   }
   
   m_car.setTranslation(m_carTrans);
   
   }
}


i don't know why it say this :cry:
pls help me

Post September 27th, 2014, 3:20 am

Posts: 191
Points on hand: 764.00 Points
Okay,.. now it makes more sense.
As i thought, you??????ve defined your switchramp function the wrong way. There are only "times" no acceleration and no heights... the switchramp function makes movings "fluid" .. "start >> acceleration to >> max speed >> decceleration to >> stop" .. i hope that makes more sense now ;)

If you look at the following line:
_catTrans.y = c_startHeight + (float)Tools.switchRampC2(c_moveUpTime, c_maxHeight, c_moveAccelerationTime, _sumTime);


...you can see the "move up time", followed by a defined "max height", an "acceleration time" and the "summary time".

Now look at your line:
m_carTrans.y = fCarHeight + (float)Tools.switchRampC2(fMoveUp1 ,fMoveUp1 ,fUpTime, Time);


..there are only doubled time variables.

I highly recommand to play with the existing scripts, which are working already and from there with small steps further ;)

import com.nolimitscoaster.*;
import nlvm.math3d.*;

public class HTH extends Script
{
  private SceneObject m_sco;
  private SceneObjectElement _car;
 
 
  private Vector3f _carTrans;
 
  private float _sumTime;
 
  private static final float c_enterTime = 50.0f;
  private static final float c_moveUpTime = 50.0f;
  private static final float c_moveDownTime = 50.0f;
  private static final float c_upTime = 10.0f;
  private static final float c_moveAccelerationTime = 10.0f;
  private static final float c_rotAccelerationTime = 10.0f;
 
  private static final float c_startHeight = 0.0f;
  private static final float c_maxHeight = 64.0f;

 
private static SceneObjectElement loadSOE(SceneObject sco, String name)
  {
    SceneObjectElement elem = sco.getElementForName(name);
    if (elem == null)
    {
      System.err.println(name + " not found");
      System.exit(-1);
    }
    return elem;
  }
 

public bool onInit()
  {
    m_sco = sim.getSceneObjectForEntityId(getParentEntityId());
    _car = loadSOE(m_sco, "CAR");
   
    _carTrans = new Vector3f();
   
    return true;
  }
 
 
public void onNextFrame(float tick)
  {
    _sumTime += tick;

   
// Ride animation:
   
   
    // Moving up
    if (_sumTime < c_moveUpTime)
    {
    _carTrans.y = c_startHeight + (float)Tools.switchRampC2(c_moveUpTime, c_maxHeight, c_moveAccelerationTime, _sumTime);
    }
   
    // Staying up   
    else if (_sumTime < (c_moveUpTime + c_upTime))
    {
    _carTrans.y = c_startHeight + c_maxHeight;
    }
   
    // Moving down
    else if (_sumTime < (c_moveUpTime + c_upTime + c_moveDownTime))
    {
      _carTrans.y = c_startHeight + c_maxHeight - (float)Tools.switchRampC2(c_moveDownTime, c_maxHeight, c_moveAccelerationTime, _sumTime - (c_moveUpTime + c_upTime));
    }
   
    // Waiting to enter
   
    else
    { 
     _carTrans.y = c_startHeight;
     
     if (_sumTime > (c_moveUpTime + c_upTime + c_moveDownTime + c_enterTime))
      {
        _sumTime = 0;
      }
    }
   
   
_car.setTranslation(_carTrans);

   

  }
}


I also don??????t know what you??????re planning, maybe a script with "steps" will do the trick better for your object.. but it??????s also a bit harder to start with.

I hope that helped to get you started ;)

Nice greetings.

Post September 27th, 2014, 4:50 am

Posts: 242
Points on hand: 493.00 Points
Bank: 2,138.00 Points
Location: France
oh yeah i've used 2 times the same variable thanks men ;)


Return to NoLimits Coaster 2 Scripting