Page 40 of 118

Re: Scripters cove

Posted: Sat Mar 10, 2012 7:01 pm
by mandoman
cim wrote:
Judging by the comment on the next line, this should probably be countShipsWithPrimaryRole("UFOship") instead. Otherwise that looks okay to me.
Yeah, it was originally like that, but it doesn't make sense to me. My intention isn't that the UFOship be already in the area, but that it responds to a prompt that a certain number of thargoids are present. The UFOship should appear after (countShipsWithPrimaryRole ("thargoid")), if the players kill score is 512, or higher, AND the thargoid count exceeds ??. I had originally planned for that number to be ">2", but that starts getting into Math, which is waaaaay beyond my ken.

Re: Scripters cove

Posted: Sat Mar 10, 2012 7:06 pm
by cim
mandoman wrote:
cim wrote:
Judging by the comment on the next line, this should probably be countShipsWithPrimaryRole("UFOship") instead. Otherwise that looks okay to me.
Yeah, it was originally like that, but it doesn't make sense to me. My intention isn't that the UFOship be already in the area, but that it responds to a prompt that a certain number of thargoids are present. The UFOship should appear after (countShipsWithPrimaryRole ("thargoid")), if the players kill score is 512, or higher, AND the thargoid count exceeds ??. I had originally planned for that number to be ">2", but that starts getting into Math, which is waaaaay beyond my ken.
Right. That's what the comment suggested. Your first check is for "are there any UFOships" and "does the player have too few kills" - and if either of those is true, don't add any more UFOships. So the role check there needs to be for UFOships.

Two lines down you've got a similar check for thargoids, which you use as described for when the player is Dangerous or better, to add UFOships equal to the number of thargoids.

Re: Scripters cove

Posted: Sat Mar 10, 2012 7:16 pm
by mandoman
cim wrote:
Right. That's what the comment suggested. Your first check is for "are there any UFOships" and "does the player have too few kills" - and if either of those is true, don't add any more UFOships. So the role check there needs to be for UFOships.

Two lines down you've got a similar check for thargoids, which you use as described for when the player is Dangerous or better, to add UFOships equal to the number of thargoids.
Okay. I knew it was correct, because Capt Murphy wrote it, but I have GOT to figure out how this scripting coordinates. The wording throws me off. I'll keep plugging at it. No insult intended to Capt. Murphy, but that original script didn't produce. Maybe the AI I wrote is screwing it up, I don't know. :?

Re: Scripters cove

Posted: Sat Mar 10, 2012 8:26 pm
by Commander McLane
mandoman wrote:
No insult intended to Capt. Murphy, but that original script didn't produce. Maybe the AI I wrote is screwing it up, I don't know. :?
Whatever the AI does, the problem with your script is already identified and was clearly shown to you. I have no idea why you choose to ignore it.

I write it again:
Commander McLane wrote:
The function is called shipExitedWitch[b][color=#FF0000]s[/color][/b]pace.

Small 's'.
Is there anything in here that you don't understand? If so, then please ask.

As in every computer language, the JavaScript commands have a fixed syntax. As in every written language, orthography is important. In computer languages it is even more important than in human languages. A human can read a text with typos and still figure out what is meant. For instance, if somebody writes "thier" instead of "their", you still understand the word. The computer, however, is dumb. It does not understand what you want to say, if you get only one letter wrong.

That's why we have a documentation in the Wiki, where the exact syntax of each command is explained. Please use this documentation and stick to the exact syntax.

The documentation tells you that there is a command shipExitedWitchspace. Please click on the link and read what this command means and what it does.

You are using a command in the 10th line of your code example which for your eyes may look the same as the one I have linked to above. For your eyes it may look the same, but it isn't. It has nothing to do with a command. Because the command is spelled "shipExitedWitchspace". But you have typed "shipExitedWitchSpace". Do you notice that this is not the same? Do you notice that there is a small, but important difference? The correct syntax requires you to write "Witchspace" with a small letter "s" in the middle. But you have written "WitchSpace" with an uppercase letter "S" in the middle. Do you see the difference?

Your computer does. For your computer "Witchspace" and "WitchSpace" are two completely different things. Your computer knows "Witchspace" as part of a command, but it has never ever heard of "WitchSpace". As far as your computer is concerned, you could have written "shipExitedRdfbsodjbviuer". It's just the same as "shipExitedWitchSpace". It is not a command your computer knows. Therefore your computer simply does nothing when it reads this command.

Please, learn the correct syntax of the commands you want to use and stick to this syntax. Do not change even one single letter. If an uppercase is required, type an uppercase. If a lowercase is required, type a lowercase. And never make up your own commands. Every command that is allowed to use is written down and explained in one of the documentation pages on the wiki. Please use them. And please type the commands exactly as you see them on these documentation pages, without changing a letter.

Re: Scripters cove

Posted: Sat Mar 10, 2012 8:31 pm
by mandoman
Thank you for that. I always enjoy a good lecture on my inability to grasp the obvious. I'll try harder.

Re: Scripters cove

Posted: Mon Mar 12, 2012 1:54 am
by Gimbal Locke
Hi, I want to write my first OXP for Oolite. I am new to JavaScript, but I've been programming in many languages and I'm eager to learn.

I was wondering if there is a way to detect if a player is in "rear view"? Is there any way to know that the player presses "F2"?

I tried to find it on the Methods page at the wiki (in particular at gui_screen_string), but I did not find anything. Am I looking at the right place? If it is not there, does it mean that it doesn't exist?

Totally unrelated and off-topic :roll: : There existed a "my other ship is a thargoid" rear window sticker for Archimedes Elite. Does anybody have a picture of that, because if I google it the only picture I find says something like "this site has been pwned"?

Re: Scripters cove

Posted: Mon Mar 12, 2012 5:37 am
by Capt. Murphy
Mandoman - Firstly an apology as the scripts I originally posted for you had the this.shipExitedWitchSpace / this.shipExitedWitchspace typo....... :oops:

The scripts also weren't just running under this.shipExitedWitchspace, but also under this.shipLaunchedFromStation. Because you might dock and relaunch several times that's why it included a check for existing UFOships, so extra ones aren't spawned every time you launch. If you only want to potentially spawn them on entering a new system you don't need that check. However you have kept the check but changed it to a check for thargoids....

The change you've made to this line...

Code: Select all

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.

is actually having the effect - do nothing if player kills is less than 512 or there are thargoids in the universe. The return; command effectively ends the function if the conditions are met so the rest of it is not run. Delete that line so you have the code below and it should work... edit to add - as long as your script is set up as a worldScript.

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"); // counts how many thargoids there are
  if (player.score >= 512 && thargoidCounter> 0) // if more than 0 and player score is more than 512 then spawn equal number of UFOships.
{
    system.addShips("UFOship", thargoidCounter, player.ship.position, 20000);
}
}

Re: Scripters cove

Posted: Mon Mar 12, 2012 5:45 am
by Capt. Murphy
Gimbal Locke wrote:
Hi, I want to write my first OXP for Oolite. I am new to JavaScript, but I've been programming in many languages and I'm eager to learn.

I was wondering if there is a way to detect if a player is in "rear view"? Is there any way to know that the player presses "F2"?

I tried to find it on the Methods page at the wiki (in particular at gui_screen_string), but I did not find anything. Am I looking at the right place? If it is not there, does it mean that it doesn't exist?

Totally unrelated and off-topic :roll: : There existed a "my other ship is a thargoid" rear window sticker for Archimedes Elite. Does anybody have a picture of that, because if I google it the only picture I find says something like "this site has been pwned"?
Hi Gimbal-Locke - the page you are looking at is for the legacy scripting engine, not the much more flexible JS script engine.

Try here as a starting point for what you want to do..... http://maikschulz.de/wiki/Oolite_JavaSc ... ionChanged

I'd also read this page http://maikschulz.de/wiki/Scripting_Ool ... JavaScript and follow all of the links to get a grip on how Oolite interacts with the JS engine. These pages have all the Oolite specific JS stuff you need to know.

The two links in my signature will take you to sites that are a general guide to JS syntax, structure and commands (not Oolite specific).

Having read all of that you may still be bemused.....the next thing is to get some scripts from an existing OXP (pick something relatively simple) and see if you can follow how they work referring to the references linked above as necessary.

Re: Scripters cove

Posted: Mon Mar 12, 2012 5:46 am
by Okti
Gimbal Locke wrote:
I was wondering if there is a way to detect if a player is in "rear view"? Is there any way to know that the player presses "F2"?

Code: Select all

this.viewDirectionChanged = function(viewString)
{
  if (viewString == "VIEW_AFT")
  {
     // Your code here
  }
}
Ninja'd by Capt.Murpy :D

Re: Scripters cove

Posted: Mon Mar 12, 2012 9:24 am
by Gimbal Locke
Thanks Capt. Murphy & Cmdr. Okti, I'll try that.

Re: Scripters cove

Posted: Mon Mar 12, 2012 9:33 am
by Commander McLane
Gimbal Locke wrote:
Hi, I want to write my first OXP for Oolite. I am new to JavaScript, but I've been programming in many languages and I'm eager to learn.

I was wondering if there is a way to detect if a player is in "rear view"? Is there any way to know that the player presses "F2"?
Generally, JavaScript is event driven. This means that all scripts act on a pre-defined set of events. Scripting means to attach a script to an event. Whenever this event takes place, your script will be executed.

All events are listed on the event handler pages in the Wiki. There are two distinct sets of events, one for world scripts and one for ship scripts. Ship scripts translate to "things that can happen to NPC ships", and world scripts roughly translate to "things that can happen to the player and/or their ship".

Re: Scripters cove

Posted: Mon Mar 12, 2012 2:16 pm
by Gimbal Locke
Thanks for the information Cmdr. McLane.

With the hints from you, Okti & Capt. Murphy I think I'll get my rear window stickers OXP working soon enough.

Re: Scripters cove

Posted: Mon Mar 12, 2012 2:31 pm
by mandoman
Thanks Capt. Murphy, I'll give that a try. :)

Re: Scripters cove

Posted: Fri Mar 16, 2012 6:58 am
by Capt. Murphy
I don't think this can be done, but thought I'd seen something somewhere (maybe I was dreaming :wink: ), but is it possible to disable/change a customsounds.plist entry on a temporary basis via script? Specifically I'd like to be able to change the "[witchdrive-malfunction]" = "bgs-c_ws_malf.ogg"; in BGS-M, to a dummy sound file, and then change it back again after an OXP has done some stuff.

Re: Scripters cove

Posted: Fri Mar 16, 2012 10:34 am
by Svengali
Capt. Murphy wrote:
I don't think this can be done, but thought I'd seen something somewhere (maybe I was dreaming :wink: ), but is it possible to disable/change a customsounds.plist entry on a temporary basis via script?
Nope, not possible.