Page 1 of 1

Speed

Posted: Fri Aug 07, 2009 4:36 pm
by Rustybolts
How do you find out how fast a player ship is traveling using java script.
Eg i want some code to run if a certain speed is met.

Posted: Sat Aug 08, 2009 4:20 am
by Kaks
From what it says in the following wiki page

http://wiki.alioth.net/index.php/Oolite ... ence:_Ship

I'd say you probably want

Code: Select all

(player.ship.speed/player.ship.maxSpeed)
the raw player.ship.speed might not be too helpful: since some slower ships might never reach the speed you're waiting for, you might want a script to react once the ship is at full throttle (1) or at half its maximum speed (0.5), or whatever other proportion of the maximum speed...

Hope this helps

Posted: Sat Aug 08, 2009 9:02 am
by Rustybolts
Thanks but doesn't quite work here's my test code

Code: Select all

if  (player.ship.maxSpeed>"1.0"){
		player.commsMessage("Works");
	}
which i wanted to start if witchdrive injectors where used. the jumpdrive should also start it but didn't. I mainly want it to detect witchdrive injector use though.

Posted: Sat Aug 08, 2009 9:04 am
by another_commander
Rustybolts wrote:
Thanks but doesn't quite work here's my test code

Code: Select all

if  (player.ship.maxSpeed>"1.0"){
		player.commsMessage("Works");
	}
which i wanted to start if witchdrive injectors where used. the jumpdrive should also start it but didn't. I mainly want it to detect witchdrive injector use though.
This should be

Code: Select all

if (player.ship.maxSpeed > 1.0)
{
    player.commsMessage("Works");
}
The value you are comparing against should be a number, not a string.

Posted: Sat Aug 08, 2009 9:13 am
by Rustybolts
Unfortunately despite changing my mistake this still did not work. Maybe a value of 1 is a s high as maxspeed goes

Posted: Sat Aug 08, 2009 9:45 am
by Eric Walch
Rustybolts wrote:
Thanks but doesn't quite work here's my test code

Code: Select all

if  (player.ship.maxSpeed>"1.0"){
		player.commsMessage("Works");
	}
which i wanted to start if witchdrive injectors where used. the jumpdrive should also start it but didn't. I mainly want it to detect witchdrive injector use though.
That would be :

Code: Select all

if  (player.ship.speed>player.ship.maxSpeed>){
		player.commsMessage("FuelInjection (Or jumpspeed) in use");
	}
I think jump speed is about 32 times max speed. I am not sure but certainly more than 20 times, so:

Code: Select all

if  (player.ship.speed>20*player.ship.maxSpeed>){
		player.commsMessage("Jumpspeed  in use");
	}
Code really does work for the player. Player speed higher than maxSpeed is one of the conditions for the addition of deepSpacePirates.

Posted: Sat Aug 08, 2009 10:42 am
by Kaks
Or even better:

Code: Select all

if  (player.ship.speed>20*player.ship.maxSpeed){
      player.commsMessage("Jumpspeed  in use");
   } else if (player.ship.speed>player.ship.maxSpeed){
      player.commsMessage("Fuel Injection in use");
   }
(I removed the extra '>' at the end of the conditions, as well as making it possible to check for jumpspeed & fuel injection separately)

the value of 1 I gave as an example was the result of dividing speed by maxSpeed, as in

Code: Select all

if((player.ship.speed/player.ship.maxSpeed) > 1) { ... }
If I were in you I'd test all various conditions and oolite properties inside the debug console. Just typing player.ship.speed in there will show your current speed etc... It's a great time saver!

Posted: Sat Aug 08, 2009 11:38 am
by Rustybolts
I have tried all possibilities suggested and receive no comms message i have checked deepspace pirates and you have used it as follows

Code: Select all

if(!system.isInterstellarSpace && !player.ship.docked && player.ship.speed > 20*player.ship.maxSpeed*Math.random() && !player.alertHostiles) 
Which is no different....
Thanks for all your help though.

Posted: Sat Aug 08, 2009 12:02 pm
by LittleBear
For testing it, you could try player.consoleMessage instead. I've found when playtesting that comms messages are not always displayed (maybe due to a range thing from the ship sending it) and it might be the same type of thing here.

Posted: Sat Aug 08, 2009 12:32 pm
by Rustybolts
Thanks i have changed my code a bit

Code: Select all

this.shipWillExitWitchspace = function(){
player.consoleMessage("witchspace ended");
}
if (player.ship.speed>20*player.ship.maxSpeed){ 
player.consoleMessage("Jumpspeed  in use"); 
} else if (player.ship.speed>player.ship.maxSpeed){ 
player.consoleMessage("Fuel Injection in use"); 
}
To test i performed a witchspace jump the console message told me when it had ended so that worked fine.
Then i tried my injectors recieved no message
Then i tried a jump again no message.

Posted: Sat Aug 08, 2009 3:25 pm
by Eric Walch
Try next code:

Code: Select all

this.tickle = function()
{
  if (player.ship.speed>20*player.ship.maxSpeed)
  { 
    player.consoleMessage("Jumpspeed  in use"); 
  } 
  else if (player.ship.speed>player.ship.maxSpeed)
  { 
     player.consoleMessage("Fuel Injection in use"); 
  }
}
You had nothing in your code that triggered your code. The tickle triggers every 10 seconds, with the same timer as the legacy code.

Although the tickle is nice for testing, don't use it in final work as at this moment all legacy scripts run also and your code will run at the busiest possible time.

Posted: Sat Aug 08, 2009 6:05 pm
by Rustybolts
Ahh thanks for this i didn't fully realise that when using javascript it doesn't run code unless you have called an event.
It works but is maybe too slow for what i am wanting. I need it to detect at the instant it occurs also at the instant no longer in use.
What i was wanting to do was have a heat meter that increased on start of witch injection, when reached highest temperature cut out the injectors until they had cooled down. This is probably not possible then at the moment.