Page 1 of 2

Is There A Comprehensive Guide/List Of Java Script Commands?

Posted: Tue Jan 03, 2012 1:12 am
by mandoman
I need to get my brain around Java Script in Oolite, and the main thing I'm having difficulty with is the commands which define conditions, create reactions, figure number variables, etc... Is there a guide for this? I SEE what others have done with "if", "else", "var", "Math.floor. Math.random, Math.abs", but I don't seem to be putting them together as a valid Java Script. I've gotten past the "Setup Actions", at lest to some degree, though not perfectly, but I need a way to use the commands I have listed, and any others I haven't listed because I don't know about. I feel like I'm just on the verge of understanding, but there is a block I have not been able to get through. Anyone know of such a guide, or list? Thanks.

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 1:19 am
by PhantorGorth
Not that detailed but a great starting point is:

http://www.w3schools.com/js/

It should cover the answers to most of the the questions you are posing, but remember that it is written from the point of view of a web developer not for some other use of a JS engine. For instance the window object is provided by all JS supporting browsers but that object doesn't exist in Oolite. For the special Oolite objects such as player, ship, mission, etc see the wiki starting here.

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 1:26 am
by mandoman
PhantorGorth wrote:
Not that detailed but a great starting point is:

http://www.w3schools.com/js/

It should cover the answers to most of the the questions you are posing, but remember that it is written from the point of view of a web developer not for some other use of a JS engine. For instance the window object is provided by all JS supporting browsers but that object doesn't exist in Oolite. For the special Oolite objects such as player, ship, mission, etc see the wiki starting here.
Thank you. That does help. :)

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 2:40 pm
by JensAyton
And for reference documentation for built-in JavaScript objects and functions (like Math), as well as syntax like if statements, see the Mozilla Developer Network.

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 3:52 pm
by SandJ
mandoman wrote:
I need to get my brain around Java Script in Oolite, and the main thing I'm having difficulty with is the commands which define conditions, create reactions, figure number variables, etc... Is there a guide for this?
For generic JavaScript, you can do a lot worse than see what books your public library has. I got half a dozen out at once a couple of years ago when trying to learn it myself.

Meanwhile:
- Wikipedia JavaScript syntax;
- a list of JavaScript reference sites.

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 4:17 pm
by snork
PhantorGorth wrote:
Not that detailed but a great starting point is:

http://www.w3schools.com/js/
I just found that site yesterday, (because of wikipedia userscript/css) and it is nice, has nifty little this and that, among them a really nice colour-listing / picker.

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 4:51 pm
by PhantorGorth
snork wrote:
PhantorGorth wrote:
Not that detailed but a great starting point is:

http://www.w3schools.com/js/
I just found that site yesterday, (because of wikipedia userscript/css) and it is nice, has nifty little this and that, among them a really nice colour-listing / picker.
I am surprised people don't find that place straight away; it's the second non-ad entry on a google search of "javascript".

I find that it's not bad for getting you started and for reminding yourself of various function syntaxes, but it doesn't cover complex stuff like scope and closures.

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 5:06 pm
by Eric Walch
PhantorGorth wrote:
I am surprised people don't find that place straight away; it's the second non-ad entry on a google search of "javascript".
I am surprised its also the second result on a google search on the dutch google site. Al other pages in the top 5 being in dutch language, its surprising that an english page is that high.

A big google flaw is that number one in the google results is the dutch site about Java! (No relation with javaScript)

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 6:01 pm
by mandoman
Have to admit that I never tried a Google search. I had the understanding that Java Script in Oolite is not quite the same as Java Script in general. I guess it's true, because I can't get this dang script to even be recognized AS a Java Script. I swear, I'm going to starting chewing on nails pretty soon. It LOOKS like what i have written is following the principles I have been reading in the Oolite oxpHowToWiki, and now also with the suggested sight, but all I get in return in Latest.log is "such, and such is a nonScript, ignoring". Keeps telling me I have a semi colon in the wrong place, or it's needed where the examples I have looked at show no indication of putting one. Frustrating. I'll just keep at it, I guess.

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 6:22 pm
by PhantorGorth
mandoman wrote:
Have to admit that I never tried a Google search. I had the understanding that Java Script in Oolite is not quite the same as Java Script in general. I guess it's true, because I can't get this dang script to even be recognized AS a Java Script. I swear, I'm going to starting chewing on nails pretty soon. It LOOKS like what i have written is following the principles I have been reading in the Oolite oxpHowToWiki, and now also with the suggested sight, but all I get in return in Latest.log is "such, and such is a nonScript, ignoring". Keeps telling me I have a semi colon in the wrong place, or it's needed where the examples I have looked at show no indication of putting one. Frustrating. I'll just keep at it, I guess.
Oolite uses the SpiderMonkey JS engine from Mozilla. The same one used in Firefox. The any differences are therefore not syntactic, they are instead down to available objects exposed by the program it's embedded in and how you add JS to Oolite over how you add it to a webpage. Your problems sound more like you are not writing valid Javascript, but without looking at your code I can not comment on the issues you are getting.

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 6:40 pm
by mandoman
Okay, here it is. You're right about it not being a valid script, as Oolite keeps telling me the same thing. All I wanted for this ship, which is a non-player ship, was to have it exit Witchspace in situations where three or more Thargoid ships are invading a system, in equal numbers to Thargoids present, and attack the Thargoids until either they, or my UFOships are destroyed.. Whether it's an all out military battle, or not. Can't seem to figure out how to pull it off. Non-script:

Code: Select all

// Standard attributes 
this.name           = "UFOship.js"; 
this.author         = "Smivs"; 
this.copyright      = "This script is hereby placed in the public domain."; 
this.version        = "1.0.1"; 
this.description    = "Script to make equal number of UFOships as number of Thargoid ships, appear at any battle with Thargoids, when Thargoids number more than 2."

this.startUp = function()
{

I had a more up to date version of this last night, but now I can't find it.  I doubt it was much better anyway.
  this.ship = "UFOship";
}

{
this.thargoid = ["thargoid battleship", "thargoid carrier", "thargoid cruiser", "thargoid tharglet", "thargoid terroriser"];
this.thargoidShipList = this.ship.thargoidRoles.concat(); // this is the "working" list of roles, which shortens as roles are picked for spawning.
}

this.ship = "roles";
{
this.role1 = "UFOship will exit witchspace";
this.role2 = "UFOship will attack thargoid ships";
this.role3 = "UFOship will attack any aggressor";
this.role4 = "UFOship will enter witchspace"; // these are all the rolls of the UFOship, dependant on conditions.
}

this.role1 = function() 
{
  if(thargoid.shiplist)
  {
         var number = Math.floor(Math.abs()*>=3.0); // more than 2 thargoid ships present.
         for(var i=3; i>=number; i++) this.thargoidShipList(this.thargoidshiplist(), =3); //UFOship will equal same number as there are thargoids present.
  };
}

this.role2 = function()
{
  if(thargoid.shiplist)
  {
          var number = Math.floor(Math.abs()*>=3.0); //Three or more thargoids present.
  };
}

this.role3 = function()
{
  if(this.ship is attacked by any aggressor)
}

this.role4 = function()
{
  if(this.thargoidshiplist)
  {
          var number = Math.floor(Math.abs()=0.0);
  };
}
  
  

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 7:18 pm
by Smivs
Just to put the record straight, I don't remember authoring that particular script! :wink:

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 7:53 pm
by mandoman
Smivs wrote:
Just to put the record straight, I don't remember authoring that particular script! :wink:
No, I know that, and certainly don't hold anyone but myself to account for it. The way you wrote it worked for how you had it, but it was not the ultimate goal for which I have set for that ship. I don't want to just spawn it every time I jump into a system, I want Oolite to spawn it when certain conditions are met. It can exit Witchspace any time there are 3 or more Thargoids present, and there needs to be the same number of UFOships spawned as there are Thargoids present. I don't understand why that is so difficult to achieve, but for me it sure seems to be. Last night I had used a combination of

Code: Select all

this.startUp = function()
{
  this.ship = "UFOship";
}

{
this.thargoid = ["thargoid battleship", "thargoid carrier", "thargoid cruiser", "thargoid tharglet", "thargoid terroriser"];
this.thargoidShipList = this.ship.thargoidRoles.concat();

this.shipWillExitWitchspace = function()
{
           if(system.isInterstellarSpace)
          {
                     var number = Math.floor(Math.abs()*Math.abs()*3);
                     if(this.thargoidshiplist.length >= number) this.thargoidshiplist = this.thargoid.concat;
                     for(var u>=3; u>=number; u++) system.legacy_addships(this.ship(), 3);
That's all I can remember. As you see, it is a bit different than what I showed before, as I was attempting to change that to the one in this post, but I still got the syntax Error warnings, and "this UFOship.js is a nonscript".

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 8:40 pm
by PhantorGorth
Oh my. I hate to say this but there are more things wrong than right.

It would be too much to discuss in here so I am willing to discuss it in PMs.

What I suggest though is to start simpler. See if you can write a simple OXP that say just spawns a UFOship near the witchpoint on the player arrival in the system and does nothing else. Read the W3Schools site. Read the wiki's JS scripting reference pages to find out how to spawn a ship. Look at the where braces, brackets, semicolons, etc are used in other people's code.

Get that simple OXP right first then start to build from there.

Re: Is There A Comprehensive Guide/List Of Java Script Comma

Posted: Tue Jan 03, 2012 11:51 pm
by mandoman
PhantorGorth wrote:
Oh my. I hate to say this but there are more things wrong than right.

It would be too much to discuss in here so I am willing to discuss it in PMs.

What I suggest though is to start simpler. See if you can write a simple OXP that say just spawns a UFOship near the witchpoint on the player arrival in the system and does nothing else. Read the W3Schools site. Read the wiki's JS scripting reference pages to find out how to spawn a ship. Look at the where braces, brackets, semicolons, etc are used in other people's code.

Get that simple OXP right first then start to build from there.
Okay. I thought that's what I was doing. Maybe I just don't have the brains for this, or talent, but I'm willing to keep trying. If I can learn it even a little, it will be one step forward for me. Did you want me to PM you, or the other way around?