Board index Roller Coaster Games NoLimits Coaster 2 NoLimits Coaster 2 Scripting Unknown method: setVisible()

Unknown method: setVisible()

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

Post February 9th, 2018, 9:40 am

Posts: 4
Points on hand: 74.00 Points
Hi all, my problem is this. I want to make it visible or invisible with keyboard key. For example,when I press "1" my 3d object should disappear. Thanks.
import com.nolimitscoaster.*;
import nlvm.math3d.*;
import nlvm.lang.*;

public class SimpleScript extends Script{

private SceneObject sco;

public bool onInit(Simulator sim)
   {
           sco = sim.getSceneObject("Teapot_01");
           sco.setVisible(false); //Unknown method: setVisible()

        return true;
        }
public void onNextFrame(float tick)
    {

     }

}

Post February 10th, 2018, 3:03 am
herman116 User avatar
Premium Member
Premium Member

Posts: 636
Points on hand: 7,471.00 Points
Location: The Netherlands
I just took a quick look in the help file and it looks like you can only check if a key has been pushed if it's been mapped to one of the following:

ACTION: This is the Left Mouse Button by default
CHANGE_VIEW_MODE: This is the Q key by default
MOVE_BACKWARD: This is the S key by default
MOVE_DOWN: This is the X key by default
MOVE_FORWARD: This is the W key by default
MOVE_LEFT: This is the A key by default
MOVE_RIGHT: This is the D key by default
MOVE_UP: This is the Space key by default
NEXT_CAR: This is the C key by default
NEXT_SEAT: This is the V key by default
NEXT_TRAIN: This is the T key by default

It is possible to map the action button to the left mouse button AND to 1 on your keyboard. But unfortunately it's not possible to retrieve the state of all the keys from your keyboard.

Your code would than probably look like this:

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

public class SimpleScript extends Script
{

   private SceneObject sco;
   private bool visible = true;

   public bool onInit(Simulator sim)
   {
      sco = sim.getSceneObject("Teapot_01");

      return true;
   }

   public void onNextFrame(float tick)
   {
      if (isPressed(ACTION))
      {
         visible = !visible;

         sco.setVisible(visible); //Unknown method: setVisible()
      }
   }

}


I have not tested this code so it might not work.

What is happening in the code is that on each frame (onNextFrame), it checks if the action key has been pressed. If the action key has been pressed, it toggles the visible value. Finally it sets the scenery object to the visibility value that just has been toggled. So if the object was visible, it will now be invisible and vice versa.

Post February 11th, 2018, 7:37 am

Posts: 4
Points on hand: 74.00 Points
Thanks @herman116
I think setVisible is not working with getSceneObject because the 3d object is not a single piece. So we want to select all child objects with getElementAt.
I solved this problem like this

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

public class SimpleScript extends com.nolimitscoaster.Script
{
   private SceneObject Sco;

public bool onInit(Simulator sim)
{
   Sco = sim.getSceneObject("Teapot");

return false;
}

public void onNextFrame(float tick)
{
   if(Button.isPressed(Button.ACTION)){
        Sco = sim.getSceneObject("Teapot");
        Sco.getElementAt(0).setVisible(false);
        Sco.getElementAt(1).setVisible(false);
        Sco.getElementAt(2).setVisible(false);
        Sco.getElementAt(3).setVisible(false);
        Sco.getElementAt(4).setVisible(false);
        Sco.getElementAt(5).setVisible(false);
   }
}


}


Return to NoLimits Coaster 2 Scripting

cron