Scripters cove

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: another_commander, winston

User avatar
Phasted
Competent
Competent
Posts: 51
Joined: Wed Jun 09, 2010 3:56 pm

Re: Vectors

Post 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.
User avatar
Day
---- E L I T E ----
---- E L I T E ----
Posts: 545
Joined: Tue Mar 03, 2015 11:35 am
Location: Paris

Re: Vectors

Post 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?
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2676
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

Is is possible to detect, from a script, what cargo will be jettisoned?
User avatar
Day
---- E L I T E ----
---- E L I T E ----
Posts: 545
Joined: Tue Mar 03, 2015 11:35 am
Location: Paris

Re: Vectors

Post 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.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2676
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post 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?
User avatar
Phasted
Competent
Competent
Posts: 51
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripters cove

Post 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.
User avatar
Phasted
Competent
Competent
Posts: 51
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripters cove

Post 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].
User avatar
Day
---- E L I T E ----
---- E L I T E ----
Posts: 545
Joined: Tue Mar 03, 2015 11:35 am
Location: Paris

Re: Scripters cove

Post 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)
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4646
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post 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.
User avatar
Norby
---- E L I T E ----
---- E L I T E ----
Posts: 2577
Joined: Mon May 20, 2013 9:53 pm
Location: Budapest, Hungary (Mainly Agricultural Democracy, TL10)
Contact:

Re: Scripters cove

Post by Norby »

phkb wrote:
displays it as a backwards question mark.
Even with 3DFont?
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4646
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post 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).
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post 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.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4646
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

D'oh! So simple! Thanks cim.
User avatar
Phasted
Competent
Competent
Posts: 51
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripters cove

Post 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!
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post 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.
Post Reply