Page 39 of 118

Re: Scripters cove

Posted: Tue Feb 28, 2012 7:25 pm
by mandoman
Ironfist wrote:
mandoman,

Is it as the latest.log says, this script is probably OK but what is it called - it would appear that the script which is calling this - is looking for "solarTankderDies.js" could it actually be called 'solarTankerDies.js'.
Just a thought.

Ironfist
LOL!!!!! You are so correct. My worst enemy in all this in my lousy typing. I'll change that and see if it makes a difference. :lol:

Okti, I'll get right on it. Thanks. :)

Re: Scripters cove

Posted: Tue Feb 28, 2012 7:35 pm
by Okti
Time to sleep over here, so you have plenty time. I will be busy with Work tomorrow but I will try to help you when I have time.

Re: Scripters cove

Posted: Tue Feb 28, 2012 7:48 pm
by mandoman
Okti wrote:
Time to sleep over here, so you have plenty time. I will be busy with Work tomorrow but I will try to help you when I have time.
Okay, thanks. :)

Re: Scripters cove

Posted: Sat Mar 03, 2012 1:34 am
by CommonSenseOTB
Okti, umm, not too sure how to put this delicately, but umm, well, here you go. :P

Image

:lol:

Re: Scripters cove

Posted: Sat Mar 03, 2012 1:38 am
by Fatleaf
Don't do that :shock:
That's my lunch :D

Re: Scripters cove

Posted: Sat Mar 03, 2012 8:58 am
by Smivs
<Smivs chuckles>

Re: Scripters cove

Posted: Sat Mar 10, 2012 7:49 am
by Capt. Murphy
I have a question about ordering when checking multiple conditions in an if() statement.

In if(a || b || !c){return false;} does the JS engine skip the checks for b and !c if a returns true, so that these kind of checks should be arranged to that the first value checked is the one that's most often going to be true for speedier scripts? Or is the whole of (a || b || !c) evaluated before deciding whether to {return false;}, in which case it may be better to do if(a){return false;};if(b){return false;};if(!c){return false;}; especially if there are lots of conditions to be checked and a is more likely to be true than b and in turn !c.

Re: Scripters cove

Posted: Sat Mar 10, 2012 8:33 am
by Capt. Murphy
Kaks wrote:
Sometimes an oxp would like to make an NPC jump to another system. However, the NPC might well be blocked by a nearby mass, since it's not always obvious how far away from the station you can safely jump, here's a way to find the minimum distance from any station in order to hopefully jump successfully at the first attempt. It's a combination of AI.plist and ship script, I'm afraid...

NB: I'm using squared distance because it's faster to calculate than distance.

Code: Select all

this.minimumJumpSquaredDistance = function(other) {
   // internal Oolite constants used: K = 0.1, SCANNER_MAX_RANGE = 25600
   let dist=other.mass * 0.1;
   return (dist > 655360000 ? 655360000 : dist); // 25600 * 25600
}
.........................
Would I be right in thinking that if you want to avoid the player.ship.mass blocking another entity's jump that this would be a valid check for an appropriate distance.....the +50 is a 'buffer'.

dist = Math.sqrt(player.ship.mass * 0.1)+50

Re: Scripters cove

Posted: Sat Mar 10, 2012 9:30 am
by cim
Capt. Murphy wrote:
In if(a || b || !c){return false;} does the JS engine skip the checks for b and !c if a returns true, so that these kind of checks should be arranged to that the first value checked is the one that's most often going to be true for speedier scripts?
This way.

Re: Scripters cove

Posted: Sat Mar 10, 2012 1:13 pm
by SandJ
Capt. Murphy wrote:
In if(a || b || !c){return false;} does the JS engine skip the checks for b and !c if a returns true?
Yes, the JavaScript engine does (which in reality means any given implementation of a JS engine should) use short circuit evaluation in combined conditional checking and will stop checking if it sees that a returns true.
Capt. Murphy wrote:
these kind of checks should be arranged so that the first value checked is the one that's most often going to be true?
Correct.

Re: Scripters cove

Posted: Sat Mar 10, 2012 5:19 pm
by mandoman
Okay, here I go again. The scripts given to me for this oxp seem like they should work, and are NOT raising any warning flags, but, they are also not producing the UFOship, in conjunction with thargoid ships that I hoped for. I tried messing with the script, because it seemed to me that the number of thargoid ships in system should be considered BEFORE UFOships are considered, in order to add the correct number of UFOships to that of thargoid ships. Here is what I did. Haven't tried it yet, and thought I would first ask if this is even a valid script. Thanks.

Code: Select all

// Standard attributes
this.name           = "UFOship.js";
this.author         = "mandoman";
this.copyright      = "This script is hereby placed in the public domain.";
this.version        = "1.0.1";
this.description    = "Script to spawn equal number of UFOships as number of Thargoid ships if player ship with score 512, or higher exits Witchspace."

// will run as player exits witchspace, and after game engine has populated the system
this.shipExitedWitchSpace = function()
{
  var thargoidCounter = system.countShipsWithPrimaryRole("thargoid"); // count how may thargoid ships are in the system.
  if (player.score < 512 || thargoidCounter > 0){return;} // do nothing if player kills is less than 512 or there are already UFOships in the ooniverse.
  var thargoidCounter = system.countShipsWithPrimaryRole("thargoid"); // counts how many thargoids there are
  if (player.score >= 512 ++ thargoidCounter> 0) // if more than 0 then spawn equal number of UFOships.
{
    system.addShips("UFOship", thargoidCounter, player.ship.position, 20000);
}
}

Re: Scripters cove

Posted: Sat Mar 10, 2012 5:24 pm
by Okti

Code: Select all

 if (player.score >= 512 ++ thargoidCounter> 0) // if more than 0 then spawn equal number of UFOships.
Try && instead of ++.

Re: Scripters cove

Posted: Sat Mar 10, 2012 5:33 pm
by cim
mandoman wrote:

Code: Select all

this.shipExitedWitchSpace = function()
{
  var thargoidCounter = system.countShipsWithPrimaryRole("thargoid"); // count how may thargoid ships are in the system.
Judging by the comment on the next line, this should probably be countShipsWithPrimaryRole("UFOship") instead.
mandoman wrote:

Code: Select all

  if (player.score < 512 || thargoidCounter > 0){return;} // do nothing if player kills is less than 512 or there are already UFOships in the ooniverse.
  var thargoidCounter = system.countShipsWithPrimaryRole("thargoid"); // counts how many thargoids there are
  if (player.score >= 512 ++ thargoidCounter> 0) // if more than 0 then spawn equal number of UFOships.
Minor typo: should be && rather than ++
mandoman wrote:

Code: Select all

{
    system.addShips("UFOship", thargoidCounter, player.ship.position, 20000);
}
}
Otherwise that looks okay to me.

Re: Scripters cove

Posted: Sat Mar 10, 2012 5:57 pm
by Commander McLane
The function is called shipExitedWitch[b][color=#FF0000]s[/color][/b]pace.

Small 's'.

Re: Scripters cove

Posted: Sat Mar 10, 2012 6:02 pm
by Okti
+1 on Commander McLanes Post,

Mandoman, I think it will be better to explain what you are trying to achieve in plain English. More comments on the JS File will explain more.