I am using geforcefan's sound.nlvm and soundTrigger.nlvm files to do this.
The first sound and trigger work perfectly, but when I setup the second sound, and create sounddown.nlvm and soundTriggerDown.nlvm, it plays the first sound file instead of the second.
Not sure what I've done wrong as everything seems correct and NL2 is showing no errors.
Audio 1:
sound.nlvm
Code: Select all
import com.nolimitscoaster.*;
public class sound extends Script {
private static final String sCoastername = "Kingda Ka";
Coaster cMyCoaster;
public bool onInit() {
cMyCoaster = sim.getCoaster(sCoastername);
TrackTrigger tTrainLeaveStationTrigger = cMyCoaster.getTrackTrigger("PlayMusic");
if(tTrainLeaveStationTrigger == null) {
System.err.println("Trigger not found");
return false;
}
TrackTriggerListener tTriggerListener = new soundTrigger();
tTrainLeaveStationTrigger.addTrackTriggerListener(tTriggerListener);
return true;
}
}
soundTrigger.nlvm
Code: Select all
import com.nolimitscoaster.*;
import nlvm.math3d.*;
public class soundTrigger extends Script implements TrackTriggerListener {
private static final String sSoundFile = "KingdaKaRoarUp.ogg";
StaticSound sSound;
public soundTrigger() {
sSound = StaticSound.loadFromFile(sSoundFile, StaticSound.E_ENVMODE_LOCAL);
if(sSound == null) {
System.err.println("Sound file not found");
return;
}
sSound.setPosition(new Vector3f(0.0807f, 20.476f, -285.73f));
sSound.setGain(100.0f);
}
public void onTrainEntering(TrackTrigger trigger, Train train) {
sSound.play();
}
public void onTrainLeaving(TrackTrigger trigger, Train train) {
}
}
Audio 2:
sounddown.nlvm
Code: Select all
import com.nolimitscoaster.*;
public class sounddown extends Script {
private static final String sCoastername = "Kingda Ka";
Coaster cMyCoaster;
public bool onInit() {
cMyCoaster = sim.getCoaster(sCoastername);
TrackTrigger tTrainLeaveStationTrigger = cMyCoaster.getTrackTrigger("PlayDown");
if(tTrainLeaveStationTrigger == null) {
System.err.println("Trigger not found");
return false;
}
TrackTriggerListener tTriggerListener = new soundTrigger();
tTrainLeaveStationTrigger.addTrackTriggerListener(tTriggerListener);
return true;
}
}
soundTriggerDown.nlvm
Code: Select all
import com.nolimitscoaster.*;
import nlvm.math3d.*;
public class soundTriggerDown extends Script implements TrackTriggerListener {
private static final String sSoundFile = "KingdaKaRoarDown.ogg";
StaticSound sSound;
public soundTriggerDown() {
sSound = StaticSound.loadFromFile(sSoundFile, StaticSound.E_ENVMODE_LOCAL);
if(sSound == null) {
System.err.println("Sound file not found");
return;
}
sSound.setPosition(new Vector3f(-27.72f, 19.767f, -288.752f));
sSound.setGain(100.0f);
}
public void onTrainEntering(TrackTrigger trigger, Train train) {
sSound.play();
}
public void onTrainLeaving(TrackTrigger trigger, Train train) {
}
}
Thanks for your help!