The Official Scripting Ask Thread
The 3creativeD effect set should exactly do the job:
Someone still have the script generator? (for custom blockscript)
Check this thread, the script generator is in there
Does anyone know how to script headlights onto a custom train or a stock train? (I’ve been using TCM’s Intamin LSM Set and have not been able to get a light to work.)
I'm having troubles with separate scripts and using resource files in NL2.
My folder structure is like this:

- Models has all Blender files, separated in different folders for the kind of model (station, misc, launch, etc.).
- Music has all .ogg files used in NL2. These are loaded with StaticSound.
- Objects is all exported Blender models and their .nl2sco, .nl2mat and texture files.
- Pictures is used for reference material.
- Scripts has all scripts and this folder is divided in subfolders as well.
Because this is a large project, I decided on splitting my script files. This way I'll also work more in the OOP style of programming which I love.

Master.nlvm is the heart of my coaster. This file is attached to my coaster and generates instances of all other classes. The blocks folder obviously has the block controller script, pushcar folder has the script for my pushcar etc. Not too difficult at all.
Now to the problem: I attached the music files (for the onboard audio and other sounds) as resources to my Master.nlvm script file in the coaster, as shown below:

onboardxy where x is the train ID (starting at 0) and y is the soundtrack as each train has 3 soundtracks: idle sound at the launch track (0), dispatch sound from the station (1) and launch+track (2), each file gets triggered when necessary and decided in the block controller. One other soundtrack is stationsafetyspiel which (as the name suggests) is the safety spiel that gets played in the station.
I use the resources to use my sound files. Nowhere do I use absolute paths on my computer. However, it does seem like it when I create a package file and send it to a friend to test it. As you can see in the error below, it's an absolute path which is correct on my PC, but obviously not on others.

This is the current script which loads the safety spiel. The error was first on line 22 (which is now commented out). I thought because the audio file was attached to the master.nlvm script, I had to get the reference through the Master class and pass it back, but that didn't work either.

At this point, I've tried several things now but I have no idea where it goes wrong. Is this a bug with NL2 maybe? Does anyone have a solution for my problem?
If anyone needs more information on something I didn't cover, let me know. I think I covered the important parts.
I'm not an expert but I think in line 19 what you have right now is basically "stationSafetySpiel = stationSafetySpiel" so it's still referring to null.
If I got it right you want to get the stationSafetySpiel from the master object so it should be "return master.stationSafetySpiel" instead of "return this.stationSafetySpiel" in line 29.
Edit: I overlooked 'master.' in line 19 and misunderstood your actual problem. Sorry.
No, that shouldn't be the case. I declare a variable 'stationSafetySpiel' of type StaticSound on line 11. At line 19, I give this a value (and the value is what I return from the master.getStationSafetySpiel() method). The method getStationSafetySpiel() on line 28 returns the value of the variable of line 11.

This is the method in the master class. So:
- I declare a private variable stationSafetySpiel on line 11.
- On line 19 I give this variable a value. The value is equal to whatever I get back from master.getStationSafetySpiel().
- In the master file, I execute the method (line 152 of the image above), which returns a StaticSound.
- The variable on line 19 gets that value that gets returned.
The error seems to be here

The file safetyspiel.ogg does not exist.
Check if the file is still present and you didn't rename it, otherwise remove this resource from the script and add it again. Don't forget to reload.
When a script controls some property of an nl2sco (In my case: Entity color), does the script have to be in the same folder as the model? I'm trying to use bestdani's effect set for that tunnel problem with my models, but the model, just like the materials and textures, aren't in the same folder as the script the effect set needs.
^ No but the nl2sco file has to be in a parent folder of the script file. It's also important to navigate to the script using the class path did then. If you can it would be the best if you can simply move the object in the existing structure.
^^^ My first impression is that this is kind of a bug. But did you tried to use small test scripts in which case the resource works in a package already to confirm that? I had these kind of issues when I used relative backward paths for resources (like ../path) so maybe the combination of using scrips as a package in combination with the resource somehow acts like an implicit relative path which gets converted to a absolute one by the package manager.
Yedrimas posted on December 31st, 2017
The error seems to be here
The file safetyspiel.ogg does not exist.
Check if the file is still present and you didn't rename it, otherwise remove this resource from the script and add it again. Don't forget to reload.
That is the thing my post is about. It's in the resources and I try to access it, but it's using an absolute path (C:\Users....) which I never specified. I only used the StaticSound.loadFromResourceId() method to get the audio file from the resources.
bestdani posted on January 1st, 2018
^^^ My first impression is that this is kind of a bug. But did you tried to use small test scripts in which case the resource works in a package already to confirm that? I had these kind of issues when I used relative backward paths for resources (like ../path) so maybe the combination of using scrips as a package in combination with the resource somehow acts like an implicit relative path which gets converted to a absolute one by the package manager.
I was thinking it possibly could be an NL2 bug as I can't really think of what is wrong. I even tried to access the specific resource in the Master class (which is attached to the coaster), but that didn't solve it.
What do you mean with the test script?
Does anyone here have a script to make a coaster like Firechaser Express at Dollywood?
That would be the Script Generator found here:
The download link can also be found here in NLC in a different thread:
thimok posted on January 1st, 2018
That is the thing my post is about. It's in the resources and I try to access it, but it's using an absolute path (C:\Users....) which I never specified. I only used the StaticSound.loadFromResourceId() method to get the audio file from the resources.
I was thinking it possibly could be an NL2 bug as I can't really think of what is wrong. I even tried to access the specific resource in the Master class (which is attached to the coaster), but that didn't solve it.
What do you mean with the test script?
Does anyone know a solution to my problem? I'd like to continue work on my ride but it's the best if this is fixed first. Maybe a lot of work is required to fix it and if I continue working on the ride, I might have to change even more things.
Except for changing the directory / package structure so that the relative path works correctly in your case or reporting the bug if you are sure that this is indeed the case and waiting for a possible fix, there's nothing more you could do I guess.
Alright, thank you for your response.
Unfortunately(?) I just tried several cases for loading a sound file in different circumstances and all were successful on my machine (I created the package and run it after renaming the original folder, so it definitely should get loaded from the package and there's no way that it can access the original directory using an absolute path). I guess the problem must be founded somewhere else and not be caused by a NL2 / package manager bug.
Directory structure:
H:.
│ loader.nl2sco
│ package bug.nl2park
│
├───scripts
│ │ Master.nlvm
│ │
│ └───music
│ MusicList.nlvm
│
└───sound
sound.wav
Script Setup:

scripts.Master:
package scripts;
import com.nolimitscoaster.*;
import scripts.music.MusicList;
public class Master extends Script{
public bool onInit(){
MusicList musicList = new MusicList(this);
return false;
}
public StaticSound getSound(){
return StaticSound.loadFromResourceId("sound", 0);
}
}
scripts.music.MusicList:
package scripts.music;
import com.nolimitscoaster.*;
import scripts.Master;
public class MusicList extends Script{
private Master master;
private StaticSound sound;
public MusicList(Master master){
this.master = master;
sound = master.getSound();
System.out.println("MusicList: " + (sound != null));
}
}
Running the package (after renaming the original directory):

Thank you for your detailed response. I sent you a message earlier today.
It's really weird. I feel like I'm doing the same thing, but for me it does not work. It's probably something silly...
This has probably been asked before but what is the best way to get into scripting? and what language is NL2's syntax closest to?
This was taken from the Nolimits 2 Manual available inside of Nolimits itself.

If you'd like more information on the language, theres a ton of information such as sample scripts, class overviews, and tips for scripting in the Nolimits 2 manual.
Thanks, how I managed to miss that is beyond me....
I have started a scripting series for absolute beginners on a new NL2 YouTube channel. It starts with creating block scripts using the blockhelper package that is delivered with NL2 to give a simple but practically usable start to get into the programming syntax and also with certain parts of the NL2 API.
For now to get me into doing these kinds of videos it is my mother tongue (German) but with enough support and shown interest we would also provide rerecorded versions with spoken English language. The automatically translated subtitles might also work for now, of course everybody can help and reach in manually added subtitles using the function for that on YouTube.
Getting one familiar with an object oriented programming language helps much in the first place, it does not have to be Java. I actually never programmed something in Java for now, but it is indeed the closest popular language to the NLVM (NL2 scripting) language. If your goal is only doing something in the NLVM, I guess some free Java, C# or C++, maybe also PHP or JavaScript tutorial is enough to get you into NL2 Scripting from examples and reading the Scripting API reference.
If you are interested in getting into the principles of high level programming languages in general then Python is very simple to start with and you can do powerful stuff rather quickly with that. But the language syntax and some features are rather different than from the other ones including the NL2 scripting language.
I have a short question. I would like some clarity about TCM's CCC2 (Custom car creator 2) I do not quite understand how it works, is there someone who wants to make a video or a thread on this subject?


All questions, concerns and hopefully answers concerning scripts on NoLimits 2 belong here.
Remember, when posting a script, please use 1 ` (back tick) for inline code like this:
public static Coaster attachedCoaster;For block level code use 3 back ticks: ``` Also after specifying your first 3 back ticks, you can set the language you want the syntax highlighting to apply to, e.g. ```java for NoLimits scripts:
public bool onInit () { return true; }