Scripters cove
Moderators: winston, another_commander
Re: Scripters cove
As far as I can tell, there's no very efficient method to check the scanner for escape pods, as they are not "powered" in the sense of having such a large power unit that they mass-lock the player. Correct?
I was planning on updating the Scanner Alerting Enhancement to check for escape pods, but I am reluctant to call system.filteredEntities() or similar. Is there a good workaround? I'd like to run the scan every second or so.
I was planning on updating the Scanner Alerting Enhancement to check for escape pods, but I am reluctant to call system.filteredEntities() or similar. Is there a good workaround? I'd like to run the scan every second or so.
Re: Scripters cove
player.ship.checkScanner() will return up to 32 nearby objects within scanner range (not necessarily the nearest 32 objects, if the scanner is particularly busy). It's often quicker to call that, and then filter the result yourself, than to usejh145 wrote:I was planning on updating the Scanner Alerting Enhancement to check for escape pods, but I am reluctant to call system.filteredEntities() or similar. Is there a good workaround? I'd like to run the scan every second or so.
system.filteredEntities
in this sort of situation.Re: Scripters cove
D'oh, thanks. I was using checkScanner(true) but didn't bother to ask myself what that "true" parameter was all about.
Re: Scripters cove
I just don't understand vectors...
I want to write a function that will return the bearing (in degrees) to System B from System A.
My clumsy attempt...
It all works fine except that bearing comes back
What really confuses me is how can a vector be used to define coordinates? Which way is the arrow pointing?
I want to write a function that will return the bearing (in degrees) to System B from System A.
My clumsy attempt...
Code: Select all
function checkForBottleneck(sys)
{
var bearing, from = Vector3D([t.coordinates.x, t.coordinates.y, 0]); // start system coordinates
var to = Vector3D([sys.coordinates.x, sys.coordinates.y, 0]); // target system coordinates
var north = from.add(Vector3D([t.coordinates.x, t.coordinates.y - 1, 0]));
// Maybe I misunderstand:
// The idea is to create a vector -- which I understand to be a line segment with a direction
// component -- pointing 0 degrees due north from the start system... but it doesn't seem
// to work...
var angle = radiansToDegrees(north.angleTo(to)), cluster = sys.systemsInRange(7);
function findBearing() {if(t.coordinates.x > sys.coordinates.x) {bearing = 360 - angle;}}
function radiansToDegrees(rad) {return rad * (180 / Math.PI);}
if(cluster.length < 5) {log(ns.RLE_IM.name, sys.name + " might be a bottleneck system...");}
log(ns.RLE_IM.name, "Angle from " + t.name + " to " + sys.name + ": " + bearing + " degrees.");
}
undefined
and I just can't figure out why...What really confuses me is how can a vector be used to define coordinates? Which way is the arrow pointing?
Re: Scripters cove
You should define radiansToDegree() before calling it.
EDIT: findBearing() is defined, but not called. So as bearing is assigned only in findBearing(), bearing is always undefined.
EDIT2:
EDIT3:
A vector is not really an arrow, this is just an easy geometrical representation. Mathematically, a vector in a n-dimensional system is a group of n values relative to these n dimensions.
For example:
- in 2D, a coordinate can be represented by a vector (x, y) which is a couple of values.
- in 3D, a coordinate can be represented by a vector (x, y, z) which is a triplet of values.
- in 26D, a coordinate can be represented by a vector (a, b, c, ..., z) which is a 26-group of values.
Now, it's really easy too use vectors to represent things in 2D or 3D, so we use them. The math domain is called Vectorial spaces (well, at least in France).
But we use them for things with a lot more dimensions, like the preferences of a user:
- user intensity of preference of character 1 in a game,
- user intensity of preference of character 2 in a game,
- user intensity of preference of character 3 in a game,
- user intensity of preference of character 4 in a game,
- user intensity of preference of character 5 in a game,
- user intensity of preference of character 6 in a game.
Now we represent the intensity of preference for a user as a vector (0, 4, 6, 2, 5, 10).
And do this for all users.
And notice that the users are in groups, visible when representing geometrically all these vectors simultaneously (those liking character 1 not liking the character 3).
And do that for marketing or spam, to identify which people are likely to succumb to product X based on what we already know of them, and what already known similar people (those with near vectors) have succumbed to...
EDIT: findBearing() is defined, but not called. So as bearing is assigned only in findBearing(), bearing is always undefined.
EDIT2:
You have to imagine a vector as an arrow from the origin (0, 0, 0) to its coordinates (x, y, z).What really confuses me is how can a vector be used to define coordinates? Which way is the arrow pointing?
EDIT3:
A vector is not really an arrow, this is just an easy geometrical representation. Mathematically, a vector in a n-dimensional system is a group of n values relative to these n dimensions.
For example:
- in 2D, a coordinate can be represented by a vector (x, y) which is a couple of values.
- in 3D, a coordinate can be represented by a vector (x, y, z) which is a triplet of values.
- in 26D, a coordinate can be represented by a vector (a, b, c, ..., z) which is a 26-group of values.
Now, it's really easy too use vectors to represent things in 2D or 3D, so we use them. The math domain is called Vectorial spaces (well, at least in France).
But we use them for things with a lot more dimensions, like the preferences of a user:
- user intensity of preference of character 1 in a game,
- user intensity of preference of character 2 in a game,
- user intensity of preference of character 3 in a game,
- user intensity of preference of character 4 in a game,
- user intensity of preference of character 5 in a game,
- user intensity of preference of character 6 in a game.
Now we represent the intensity of preference for a user as a vector (0, 4, 6, 2, 5, 10).
And do this for all users.
And notice that the users are in groups, visible when representing geometrically all these vectors simultaneously (those liking character 1 not liking the character 3).
And do that for marketing or spam, to identify which people are likely to succumb to product X based on what we already know of them, and what already known similar people (those with near vectors) have succumbed to...
Re: Scripters cove
From the origin... I had that 100% all wrong!Day wrote:EDIT2:You have to imagine a vector as an arrow from the origin (0, 0, 0) to its coordinates (x, y, z).What really confuses me is how can a vector be used to define coordinates? Which way is the arrow pointing?
So clearly, my idea is all wet...
Which leaves me with the problem: How do I determine the compass bearing/azimuth (in degrees) to B from A?
Re: Scripters cove
Maybe not. I mean, a vector (1, 2) is a move of 1 along x, and 2 along y. It can be represented as an arrow from (0, 0) to (1, 2)Phasted wrote:From the origin... I had that 100% all wrong!Day wrote:EDIT2:You have to imagine a vector as an arrow from the origin (0, 0, 0) to its coordinates (x, y, z).What really confuses me is how can a vector be used to define coordinates? Which way is the arrow pointing?
So clearly, my idea is all wet...
Your formula was sound, I think. Just the order of your commands.Which leaves me with the problem: How do I determine the compass bearing/azimuth (in degrees) to B from A?
- Wildeblood
- ---- E L I T E ----
- Posts: 2453
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
- Contact:
Vectors
Tell more, please.Day wrote:A vector is not really an arrow, this is just an easy geometrical representation. Mathematically, a vector in a n-dimensional system is a group of n values relative to these n dimensions.
For example:
- in 2D, a coordinate can be represented by a vector (x, y) which is a couple of values.
- in 3D, a coordinate can be represented by a vector (x, y, z) which is a triplet of values.
- in 26D, a coordinate can be represented by a vector (a, b, c, ..., z) which is a 26-group of values.
Now, it's really easy too use vectors to represent things in 2D or 3D, so we use them. The math domain is called Vectorial spaces (well, at least in France).
But we use them for things with a lot more dimensions, like the preferences of a user:
- user intensity of preference of character 1 in a game,
- user intensity of preference of character 2 in a game,
- user intensity of preference of character 3 in a game,
- user intensity of preference of character 4 in a game,
- user intensity of preference of character 5 in a game,
- user intensity of preference of character 6 in a game.
Now we represent the intensity of preference for a user as a vector (0, 4, 6, 2, 5, 10).
And do this for all users.
And notice that the users are in groups, visible when representing geometrically all these vectors simultaneously (those liking character 1 not liking the character 3).
And do that for marketing or spam, to identify which people are likely to succumb to product X based on what we already know of them, and what already known similar people (those with near vectors) have succumbed to...
Re: Scripters cove
Something like this could work (not tested):
function checkForBottleneck(sys)
{
function radiansToDegrees(rad) {return rad * 180 / Math.PI;}
var fromTo = Vector3D([sys.coordinates.x - t.coordinates.x, sys.coordinates.y - t.coordinates.y, 0]);
var north = Vector3D([0, -1, 0]));
var angle = radiansToDegrees(north.angleTo(fromTo));
log(ns.RLE_IM.name, "Angle from " + t.name + " to " + sys.name + ": " + angle + " degrees.");
}
function checkForBottleneck(sys)
{
function radiansToDegrees(rad) {return rad * 180 / Math.PI;}
var fromTo = Vector3D([sys.coordinates.x - t.coordinates.x, sys.coordinates.y - t.coordinates.y, 0]);
var north = Vector3D([0, -1, 0]));
var angle = radiansToDegrees(north.angleTo(fromTo));
log(ns.RLE_IM.name, "Angle from " + t.name + " to " + sys.name + ": " + angle + " degrees.");
}
Re: Vectors
Really? I would have thought to be rather boring.Wildeblood wrote:Tell more, please.
On which part? The math part, or the usage part?
- Wildeblood
- ---- E L I T E ----
- Posts: 2453
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
- Contact:
Re: Vectors
Ether or both. It seems like an interesting subject.Day wrote:Really? I would have thought to be rather boring.Wildeblood wrote:Tell more, please.
On which part? The math part, or the usage part?
Re: Vectors
Far from boring... in fact, quite useful. Thanks to your very helpful insight on visualizing vectors and your suggestion about converting the coordinates, I was able to solve my problem... or the first part of it anyway...Day wrote:Really? I would have thought to be rather boring.Wildeblood wrote:Tell more, please.
Code: Select all
this._prepareForNextSystem = function(type)
{
if(type === "galactic") {return;}
var d, t = System.infoForSystem(galaxyNumber, player.ship.targetSystem);
function findEconBalance() {}
function findDistance(sys)
{
function findBearing()
{
var c = "coordinates", V3D = Vector3D;
var from = V3D([t[c].x, t[c].y, 0]), North = V3D([0, -1, 0]), to = V3D([sys[c].x, sys[c].y, 0]);
var adj_c = convertCoordinates(), angle = radToDeg(North.angleTo(adj_c)), bearing = angleToBearing();
function angleToBearing() {if(from.x > to.x) {return 360 - angle;} else {return angle;}}
function convertCoordinates() {return V3D([(to.x - from.x), (to.y - from.y), 0]);}
function radToDeg(rad) {return rad * (180 / Math.PI);}
log(ns.RLE_IM.name, "Bearing from " + t.name + " to " + sys.name + ": " + bearing + " degrees.");
}
d = t.distanceToSystem(sys);
findBearing();
}
this._cluster = t.systemsInRange(7);
//this._group = t.systemsInRange(14);
//this._sector = t.systemsInRange(21);
//this._quadrant = t.systemsInRange(28);
this._cluster.forEach(findDistance);
Re: Vectors
Phasted wrote:Far from boring... in fact, quite useful. Thanks to your very helpful insight on visualizing vectors and your suggestion about converting the coordinates, I was able to solve my problem... or the first part of it anyway...Day wrote:Really? I would have thought to be rather boring.Wildeblood wrote:Tell more, please.
You're welcome.Phasted wrote:Tested and bug-free. Thanks.Code: Select all
function findBearing() { var c = "coordinates", V3D = Vector3D; var from = V3D([t[c].x, t[c].y, 0]), North = V3D([0, -1, 0]), to = V3D([sys[c].x, sys[c].y, 0]); var adj_c = convertCoordinates(), angle = radToDeg(North.angleTo(adj_c)), bearing = angleToBearing(); function angleToBearing() {if(from.x > to.x) {return 360 - angle;} else {return angle;}} function convertCoordinates() {return V3D([(to.x - from.x), (to.y - from.y), 0]);} function radToDeg(rad) {return rad * (180 / Math.PI);} log(ns.RLE_IM.name, "Bearing from " + t.name + " to " + sys.name + ": " + bearing + " degrees."); }
Is this working, even the exact first time it is called? I'm puzzled at the fact you use functions before declaring them (convertToCoordinates, radToDeg, angleToBearing).
Another thing. You might like to use the ternary operator ?: in angleToBearing().
It would be rewritten like this:
Code: Select all
function angleToBearing() { return from.x > to.x ? 360 - angle : angle;}
Re: Vectors
Day wrote:Is this working, even the exact first time it is called? I'm puzzled at the fact you use functions before declaring them (convertToCoordinates, radToDeg, angleToBearing).
In JavaScript, function definitions are "hoisted" to the top of the enclosing function or code. So, as long as all of the variables are declared and defined BEFORE the function is called, you can put the function definition just about anywhere,,,
This one is tricky. The variables have to be defined in a certain order (c before from and to; from and to before adj_c, etc.) But it works...
Re: Vectors
Ah... But maybe it doesn't work when functions are declared this way?:Phasted wrote:In JavaScript, function definitions are "hoisted" to the top of the enclosing function or code. So, as long as all of the variables are declared and defined BEFORE the function is called, you can put the function definition just about anywhere,,,Day wrote:Is this working, even the exact first time it is called? I'm puzzled at the fact you use functions before declaring them (convertToCoordinates, radToDeg, angleToBearing).
This one is tricky. The variables have to be defined in a certain order (c before from and to; from and to before adj_c, etc.) But it works...
Code: Select all
var thingie = function() {alert("Hello World!";)}