UK theme parks from another point of view!

 
User avatar
apx00
TT Member
TT Member
Topic Author
Posts: 7
Joined: May 2019

NoLimits2: StaticSound only working in one place.

Thu Jun 20, 2019 6:05 pm

Don't think this is a quick question so I've made its own thread.

I'm trying to get some area music to play for a NoLimits2 recreation. To do this I am using roughly 15 speakers which should all play the same music, however the music will only play through one speaker when the simulation is run. My code for each speaker is below, each speaker runs this script and should each play the music.

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

public class StaticThemeMusic extends Script {
  private Simulator sim;
 
  //Variable to store the scene object for the speaker
  private SceneObject sco;
 
  //Paramaters
  public String type;
  public ResourcePath audioFilePath;
 
  //Sound and location
  public StaticSound soundHandle;
  public Vector3f pos;
 
  //Sound params
  public double gain = 0.5;
  public double rolloff = 0.8;
  public double refDistance = 10;
 
  public bool onInit(){
    sim = NoLimits.getSimulator();
    
    int pid = getParentEntityId();
    
    sco = sim.getSceneObjectForEntityId(pid);
    
    //Get parameters.
    type = sco.getStringParameter("type");
    audioFilePath = sco.getResourcePathParameter("audio");
    
    //Get position of object and add static sound...
    pos = sco.getTranslation();
    
    //Set sound parameters.
    if (type.equals("TYP_TRACK_LIFT")){
      gain = 0.75;
      rolloff = 10;
      refDistance = 2;
    }
    
    else if (type.equals("TYP_MUTE")){
      gain = 0;
    }
    
    //Add sound.
   
    System.out.println("gain");
    System.out.println(gain);
    System.out.println("");
    
    soundHandle = StaticSound.loadFromResource(audioFilePath, StaticSound.FLAG_SHARED);
    soundHandle.setGain((float) gain);
    soundHandle.setPosition(pos);
    soundHandle.playLoop();
    return false;
  }
}


I have tried naming the speakers all the same, and changing them to different names. I have tried removing the parameters and hard-coding the path to the audio file and I have tried the StaticSound with and without all the flags. Could anyone offerf any advice as to what the problem might be?

Thanks in advance!
 
User avatar
apx00
TT Member
TT Member
Topic Author
Posts: 7
Joined: May 2019

Re: NoLimits2: StaticSound only working in one place.

Sun Jun 23, 2019 12:23 pm

Fixed it, turns out if you have the 'onInit()' function written like this...

public bool onInit(){
  //...
  return false
}


It returns some sort of error because it is returning false, so it will only activate one speaker since the rest will not run because the first instance has returned false.

To fix it I made this function always return true, so my code now looks like this...
import com.nolimitscoaster.*;

public class StaticThemeMusic extends Script implements FrameListener {
  private Simulator sim;
 
  //Variable to store the scene object for the speaker
  private SceneObject sco;
 
  //Paramaters
  public String type;
  public ResourcePath audioFilePath;
 
  //Sound and location
  public StaticSound soundHandle;
  public Vector3f pos;
 
  //Sound params
  public double gain = 0.5;
  public double rolloff = 0.8;
  public double refDistance = 10;
 
  public bool onInit(){
    
    sim = NoLimits.getSimulator();
    
    int pid = getParentEntityId();
    
    sco = sim.getSceneObjectForEntityId(pid);
    
    //Get parameters.
    type = sco.getStringParameter("type");
    audioFilePath = sco.getResourcePathParameter("audio");
    
    //Get position of object and add static sound...
    pos = sco.getTranslation();
    
    //Set sound parameters.
    if (type.equals("TYP_TRACK_LIFT")){
      gain = 0.75;
      rolloff = 10;
      refDistance = 2;
    }
    
    else if (type.equals("TYP_MUTE")){
      gain = 0;
    }
    
    //Add sound.
    //TODO: Find out why its loading all these sounds on the top two speakers.
    System.out.println("gain");
    System.out.println(gain);
    System.out.println("");
    
    soundHandle = StaticSound.loadFromResource(audioFilePath, StaticSound.FLAG_SHARED);
    soundHandle.setGain((float) gain);
    //soundHandle.setDistanceParameters((float) refDistance, (float) rolloff);
    //soundHandle.setEnvironmentMode(StaticSound.E_ENVMODE_LOCAL);
    //soundHandle.setDopplerMode(false);
    //soundHandle.setAmbientMode(false);
    soundHandle.setPosition(pos);
    soundHandle.playLoop();
    
    //CHANGE: THIS NOW RETURNS TRUE INSTEAD OF FALSE
    return true;
  }
}


The extra sound settings (the ones commented out) will be added later but don't need to be.

Hopefully this helps someone, enjoy!

Who is online

Users browsing this forum: No registered users and 6 guests