Oolite Bulletins

For information and discussion about Oolite.
It is currently Tue Mar 26, 2019 6:38 am

All times are UTC




Post new topic  Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sat Aug 23, 2014 9:18 pm 
Offline
Competent
Competent
User avatar

Joined: Sat Aug 16, 2014 12:06 pm
Posts: 53
I am trying to modify a script to change the volume of an engine sound according to the current engine thrust level (w and s keys). I am reading the player.ship.thrust property but it always seems to return the ship's maximum thrust (=32 for the Cobra III).

Is there a property that will return the actual engine level, in this case somewhere between 0 and 32 presumably?

The sound plays OK, I just cannot change the volume.

Here are my code snippets:
Code:
	this.sprTimer = new Timer(this,this.sprTick,0,0.25); this.sprTimer.stop();
	this.sprEngineSound = new SoundSource;
	sprEngineSound.sound = "sprEngine.ogg";
	sprEngineSound.loop = true;


this.sprTick = function()
{
	//normalise to produce volume 0 - 1
	sprEngineSound.volume = player.ship.thrust/player.ship.maxThrust;

	//debug output
	log(this.name,"Current Level: "+player.ship.thrust); //always gives 32

	return;
};

this.shipWillLaunchFromStation = function(station)
{
	 // ... other code

	this.sprTimer.start();
	sprEngineSound.play();

};


Top
   
PostPosted: Sat Aug 23, 2014 9:23 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4018
The thrust property measures the ability of the ship to accelerate. While it could in theory change, it doesn't tend to. (I'm not sure there are any circumstances in which the JS value changes for the player ship)

You probably want player.ship.speed and player.ship.maxSpeed instead (noting that speed will exceed maxSpeed under injectors or torus drive, but the SoundSource will treat any volume > 1 as equal to 1 anyway, so you probably don't need to worry about that here)

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
PostPosted: Sat Aug 23, 2014 9:38 pm 
Offline
Competent
Competent
User avatar

Joined: Sat Aug 16, 2014 12:06 pm
Posts: 53
Excellent! Thank you, that works nicely. I now have a custom engine roar whose volume is proportional to my speed.

btw I have done this by hacking the main script in the BGS expansion along with stealing the engine sound from the XR2 in Orbiter.

ed. top tip for other newbie script hackers: Hold the Shift key down when starting Oolite! It seems that scripts are cached and changes will not register even after a reboot.


Top
   
PostPosted: Sun Aug 24, 2014 12:24 am 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Sun Jan 23, 2011 9:27 pm
Posts: 471
Location: Belgium, Monarchy, Feudal, Overtaxed system
Welcome to the boards streb2001

Nice job on the script, I was thinking about missing engine sound for the player only yesterday.
Quote:
Excellent! Thank you, that works nicely. I now have a custom engine roar whose volume is proportional to my speed.

btw I have done this by hacking the main script in the BGS expansion along with stealing the engine sound from the XR2 in Orbiter.

ed. top tip for other newbie script hackers: Hold the Shift key down when starting Oolite! It seems that scripts are cached and changes will not register even after a reboot.

Yes, or you can always add the line
Code:
"always-flush-cache" = YES;
to the .GNUstepDefaults file like so:
Code:
{
    NSGlobalDomain = {
    };
    oolite = {
	"Commander Gordts-humbletrash" = "-6792";
	"Jameson-humbletrash" = "-29624";
	JoystickAxes = {
	    0 = {
		isAxis = 1;
		stickAxBt = 0;
		stickNum = 0;
	    };
	    1 = {
		isAxis = 1;
		stickAxBt = 1;
		stickNum = 0;
	    };
	};
	JoystickButs = {
	    0 = {
		isAxis = 0;
		stickAxBt = 3;
		stickNum = 0;
	    };
	    1 = {
		isAxis = 0;
		stickAxBt = 1;
		stickNum = 0;
	    };
	    12 = {
		isAxis = 0;
		stickAxBt = 11;
		stickNum = 0;
	    };
	    13 = {
		isAxis = 0;
		stickAxBt = 7;
		stickNum = 0;
	    };
	    14 = {
		isAxis = 0;
		stickAxBt = 10;
		stickNum = 0;
	    };
	    15 = {
		isAxis = 0;
		stickAxBt = 67;
		stickNum = 0;
	    };
	    16 = {
		isAxis = 0;
		stickAxBt = 65;
		stickNum = 0;
	    };
	    17 = {
		isAxis = 0;
		stickAxBt = 6;
		stickNum = 0;
	    };
	    19 = {
		isAxis = 0;
		stickAxBt = 5;
		stickNum = 0;
	    };
	    21 = {
		isAxis = 0;
		stickAxBt = 4;
		stickNum = 0;
	    };
	    23 = {
		isAxis = 0;
		stickAxBt = 2;
		stickNum = 0;
	    };
	    32 = {
		isAxis = 0;
		stickAxBt = 64;
		stickNum = 0;
	    };
	    33 = {
		isAxis = 0;
		stickAxBt = 66;
		stickNum = 0;
	    };
	    8 = {
		isAxis = 0;
		stickAxBt = 9;
		stickNum = 0;
	    };
	    9 = {
		isAxis = 0;
		stickAxBt = 8;
		stickNum = 0;
	    };
	};
	PitchAxisProfile = {
	    Deadzone = 0.05;
	    Parameter = 1;
	    Power = 1;
	    Type = Standard;
	};
	RollAxisProfile = {
	    Deadzone = 0.05;
	    Parameter = 1;
	    Power = 1;
	    Type = Standard;
	};
	YawAxisProfile = {
	    Deadzone = 0.05;
	    Parameter = 1;
	    Power = 1;
	    Type = Standard;
	};
	"always-flush-cache" = YES;
	"debug-settings-override" = {
	};
	fullscreen = YES;
	"music mode" = off;
	"save-directory" = "C:\\games/Oolite-1.81-blue ownbuild/oolite.app/oolite-saves";
	"show-ship-model-in-status-screen" = YES;
    };
}
Open file with notepad ++ and not notepad since it leaves garbage (carriage returns)

Then you won't have to worry about the shift key again ever.

_________________
Alpha Backer of Elite Dangerous
With 250 GBP :D


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Limited