Page 109 of 115

Re: Scripters cove

Posted: Mon Jul 25, 2022 4:56 am
by Switeck
phkb wrote: Sun Jul 24, 2022 11:13 pm
I needed a version of an Anaconda that didn't have any escorts assigned, as I would be adding escorts manually via code.
I had a similar problem years ago with wanting to assign a navigational beacon only to 1 version of a station. If the 2nd station used a:

Code: Select all

like_ship="1st station";
...it would pick up that beacon property which I didn't want it to have.
And I'm not sure that setting:

Code: Select all

beacon= null;
on the 2nd station's shipdata.plist would work without problems.

This shows the importance of using templates with almost all properties turned off.

Re: Scripters cove

Posted: Tue Aug 02, 2022 9:11 pm
by Slartibartfast
hello

again a simple question.

I would like to clean my cargo ( set everything to zero )

in https://wiki.alioth.net/index.php/Oolit ... :_Manifest
i found this

Code: Select all

var i, c;

// now remove at least 1 of / 20% of each type of cargo carried.
for (i = 0; i < manifest.list.length; i++)
{
	c = manifest.list[i].commodity;
	manifest[c] = Math.floor(manifest[c] * 0.8);
}
so i changed the last assignment to ... = 0; // 0.0 also tried
and added a log below that line, that shows the freight
--> from the 8 commodities i have, only 4 are listed
then commented out the assignment
--> all commodities are shown.

what am i doing wrong? :(

matthias

Re: Scripters cove

Posted: Tue Aug 02, 2022 10:48 pm
by phkb
Slartibartfast wrote: Tue Aug 02, 2022 9:11 pm
so i changed the last assignment to ... = 0; // 0.0 also tried
and added a log below that line, that shows the freight
--> from the 8 commodities i have, only 4 are listed
then commented out the assignment
--> all commodities are shown.

what am i doing wrong? :(

matthias
The problem is that, by zeroing out a commodity inside the loop, the bounds of the loop are being changed because the "list" property of the manifest object is getting smaller each time.

For example, if the array initially looks like this:

Code: Select all

Index   Value
0       5  x Food
1       10 x Computers
2       3 x Luxuries
3       50 x Gold
If you zero out the commodity at index 0, the array will then look like this:

Code: Select all

Index   Value
0       10 x Computers
1       3 x Luxuries
2       50 x Gold
But your loop moves on to the next index (ie index 1), which skips the computers and goes to the luxuries instead.

Try this instead:

Code: Select all

var i, c;
for (i = manifest.list.length - 1; i >= 0; i--) {
	c = manifest.list[i].commodity;
	manifest[c] = 0
}
By going in reverse order through the array, you can avoid the problem.

Alternatively, you could do this:

Code: Select all

var c;
if (manifest.list.length > 0) {
	do {
		c = manifest.list[0].commodity;
		manifest[c] = 0;
	} while (manifest.list.length > 0);
}

Re: Scripters cove

Posted: Tue Aug 02, 2022 11:46 pm
by Slartibartfast
Ahhhhh!!!

i think i understand

therefore something like this should work also!?

1. ) transfer item_names into an array // ( 1st loop )
2,) for ( item_name in array ) // ( 2nd loop )
- set item_name number to zero

correct?

( ok - not so nice as your solutions - but helps to understand )


cheers

Re: Scripters cove

Posted: Wed Aug 03, 2022 12:55 am
by Slartibartfast
Hi

i have tested this (extended) version: ( later i'll take yours )

Code: Select all

	var fracht;

		var zaehler = manifest.list.length;
		log(this.name, " manifestlength: " + zaehler);

		const item_name_array = [];

		for (let i = 0; i < zaehler; i++)
		{
			item_name_array[i] = manifest.list[i].commodity;
			log(this.name, " test: " + item_name_array[i] + " " + i);
		}

		for (let j = 0; j < zaehler; j++)
		{
			fracht = item_name_array[j];
			manifest[fracht] = 0;
			log(this.name, " test2: " + fracht + " " + j);
		}
		log(this.name, " new manifestlength: " + manifest.list.length);
and i got the following output (log):

Code: Select all

02:33:50.271 [oolite_oxp_slartitest]:  manifestlength: 8
02:33:50.271 [oolite_oxp_slartitest]:  test: radioactives 0
02:33:50.272 [oolite_oxp_slartitest]:  test: luxuries 1
02:33:50.272 [oolite_oxp_slartitest]:  test: computers 2
02:33:50.272 [oolite_oxp_slartitest]:  test: machinery 3
02:33:50.273 [oolite_oxp_slartitest]:  test: alloys 4
02:33:50.273 [oolite_oxp_slartitest]:  test: gold 5
02:33:50.274 [oolite_oxp_slartitest]:  test: quirium_crystal 6
02:33:50.274 [oolite_oxp_slartitest]:  test: alien_items 7
02:33:50.274 [oolite_oxp_slartitest]:  test2: radioactives 0
02:33:50.275 [oolite_oxp_slartitest]:  test2: luxuries 1
02:33:50.275 [oolite_oxp_slartitest]:  test2: computers 2
02:33:50.275 [oolite_oxp_slartitest]:  test2: machinery 3
02:33:50.275 [oolite_oxp_slartitest]:  test2: alloys 4
02:33:50.276 [oolite_oxp_slartitest]:  test2: gold 5
02:33:50.276 [oolite_oxp_slartitest]:  test2: quirium_crystal 6
02:33:50.276 [oolite_oxp_slartitest]:  test2: alien_items 7
02:33:50.276 [oolite_oxp_slartitest]:  new manifestlength: 0
thx for your assistance ;-)

matthias

Re: Scripters cove

Posted: Wed Aug 03, 2022 1:50 am
by phkb
Slartibartfast wrote: Tue Aug 02, 2022 11:46 pm
1. ) transfer item_names into an array // ( 1st loop )
2,) for ( item_name in array ) // ( 2nd loop )
- set item_name number to zero

correct?
Yes, that would achieve the same result, as the list you're looping through when zeroing commodities won't change mid loop.

Re: Scripters cove

Posted: Thu Aug 25, 2022 3:12 am
by Massively Locked
I'm reading thru some scripts and I see this:

Code: Select all

this.startUpComplete = function(){
	delete this.startUpComplete;
Can someone explain to me what the point of this is? Why would you immediately delete the event handler on creating it? Why doesn't this affect all the following statements in the function block?

Re: Scripters cove

Posted: Thu Aug 25, 2022 4:27 am
by phkb
Massively Locked wrote: Thu Aug 25, 2022 3:12 am
Can someone explain to me what the point of this is? Why would you immediately delete the event handler on creating it? Why doesn't this affect all the following statements in the function block?
It's largely about sequencing. startUpComplete will only run once per session (ie when a new game starts, or a saved game loads). Sometimes, it's important for one OXP to know if another OXP has executed already. By deleting the startUpComplete function, it signals to any other OXP's who might want to know that it's start up functions have completed.

It might also be important for some system instantiation processes in the same OXP to know if the startUpComplete function has been completed.

So, basically, it's a way to flag that the step is complete.

Re: Scripters cove

Posted: Fri Aug 26, 2022 3:32 am
by Massively Locked
Thanks for the explanation. While I don't think I'll need it for anything I'm writing, it's still a good thing to have in one's toolbox.

Re: Scripters cove

Posted: Fri Sep 30, 2022 4:29 pm
by Massively Locked
I just started playing with equipment and condition scripts. Out of convenience (or maybe it's laziness), I wrote the elements of these two right in my main script. It's working just fine as far as I can tell. Is it OK to do this (keep everything in one file) or is it considered a bad practice?

Re: Scripters cove

Posted: Sun Oct 02, 2022 2:54 am
by montana05
Massively Locked wrote: Fri Sep 30, 2022 4:29 pm
I just started playing with equipment and condition scripts. Out of convenience (or maybe it's laziness), I wrote the elements of these two right in my main script. It's working just fine as far as I can tell. Is it OK to do this (keep everything in one file) or is it considered a bad practice?
Personally, I would call it a bad practice. :roll: Condition scripts should be separate for some reasons, one would be easier maintenance in the future.

Re: Scripters cove

Posted: Sun Oct 23, 2022 7:17 am
by Cholmondely
Help!

Adding a shiplibrary plist for Idkman's Wavefront.

I can't get anything to appear in the Ship Library. The ship does seem to load and the laser appears for sale on the F3 screen.

My shiplibrary.plist is

Code: Select all

	{
	class = "ship";
	description = "An advanced fighter. Armed with a powerful ablation laser";
	ship = "Farmca Corporation Wavefront MKI multirole fighter"; // I've also tried "wavefront" & "oolite_template_wavefront"
	summary = "[oolite-ship-library-summary-MM]"; 
	}
Idkman's shipdata.plist (adumbrated by Montana) is

Code: Select all

	{
	"oolite_template_wavefront" = {
		aft_eject_position = "0.0 10.5 -22.0";
		ai_type = "oolite-policeAI.js";
		auto_ai = yes;
		accuracy = 8;
		auto_weapons = no;
		cargo_type = "CARGO_NOT_CARGO";
		custom_views =
		(
			{
				view_description = "Rear View";
				view_orientation = "1.0 0.0 0.0 0.0";
				view_position = "0.0 20.0 -150.0";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Rear Right View";
				view_orientation = "0.9239 0.0 0.3827 0.0";
				view_position = "106.06 20.0 -106.06";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Right View";
				view_orientation = "0.7071 0.0 0.7071 0.0";
				view_position = "150.0 20.0 0.0";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Front Right View";
				view_orientation = "0.3827 0.0 0.9239 0.0";
				view_position = "106.06 20.0 106.06";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Front View";
				view_orientation = "0.0 0.0 1.0 0.0";
				view_position = "0.0 20.0 150.0";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Front Left View";
				view_orientation = "0.3827 0.0 -0.9239 0.0";
				view_position = "-106.06 20.0 106.06";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Left View";
				view_orientation = "0.7071 0.0 -0.7071 0.0";
				view_position = "-150.0 20.0 0.0";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Rear Left View";
				view_orientation = "0.9239 0.0 -0.3827 0.0";
				view_position = "-106.06 20.0 -106.06";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Top View";
				view_orientation = "-0.7071 0.7071 0.0 0.0";
				view_position = "0.0 150.0 -10.0";
				weapon_facing = "FORWARD";
			},
			{
				view_description = "Bottom View";
				view_orientation = "0.0 0.0 0.7071 0.7071";
				view_position = "0.0 -150.0 -10.0";
				weapon_facing = "FORWARD";
			}
		);
		energy_recharge_rate = 15;
		exhaust = (
					"11.5223 -0.0416 -26.249 4.0 4.0 1.5",
					"0.0 -0.0416 -26.249 4.0 4.0 1.5",
					"-11.5223 -0.0416 -26.249 4.0 4.0 1.5"
				  );
		forward_weapon_type = "WEAPON_ABLATION_LASER";
		aft_weapon_type = "WEAPON_ABLATION_LASER";
		cloak_automatic = yes;
		cloak_passive = yes;
		exhaust_emissive_color = "1 0 0"; // added in " "
		fuel = 250;
		has_cloaking_device = yes;
		has_military_scanner_filter = yes;
		hyperspace_motor_spin_time = 5;
		injector_burn_rate = 0.1;
		injector_speed_factor = 10;
		has_shield_enhancer = yes;
		has_ecm = yes;
		has_fuel_injection = yes;
		has_scoop = yes;
		scanner_range = 40000;
		has_military_jammer = yes;
		has_shield_booster = yes;
		heat_insulation = "4.0";
		is_template = 1;
		has_escape_pod = yes;
		likely_cargo = 0;
		materials = 
		{ 
			"Hull" = 
			{
				diffuse_map = "oolite_viper_interceptor_diffuse.png"; 
				gloss = 0.55;
				specular_color = (0.5, 0.5, 0.5);
				shininess = 55; 
				emission_map = 
				{
					name = "oolite_viper_interceptor_diffuse.png"; extract_channel = "a";
				}; 
				emission_modulate_color = (0.9926, 0.9686, 0.7325, 1.0); 				
			};
			"Engine" = 
			{ 
				diffuse_map = "oolite_viper_interceptor_diffuse.png"; 
				gloss = 0.55;
				specular_color = ( 0.5, 0.5, 0.5 );
				shininess = 55; 
				emission_map = 
				{
					name = "oolite_viper_interceptor_diffuse.png"; extract_channel = "a";
				}; 
				emission_modulate_color = (0.7325, 0.9686, 0.9926, 1.0); 
			};			
		};
		max_cargo = 40;
		extra_cargo = 20;
		sun_glare_filter = 0.8;
		max_energy = 500;
		max_flight_pitch = 2.7;
		max_flight_yaw = 2.7;
		max_flight_roll = 4.5;
		max_flight_speed = 850;
		max_missiles = 3;
		missile_launch_position = "0.0 -10.5 -9.0";
		missiles = 3;
		model = "oolite_viper_interceptor.dat";
		name = "Farmca Corporation Wavefront MKI multirole fighter";
		roles = "hunter-heavy(2.0) escort-heavy(1.25) assassin-heavy(2.0)";
		scoop_position = "0.0 -6 18.5";
		thrust = 80;
		view_position_aft = "0.0 1.85 -32.0";
		view_position_forward = "0.0 1.85 35.2";
		view_position_port = "-23.75 2.2 -1.75";
		view_position_starboard = "23.75 2.2 -1.75";
		weapon_facings = 3;
		weapon_position_aft = "0.0 -8.0 -32.0";
		weapon_position_forward = "0.0 -0.15 35.034";	
		weapon_position_port = "-23.75 0.0 -1.75";
		weapon_position_starboard = "23.75 0.0 -1.75";
	};
	"oolite_template_wavefront-player" = 
	{
		like_ship = "oolite_template_wavefront";
		forward_weapon_type = "WEAPON_ABLATION_LASER";
		is_template = 1;
		roles = "player";
	};
	"wavefront" =
	{
		like_ship = "oolite_template_wavefront";
	};
	"wavefront-player" =
	{
		like_ship = "oolite_template_wavefront-player";
	};
}
What am I doing wrong? My .plist syntax checker says that everything is fine...

Re: Scripters cove

Posted: Sun Oct 23, 2022 7:43 am
by Alnivel
Cholmondely wrote: Sun Oct 23, 2022 7:17 am
Help!

Adding a shiplibrary plist for Idkman's Wavefront.

I can't get anything to appear in the Ship Library. The ship does seem to load and the laser appears for sale on the F3 screen.

My shiplibrary.plist is

Code: Select all

	{
	class = "ship";
	description = "An advanced fighter. Armed with a powerful ablation laser";
	ship = "Farmca Corporation Wavefront MKI multirole fighter"; // I've also tried "wavefront" & "oolite_template_wavefront"
	summary = "[oolite-ship-library-summary-MM]"; 
	}
Is it the whole shiplibrary.plist or just a fragment from it? If the first, then all these entries must be between a pair of parentheses:

Code: Select all

(
	{
		class = "ship";
		description = "An advanced fighter. Armed with a powerful ablation laser";
		ship = "wavefront"; // there must be a key from shipdata
		summary = "[oolite-ship-library-summary-MM]"; 
	}
)

Re: Scripters cove

Posted: Sun Oct 23, 2022 7:59 am
by Cholmondely
Alnivel wrote: Sun Oct 23, 2022 7:43 am
Cholmondely wrote: Sun Oct 23, 2022 7:17 am
Help!

Adding a shiplibrary plist for Idkman's Wavefront.

I can't get anything to appear in the Ship Library. The ship does seem to load and the laser appears for sale on the F3 screen.

My shiplibrary.plist is

Code: Select all

	{
	class = "ship";
	description = "An advanced fighter. Armed with a powerful ablation laser";
	ship = "Farmca Corporation Wavefront MKI multirole fighter"; // I've also tried "wavefront" & "oolite_template_wavefront"
	summary = "[oolite-ship-library-summary-MM]"; 
	}
Is it the whole shiplibrary.plist or just a fragment from it? If the first, then all these entries must be between a pair of parentheses:

Code: Select all

(
	{
		class = "ship";
		description = "An advanced fighter. Armed with a powerful ablation laser";
		ship = "wavefront"; // there must be a key from shipdata
		summary = "[oolite-ship-library-summary-MM]"; 
	}
)
The whole thing!

I just tried

Code: Select all

(
	{
	class = "ship";
	description = "An advanced fighter. Armed with a powerful ablation laser";
	ship = "oolite_template_wavefront"; // this seems to me the most likely of the available options
	summary = "[oolite-ship-library-summary-MM]"; 
	}
)
Still no go! And I checked for invisible codes too...

Re: Scripters cove

Posted: Sun Oct 23, 2022 8:21 am
by Alnivel
Cholmondely wrote: Sun Oct 23, 2022 7:59 am
I just tried

Code: Select all

(
	{
	class = "ship";
	description = "An advanced fighter. Armed with a powerful ablation laser";
	ship = "oolite_template_wavefront"; // this seems to me the most likely of the available options
	summary = "[oolite-ship-library-summary-MM]"; 
	}
)
Have you tried with a non-template ship too? I just checked it myself - entry with "wavefront" is displayed, with template - no.
If this stilll does not work, maybe something useful is in the logs?