Skip to content

All Comments

13181 to 13200 of 19729

Filter comments

The Official Scripting Ask Thread
Scripting

thank you so much for this there is 2 warnings but i think i know what they are, and it finally works when i left click the light turns on which is almost what i want

import nlvm.math3d.*;
import nlvm.lang.Math;

doesn't need to be there for now

View comment
The Official Scripting Ask Thread
Scripting

You're missing the closing } after

light.setEnabled(Button.isPressed(Button.ACTION) && sim.getCurSunElevation() < 0.05f);
public void onNextFrame(float tick)
{
    light.setEnabled(Button.isPressed(Button.ACTION) && sim.getCurSunElevation() < 0.05f);
}

Also :
turn is never set (the variable does not exist before assignation). Possible fix : rename turn to light

a light is not a scene object, you may want to replace obj.getElementForName with obj.getLightForName
light should also be replaced with a SceneObjectLight instead of a SceneObjectElement.

light is never set and does not exist before assignation. Light =/= light. Possible fix : rename Light to light in : private SceneObjectElement Light; (also missing a semicolon)

Vector3f dis is never used : No need to fix, but to remove a warning, delete this line. Same for DEG.

onInit() is missing a return statement.

Wrong name used in getElement(/Light)ForName

This should look like this (Not tested):

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

public class LightEnabled extends Script
{	
	// Removed unused DEG & dis
	
	protected String SCRIPT_NAME = "Light";
	protected String LIGHT_NAME = "Light";
	private SceneObject obj;
	
	// Changed type, name, missing ';'
	private SceneObjectLight light;
	
	public bool onInit() {
		obj = sim.getSceneObjectForEntityId(getParentEntityId());
		
		if(obj == null) {
			System.err.println(SCRIPT_NAME + ": Object not found");
			return false;
		}
		
		// Renamed from turn to light, changed to getLightForName, corrected parameter
		light = obj.getLightForName(LIGHT_NAME);
	
		if(light == null) {
			System.err.println(SCRIPT_NAME + ": Element " + LIGHT_NAME + " not found");
			return false;
		}
		
		// Added missing return statement
		return true;
	}
	
	// Added missing }
	public void onNextFrame(float tick) {
		light.setEnabled(Button.isPressed(Button.ACTION) && sim.getCurSunElevation() < 0.05f);
	}
	
}

TLDR: Missing semicolon line 12

View comment
The Official Scripting Ask Thread
Scripting

I keep getting an error on " public bool onInit(){ " it says that there is an error but i cant see any issues with this line, i know that the script is probably all wrong but im just confused about that one error

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

public class LightEnabled extends Script
{	
	protected static final float DEG = (float)Math.PI/180.f;
	protected String SCRIPT_NAME = "Light";
	protected String LIGHT_NAME = "Light";
   	private Vector3f dis = new Vector3f();
	private SceneObject obj;
	private SceneObjectElement Light
	
	
	public bool onInit(){
		obj = sim.getSceneObjectForEntityId(getParentEntityId());
		if(obj==null){
			System.err.println(SCRIPT_NAME + ": Object not found");
			return false;
		}
		turn = obj.getElementForName(LIGHT_NAME + ": Object not found");
		if(turn==null){
			System.err.println(SCRIPT_NAME + ": Element " + LIGHT_NAME + " not found");
			return false;
		}
	}
	public void onNextFrame(float tick)
	{
    light.setEnabled(Button.isPressed(Button.ACTION) && sim.getCurSunElevation() < 0.05f);
	
	
}
View comment
13181 to 13200 of 19729