Page 3 of 4

Posted: Tue Jul 21, 2009 10:59 pm
by another_commander
For scripting missions examples you have to have a look at Cataclysm.

Posted: Wed Jul 22, 2009 1:42 pm
by Commander McLane
another_commander wrote:
For scripting missions examples you have to have a look at Cataclysm.
Thanks for the appraisal, :D however I wouldn't really suggest that as a first look. It's quite complex (probably the longest JS-script to date) and not commented. I'd therefore rather suggest the Anarchies-script, which I happen to have commented quite extensively (it was my first attempt in JS-scripting, also translating the older legacy version, and I found it a good idea at the time to comment basically every line--would still be a good idea, of course, but I've gotten lazy :roll: ).

At the risk of boring you, Rustybolts, by re-iterating my mantra again: Why don't you start with the JavaScript test OXP provided in the wiki? It is again linked to from the Category:Oolite_scripting-page. Really, all information you need is concentrated on and accessible from this very entry point.

Posted: Wed Jul 22, 2009 2:02 pm
by Eric Walch
Commander McLane wrote:
Why don't you start with the JavaScript test OXP provided in the wiki? ... Really, all information you need is concentrated on and accessible from this very entry point.
Only that "LogWithClass" in that script is outdated and should be replaced by just "log"

For mission offering I would look inside UPS-courier as Svengali wrote. The UPS scripts themselves are to complex to start with, but I added a stripped demo script that is commented and dedicated to offering missions. (I really should upload it once as a separate file)

Posted: Wed Jul 22, 2009 3:32 pm
by Rustybolts
Thanks guys for the suggestions i will most probably will be looking at all the above suggestions.
Commander Mclane
At the risk of boring you, Rustybolts, by re-iterating my mantra again: Why don't you start with the JavaScript test OXP provided in the wiki? It is again linked to from the Category:Oolite_scripting-page. Really, all information you need is concentrated on and accessible from this very entry point.
Yes i will be looking at this to :D

Cheers Rusty

Posted: Wed Jul 22, 2009 7:32 pm
by Rustybolts
Have been looking into js one thing that puzzles me so far is

Code: Select all

if (missionVariables.longwayround=='MISSION_COMPLETE'
			&& !missionVariables.blackbaron
Is " !missionVariables.blackbaron " asking if it is undefined?

Posted: Wed Jul 22, 2009 7:41 pm
by Eric Walch
Rustybolts wrote:
Have been looking into js one thing that puzzles me so far is

Code: Select all

if (missionVariables.longwayround=='MISSION_COMPLETE'
			&& !missionVariables.blackbaron
Is " !missionVariables.blackbaron " asking if it is undefined?
Yes. Mission variables are stored as strings and there you only test for existence with this test.
With normal variables this could also mean that the variable is false or zero. (I made already some mistakes with the difference)

Posted: Thu Jul 23, 2009 6:02 am
by Commander McLane
Ah, that's a point I completely forgot. Sorry.

What is not included in the wiki-documentation is a documentation of the JavaScript-syntax as such (like what '!' means, or the difference between '=' and '==', and things like that). You would need to find this elsewhere. But it should be easily available somewhere in the interweb.

Posted: Thu Jul 23, 2009 6:15 am
by Rustybolts
For anyone else reading this thread and is interested
Artithmetic Operators
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus (remainder of a division)
++ Increment
-- Decrement
Assignment Operators
Operator Description
= Assign
+= Add and assign. For example, x+=y is the same as x=x+y.
-= Subtract and assign. For example, x-=y is the same as x=x-y.
*= Multiply and assign. For example, x*=y is the same as x=x*y.
/= Divide and assign. For example, x/=y is the same as x=x/y.
%= Modulus and assign. For example, x%=y is the same as x=x%y.
Comparison Operators
Operator Description
== Is equal to
=== Is identical (is equal to and is of the same type)
!= Is not equal to
!== Is not identical
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
Logical/boolean Operators
Operator Description
&& and
|| or
! not
String Operators
In JavaScript, a string is simply a piece of text.

Operator Description
= Assignment
+ Concatenate (join two strings together)
+= Concatenate and assign

Posted: Thu Jul 23, 2009 7:58 am
by Griff
Thanks for the list Rustybolts, very helpful! the '+=' one crops up a lot in the Oolite shader code examples, i could never find out what it was exactly and only managed to work it out with lots of experimenting so it's really great to have a proper explanation

Posted: Thu Jul 23, 2009 8:11 am
by Eric Walch
Thanks Rustybolts, maybe the list should be put on the wiki for starting scripters. It covers the most often used operators needed to understand 99% of the scripts. (At least on the point of operators)

I only want to add that there are two kinds of ++

Code: Select all

x = 5;
y = x++;
First assign and than increment. y will be 5 and x will be 6 at the end

Code: Select all

x = 5;
y = ++x;
First increment and than assign. y will be 6 and x will be 6 at the end

Posted: Thu Jul 23, 2009 5:18 pm
by Cmd. Cheyd
If that doesn't get added to the wiki, I'm printing it and posting it beside my home computer. I know JACK about javascripting and have been having a hard time understanding some of the maths / operations by simply looking at existing code.

Posted: Thu Jul 23, 2009 7:07 pm
by Eric Walch
Cmd. Cheyd wrote:
If that doesn't get added to the wiki, I'm printing it and posting it beside my home computer.
I made a start here. Other may fill it in further.

Posted: Thu Jul 23, 2009 7:29 pm
by Thargoid
As I said in reply to your PM, I'd recommend the FAQs at Javascripter.net as quite a good quick resource for looking things up. Alongside the wiki of course for more Oolite-specific functions, methods and events.

Posted: Thu Jul 23, 2009 7:39 pm
by Rustybolts
Thargoid wrote:
As I said in reply to your PM, I'd recommend the FAQs at Javascripter.net as quite a good quick resource for looking things up. Alongside the wiki of course for more Oolite-specific functions, methods and events.
My pm?
Good site though!

Posted: Thu Jul 23, 2009 7:58 pm
by Thargoid
No, Cmd. Cheyd's :)