Page 82 of 118

Re: Vectors

Posted: Tue May 26, 2015 2:51 pm
by Phasted
Day wrote:
Ah... But maybe it doesn't work when functions are declared this way?:

Code: Select all

var thingie = function() {alert("Hello World!";)}
Correct. In that case the function declaration would be hoisted, but not the definition. If you tried to put a function call before the line that defines the function, you'd get an error.

Re: Vectors

Posted: Tue May 26, 2015 3:15 pm
by Day
Phasted wrote:
Day wrote:
Ah... But maybe it doesn't work when functions are declared this way?:

Code: Select all

var thingie = function() {alert("Hello World!";)}
Correct. In that case the function declaration would be hoisted, but not the definition. If you tried to put a function call before the line that defines the function, you'd get an error.
In this case, is there an interest to use the

Code: Select all

var thingie = function() {alert("Hello World!";)}
form? Except perhaps for dynamic reassignation?

Re: Scripters cove

Posted: Tue May 26, 2015 4:16 pm
by spara
Is is possible to detect, from a script, what cargo will be jettisoned?

Re: Vectors

Posted: Tue May 26, 2015 4:52 pm
by Day
Wildeblood wrote:
Tell more, please.
Ok, so...
I might update this post...
First, I should point that all the math is more precisely explained here: en.wikipedia.org/wiki/Vector_space

Then, for the math part.
A vector space is simply a set of dimensions, like for example this one:
- length,
- height,
- depth,
- alpha,
- time.
These dimensions have units, so we can measure along them.
The zero vector here would be: (0, 0, 0, 0, 0), and the unit vector would be (1, 1, 1, 1, 1).
A vector is a group of n values describing a point in this vector space.
It can used to describe a position, or a displacement, this being a substraction between two positions.
Vectors may be added: +
Vectors may be multiplied: *

Multiplied? Yup, a vector is simply a matrix of dimensions [1, n] or [n, 1] :)

Now, what interesting physical operations can we use vector for?
- translation: adding a vector (displacement) to a vector (position),
- projection: if I want to get the alpha component of my previous vector space, i just have to multiply it by the matrix [[0, 0, 0, 1, 0]].
- rotation, scaling: well, there we go more into the explanation of matrixes.

We speak of an orthogonal vector space when all projections of unit vectors along each dimension on other dimensions give zero. Physically, they are independent.
And an orthonormal vector space is the same, plus each unit vector along each dimension has the same length when using the same function chosen as "length(vector)".
In 3D worlds, we always use orthonormal vector spaces.

Re: Scripters cove

Posted: Tue May 26, 2015 5:39 pm
by spara
Not that I would not enjoy lesson in vectors, but may I humbly ask for a dedicated thread for it. It will get lost here and it's got not much to do with scripting. It's more of a basic maths type of thing. Progress to quaternions and it'll be worth stickying :mrgreen: .

Anyway, to repeat my question, so it won't get lost: Is there a way to detect what the player will be jettisoning next?

Re: Scripters cove

Posted: Tue May 26, 2015 5:54 pm
by Phasted
spara wrote:
Not that I would not enjoy lesson in vectors, but may I humbly ask for a dedicated thread for it
A good point... perhaps one of the moderators can be persuaded to split this off.

Re: Scripters cove

Posted: Tue May 26, 2015 6:06 pm
by Phasted
spara wrote:
Anyway, to repeat my question, so it won't get lost: Is there a way to detect what the player will be jettisoning next?
I think you're out of luck... you'll have to ask for an event handler: this.playerDumpedCargo(commodity, quantity) that fires when the player actually ejects a container or this.playerWillDumpCargo(commodity, quantity) that fires each time the player cycles through his manifest with [crtl-r].

Re: Scripters cove

Posted: Tue May 26, 2015 8:50 pm
by Day
Phasted wrote:
spara wrote:
Not that I would not enjoy lesson in vectors, but may I humbly ask for a dedicated thread for it
A good point... perhaps one of the moderators can be persuaded to split this off.
I'll do one :) (but tomorrow, now is sleepy time)

Re: Scripters cove

Posted: Wed May 27, 2015 10:48 pm
by phkb
How do I get an ellipsis character ("…") using Javascript? I tried var ellip = String.fromCharCode(133);, and even tried inserting it directly into text, but it displays it as a backwards question mark.

Re: Scripters cove

Posted: Thu May 28, 2015 12:57 am
by Norby
phkb wrote:
displays it as a backwards question mark.
Even with 3DFont?

Re: Scripters cove

Posted: Thu May 28, 2015 1:31 am
by phkb
I've tried with the default font, Dangerous square, 3D font, and Standalone font. They all show a question mark (sorry, not a backwards one. just a regular one).

Re: Scripters cove

Posted: Thu May 28, 2015 6:29 am
by cim
phkb wrote:
How do I get an ellipsis character ("…") using Javascript? I tried var ellip = String.fromCharCode(133);, and even tried inserting it directly into text, but it displays it as a backwards question mark.
String.fromCharCode() doesn't support high-bit (128-255) characters very well. Direct insertion into the text file should work fine - I just did mission.runScreen({title: "…"}); in the debug console - but make sure your text editor is saving the file as UTF-8 and not some other encoding.

Re: Scripters cove

Posted: Thu May 28, 2015 6:52 am
by phkb
D'oh! So simple! Thanks cim.

Re: Scripters cove

Posted: Sun May 31, 2015 12:12 am
by Phasted
Downloaded 1.82 and I've just started playing around with it.

Wrote a test commodity script, just to see what would happen...

Code: Select all

this.updateGeneralCommodityDefinition = function(mD, sn, sysID)
{
  var p_a = "price_average", p_e = "price_economic", p_r = "price_random";
  var dL = ns.RLE_IM._difLev, eB, /*= Math.abs(ns.RLE._econBalance),*/ se = "system.economy";
  var pa = mD[p_a], pe = mD[p_e], pr = mD[p_r];
  if(eB == null) {eB = Math.random() * 25;}  log(this.name, eB + sn + ": set by food...");
  pAvg(); pEcon(); pRnd();
  log(this.name, "what time is it?  It's food time!");
  return mD;
  function pAvg()   {if(dL > 3) {pa -= 5 * (dL - 3);} mD[p_a] = pa;}
  function pEcon()  {pe += eB * .0035; if(dL > 3) {pe -= .06 * (dL - 3);} mD[p_e] = pe;}
  function pRnd()   {pr += eB * .0015; mD[p_r] = pr;}
}
For some reason not clear to me this is being called three times... Is it supposed to be called three times, or have I done something I shouldn't have?

Here's the relevant bit from the log:

Code: Select all

19:43:03.595 [RLE-commodity-food]: 22.848355898001792: set by food...
19:43:03.595 [RLE-commodity-food]: what time is it?  It's food time!
19:43:03.596 [RLE-commodity-computers]: 19.71192216405066: set by computers...
19:43:03.596 [RLE-commodity-computers]: what time is it?  It's computer time!
19:43:03.601 [RLE-commodity-food]: 18.91723736814816: set by food...
19:43:03.601 [RLE-commodity-food]: what time is it?  It's food time!
19:43:03.602 [RLE-commodity-computers]: 19.380363223454356: set by computers...
19:43:03.602 [RLE-commodity-computers]: what time is it?  It's computer time!
19:43:03.607 [RLE-commodity-food]: 3.761511813537857: set by food...
19:43:03.607 [RLE-commodity-food]: what time is it?  It's food time!
19:43:03.607 [RLE-commodity-computers]: 24.72310966388351: set by computers...
19:43:03.607 [RLE-commodity-computers]: what time is it?  It's computer time!

Re: Scripters cove

Posted: Sun May 31, 2015 7:57 am
by cim
Phasted wrote:
For some reason not clear to me this is being called three times... Is it supposed to be called three times
Yes. Once with station null for the system prices, and then once for each secondary station of which there are presumably two in your test system.