Scripters cove
Moderators: winston, another_commander
Re: Question about Timers
Thanks Wildeblood, I'll try that.
And I think I understand now why my first experiments with timers failed miserably...
And I think I understand now why my first experiments with timers failed miserably...
忍 knowing that enough is enough, you'll always have enough.
Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
- Rorschachhamster
- ---- E L I T E ----
- Posts: 274
- Joined: Sun Aug 05, 2012 11:46 pm
- Contact:
Re: Scripters cove
Ok, quaternions...
In the documentation on the wiki there is the example for a rotation with two subentities at 120° +/-. I work on a three point system of leading a ship slowly unto the position of another entity with a very slow pace (to avoid collision warning before the very near point is reached). This is what I have, with rotationBy as the example rotations, because it is three sided, for the vector that is the vector on wich the ship closes in:
Now, if this.vectorContainer isn't changed it works like a charm... Any hints?
In the documentation on the wiki there is the example for a rotation with two subentities at 120° +/-. I work on a three point system of leading a ship slowly unto the position of another entity with a very slow pace (to avoid collision warning before the very near point is reached). This is what I have, with rotationBy as the example rotations, because it is three sided, for the vector that is the vector on wich the ship closes in:
Code: Select all
this.vectorContainer = chosenWagon.vectorUp;
var choosedirection = Math.ceil(Math.random()*3);
switch (choosedirection) {
case(1):
this.vectorContainer = chosenWagon.vectorUp.rotateBy([0.5,0,0,0.8660254]);
break;
case (2):
this.vectorContainer = chosenWagon.vectorUp.rotateBy([0.5,0,0,-0.8660254]);
break;
default:
break;
};
- Wildeblood
- ---- E L I T E ----
- Posts: 2453
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
- Contact:
Re: Scripters cove
How do I scan an array and delete each element that has a particular value? I was thinking I could just use a for loop, but that's nonsense because as soon as an element gets deleted the array changes length.
Here the fifth element of each sub-array is its category:-
And I want to remove two of the three sub-arrays by calling
Here the fifth element of each sub-array is its category:-
Code: Select all
this.$tips = [
["content","content","content","content","myCategory"],
["content","content","content","content","otherCategory"],
["content","content","content","content","myCategory"]
];
this.$removeTips(myCategory)
.Code: Select all
// REMOVE ALL TIPS IN GIVEN CATEGORY
this.$removeTips = function(category)
{
var counter = 0;
for (var i = 0; i < this.$tips.length; i++) // BOGUS!
{
if (this.$tips[i][5] && this.$tips[i][5] === category)
{
delete this.$tips[i];
counter++;
}
}
return counter;
}
- Eric Walch
- Slightly Grand Rear Admiral
- Posts: 5536
- Joined: Sat Jun 16, 2007 3:48 pm
- Location: Netherlands
Re: Scripters cove
Games use quaternions because this is the fastest way to calculate 3D movements. When you want to do movements, you start with calculating the movement quaternion: That do you by taking the identity quaternion [1,0,0,0] and rotate is according to the axes you need. Than you have the quaternion with the rotation and multiply that with the old ships quaternion.
e.g.
q = new Quaternion(1,0,0,0)
q = q.rotateZ(rol*Δt);
q = q.rotateX(pitch*Δt);
ship.orientation = ship.orientation.multiply(q);
(I am not sure about the multiplying order in the last line. It could be the other way round. It is a long time ago I wrote a test script doing it this way and I can't find it anymore)
In here Δt is the time parameter, assuming you do it in frameCallbacks.
e.g.
q = new Quaternion(1,0,0,0)
q = q.rotateZ(rol*Δt);
q = q.rotateX(pitch*Δt);
ship.orientation = ship.orientation.multiply(q);
(I am not sure about the multiplying order in the last line. It could be the other way round. It is a long time ago I wrote a test script doing it this way and I can't find it anymore)
In here Δt is the time parameter, assuming you do it in frameCallbacks.
Last edited by Eric Walch on Wed Mar 06, 2013 4:10 pm, edited 1 time in total.
UPS-Courier & DeepSpacePirates & others at the box and some older versions
Re: Scripters cove
Reverse the for loopWildeblood wrote:How do I scan an array and delete each element that has a particular value? I was thinking I could just use a for loop, but that's nonsense because as soon as an element gets deleted the array changes length.
Code: Select all
for (var i = this.$tips.length-1 ; i >= 0 ; i--)
- Wildeblood
- ---- E L I T E ----
- Posts: 2453
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
- Contact:
Re: Scripters cove
Thanks, cim.cim wrote:Reverse the polarity of the plasma conduits.
- Rorschachhamster
- ---- E L I T E ----
- Posts: 274
- Joined: Sun Aug 05, 2012 11:46 pm
- Contact:
Re: Scripters cove
Ok... this sounds like I can understand it, eventually. Oh, and I probably have to because visualEffects can't be AIed.Eric Walch wrote:Games use quaternions because this is the fastest way to calculate 3D movements. When you want to do movements, you start with calculating the movement quaternion: That do you by taking the identity quaternion [1,0,0,0] and rotate is according to the axes you need. Than you have the quaternion with the rotation and multiply that with the old ships quaternion.
e.g.
q = new Quaternion(1,0,0,0)
q = q.rotateZ(rol*Δt);
q = q.rotateX(pitch*Δt);
ship.orientation = ship.orientation.multiply(q);
(I am not sure about the multiplying order in the last line. It could be the other way round. It is a long time ago I wrote a test script doing it this way and I can't find it anymore)
In here Δt is the time parameter, assuming you do it in frameCallbacks.
But the actual problem is really more a Vector3D question, in wich rotateBy uses a Quaternion to specify the rotation.
I need the vectorUp rotated by 120° (and 240° or -120°) around the z-axis of the ship that it's originates from, but it's in another ship's script.
The chosenWagon is the origin of the vectorUp. So, it has to be turned around the vectorForward (or heading) of that ship, and I thought this would be done by the same quaternion as in the subentities example on the wiki. Obviously this doesn't work. Maybe because I have to work that z-axis to be turned around somehow in? I really don't know, how...
Re: Scripters cove
Hello helpful people. Question about weaponFacings.
I'm using this code to read the number of weapon facings of a targeted ship:
I'm getting a reading 15 from Orbital Shuttle and Buoy (amongst others). Is this property in use yet and what does it actually tell?
I'm am a bit confused as Orbital Shuttle's shipdata says:
I'm using this code to read the number of weapon facings of a targeted ship:
Code: Select all
this.shipTargetAcquired = function(target) {
log("facings", target.weaponFacings);
}
I'm am a bit confused as Orbital Shuttle's shipdata says:
Code: Select all
forward_weapon_type = "WEAPON_NONE";
...
weapon_facings = 0;
weapon_position_aft = "0.0 0.0 -17.5";
weapon_position_forward = "0.0 -4.5 17.5";
weapon_position_port = "-9.0 0.0 11.5";
weapon_position_starboard = "9.0 0.0 11.5";
Re: Scripters cove
The wiki tells all. The value is a bitmask of the four facings and whether they are available or not.
The other bits in shipdata are the weapon positions on the model-is where the beam comes from when that weapon fires. But yes the weapon_facings setting in the shipdata does seem a bit odd and is being ignored for some reason, maybe being overridden by having the position entire in there.
The other bits in shipdata are the weapon positions on the model-is where the beam comes from when that weapon fires. But yes the weapon_facings setting in the shipdata does seem a bit odd and is being ignored for some reason, maybe being overridden by having the position entire in there.
My OXPs via Boxspace or from my Wiki pages .
Thargoid TV
Dropbox Referral Link
Thargoid TV
Dropbox Referral Link
Re: Scripters cove
Do you have any replacement shipsets installed? If so, I don't believe any of those have yet been updated to include thespara wrote:I'm getting a reading 15 from Orbital Shuttle and Buoy (amongst others). Is this property in use yet and what does it actually tell?
I'm am a bit confused as Orbital Shuttle's shipdata says:
weapon_facings
parameter, so they'll be overriding the core shipdata, not specifying it, and it'll default back to 15.- Smivs
- Retired Assassin
- Posts: 8408
- Joined: Tue Feb 09, 2010 11:31 am
- Location: Lost in space
- Contact:
Re: Scripters cove
<Smivs adds another line to his 'To do' list...>cim wrote:Do you have any replacement shipsets installed? If so, I don't believe any of those have yet been updated to include theweapon_facings
parameter...
Commander Smivs, the friendliest Gourd this side of Riedquat.
Re: Scripters cove
Why of course . You must be psychic cim. I'm using Griff's atm and at the same time looking at the core ship definitions. All clear now, thanks a lot.
This probably means, that before the most popular shipsets are updated, it's not advisable to rely on this property.
This probably means, that before the most popular shipsets are updated, it's not advisable to rely on this property.
Re: Scripters cove
Well, that and we're never going to be in a position where every miscellaneous ship OXP has it set even if they should. Before 1.77 every NPC ship had a value of 15 (and the property was implicit). Now almost every ship still has a value of 15, but some of them don't. It's one of those things that will gradually get better over time, but it's still at least slightly useful now.spara wrote:This probably means, that before the most popular shipsets are updated, it's not advisable to rely on this property.
- Rorschachhamster
- ---- E L I T E ----
- Posts: 274
- Joined: Sun Aug 05, 2012 11:46 pm
- Contact:
Re: Scripters cove
Quick AI script question:
Does "setTargetToRandomStation" choose the main station as well?
Because I never encountered it in my tests, and that were many tests...
EDIT: ...and, connected to the first question can I use "rollD: 10" and then only let something happen if a 1 is rolled and ignore other results? I would think so...
Does "setTargetToRandomStation" choose the main station as well?
Because I never encountered it in my tests, and that were many tests...
EDIT: ...and, connected to the first question can I use "rollD: 10" and then only let something happen if a 1 is rolled and ignore other results? I would think so...
Re: Scripters cove
Only if there are no other non-carrier dockables in the system, which is generally rare.Rorschachhamster wrote:Does "setTargetToRandomStation" choose the main station as well?
Yes, certainly. TheRorschachhamster wrote:EDIT: ...and, connected to the first question can I use "rollD: 10" and then only let something happen if a 1 is rolled and ignore other results? I would think so...
rollD
command just generates a particular AI event, and as with other AI events you're under no obligation to respond.