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.