Speed

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Post Reply
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Speed

Post 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.
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post 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
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post 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.
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6683
Joined: Wed Feb 28, 2007 7:54 am

Post 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.
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post by Rustybolts »

Unfortunately despite changing my mistake this still did not work. Maybe a value of 1 is a s high as maxspeed goes
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post 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.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post 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!
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post 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.
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2882
Joined: Tue Apr 04, 2006 7:02 pm
Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.

Post 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.
OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post 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.
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post 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.
User avatar
Rustybolts
---- E L I T E ----
---- E L I T E ----
Posts: 293
Joined: Sun Jun 07, 2009 6:22 pm
Location: UK

Post 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.
STE.+ Firefly/Dragonfly + BlackJacksbullion v.1.23 link below.
http://www.mediafire.com/?sharekey=ca16 ... f6e8ebb871
Image
Post Reply