Scripters cove

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

Moderators: winston, another_commander

User avatar
Mauiby de Fug
---- E L I T E ----
---- E L I T E ----
Posts: 824
Joined: Tue Sep 07, 2010 2:23 pm

Re: Scripters cove

Post by Mauiby de Fug » Sun Feb 11, 2018 4:04 pm

Fantastic Spara! I hadn't noticed the static methods on the wiki page - don't know if I'm blind or just hadn't scrolled down far enough. With a bit of thought, it should should be able to write a script to log all the various roles for the oxp ships, and then regex that into a format that can be dropped into a spreadsheet. Then there should be something like the core list table I linked to earlier, and then I will be able to make an informed decision on what to alter.

All without the hassle of unzipping each oxp and manually looking through the plists!

I believe that this will only work with the roles used by the populator. Ships often had their own unique role for use in missions and such, and added by scripts, would still appear with the same frequency regardless of any tinkering (unless I delve in to all oxps to check spawning scripts, but that seems like even more work than I can be bothered with at this moment in time.)

And once I do know what I want to alter, it might be that Redspear's find and replace trick would be a quick and easy hack, depending on the outcome of the various lists.

I knew it was worth asking here before starting a long and tedious process!

The next stage once I'm happy with all the ships would be to look at the stations. The problem with a perfectionist nature is that I want everything to be set up before I start playing the game, and the problem with real life is that it takes up time. I suspect I'll actually start my new commander at some point in the spring/summer. In the meantime I'll have to be content with the dark side of editing and tweaking...

User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2550
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara » Sun Feb 11, 2018 4:11 pm

Mauiby de Fug wrote:
Sun Feb 11, 2018 4:04 pm
...The problem with a perfectionist nature is that I want everything to be set up before I start playing the game...
And then a new version of the game pops up or some oxp gets updated so that the game just isn't the same that it was when you started your game. And you just have to start over again. Luckily I kind of like the early game build phase, since the farthest I have ever got with Oolite is the second chart.... :lol:

User avatar
Mauiby de Fug
---- E L I T E ----
---- E L I T E ----
Posts: 824
Joined: Tue Sep 07, 2010 2:23 pm

Re: Scripters cove

Post by Mauiby de Fug » Fri Mar 02, 2018 3:44 pm

Well, I'm starting simply in my task of selection and am just focusing on inserting the various complete shipsets and making sure that they all work nicely together.

What I have noticed is that some of these have their own buoys defined. Is there an obvious way to ensure that the main buoys used in a system are used from the same shipset as the main station? Or am I going to need to write a script to check and replace these myself?

User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 260
Joined: Mon May 30, 2016 3:54 am

Re: Scripters cove

Post by montana05 » Thu Jul 12, 2018 11:53 am

Naive question of mine, if I compare an AI to a ship script, which commands will overwrite the other ? My ship script is slowly becoming an hybrid of both. :lol:
Trying to survive behind the controls of a Caduceus Psi XT in Alpha test :lol:

User avatar
phkb
Commodore
Commodore
Posts: 2372
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Thu Jul 12, 2018 2:11 pm

Well, an AI and a ship script are essentially two different things. At a general level, ship script handles events that occur to the ship, and an AI deals with responses to stimuli (which can be caused by events, or from other things). Obviously that's a generalisation. I would imagine a complex AI routine could end up harnessing both scripts quite extensively (ie an event triggers an AI response, and so forth).

As for which overrides which, they shouldn't override each other at all, as they have different trigger points and default function names. You can have an AI script and a ship script attached to the same ship, and they won't necessarily conflict with each other. That being said, without seeing your code, or discussing a particular example, I may be talking nonsense here, but from what I understand, there shouldn't be any inherent conflict between the two.

User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 260
Joined: Mon May 30, 2016 3:54 am

Re: Scripters cove

Post by montana05 » Thu Jul 12, 2018 2:47 pm

Thank you phkb, you helped me a little in my confusion.
However, AI and scrips using actually sometimes the same events, as you know yourself you can write an entire AI in js. So if an AI and a scrip got different approaches to, for example, "this ship get attacked", what comes first ? Simple example a js "this.ship.target = attacker" overwrites any "this.ship.reactToAIMessage("TARGET_LOST");" up to a level that even a derelict ship still attacks. You need to set "this.ship.target = null" before finally the target is lost. Currently my entire script is full of debugs, 15 min playing and 1h following up with the log. Its interesting what results you could get out of that.

Well, I guessed I just answered my own question, seems script overwrites AI, at least in this case. :oops:
Trying to survive behind the controls of a Caduceus Psi XT in Alpha test :lol:

User avatar
phkb
Commodore
Commodore
Posts: 2372
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Thu Jul 12, 2018 2:59 pm

If it came down to orders, I would (as you have noted yourself) put the ship script JS interactions after the AI ones. But without deep-diving into the code, I wouldn't be able to say that is always going to be the answer in every case. But it's a reasonable rule-of-thumb to go on with.

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

Re: Scripters cove

Post by Phasted » Wed Jul 18, 2018 9:28 pm

It used to be possible to define arbitrary properties on the SystemInfo object and have them saved in the planetinfo_overrides section of the saved game file... is this no longer the case?

I can still define properties on SystemInfo, but they aren't being saved... :?

User avatar
phkb
Commodore
Commodore
Posts: 2372
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Wed Jul 18, 2018 10:01 pm

Phasted wrote: It used to be possible to define arbitrary properties on the SystemInfo object and have them saved in the planetinfo_overrides section of the saved game file
You can update most of the defined properties of a system (eg population or productivity), and these will be saved automatically, but arbitrary ones...hmm not sure about that one.

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

Re: Scripters cove

Post by Phasted » Thu Jul 26, 2018 10:01 pm

Phasted wrote:
Wed Jul 18, 2018 9:28 pm
It used to be possible to define arbitrary properties on the SystemInfo object and have them saved in the planetinfo_overrides section of the saved game file... is this no longer the case?

I can still define properties on SystemInfo, but they aren't being saved... :?
I cannot figure out what's wrong here...

Absolutely nothing is being saved from the SystemInfos.

Here's a test function I used:

Code: Select all

if(!oxp) {var oxp = {};}
oxp.RLE = this;
oxp.iFS = System.infoForSystem;

this.startUp = function() {this._RLE_event_newGameSession();}

this._RLE_event_newGameSession = function()
{
	var gN = galaxyNumber, si;
	function modifySystemInfo(si)
	{
		log(oxp.RLE.name, "mSI called okay..." + "system: " + si.name + "; si.economy:  " + si.economy + "; si.government:  " + si.government);
		system.info.arbitraryProperty = !!1;
		var M = Math, chance = M.random(), c = "ceil", f = "floor", g = "government", t = "techlevel";
		si.locked = !!1;
		si.setProperty("locked", "true", 3);
		switch(si.economy)
		{
			case 0:	//	RI
			case 5:	//	RA
			{
				if(chance < .4) 			{si[g] = 7;}	//	Corporate State
				else if(chance < .75) 		{si[g] = 6;}	//	Democracy
				else 					{si[g] = 5;}	//	Confederacy
				break;
			}
			case 1:	//	AI
			case 6:	//	AA
			{
				if(chance < .15) 			{si[g] = 5;}	//	Confederacy
				else if(chance < .5) 		{si[g] = 4;}	//	Dictatorship
				else if(chance < .85)		{si[g] = 3;}	//	Communist
				else					{si[g] = 2;}	//	Multi_government
				break;
			}
			case 2:	//	PI
			case 7:	//	PA
			{
				if(chance < .4)			{si[g] = 0;}	//	Anarchy
				else if(chance < .75)		{si[g] = 1;}	//	Feudal
				else					{si[g] = 2;}	//	Multi_government
				break;
			}
			case 3:	//	MI
			case 4:	//	MA
			{
				if(chance < .05)			{si[g] = 6;}	//	Democracy
				else if(chance < .25)		{si[g] = 5;}	//	Confederacy
				else if(chance < .5)		{si[g] = 4;}	//	Dictatorship
				else if(chance < .75)		{si[g] = 3;}	//	Communist
				else if(chance < .95)		{si[g] = 2;}	//	Multi_government
				else									{si[g] = 1;}	//	Feudal
			}
		}
		switch(si[g])
		{
			case 0: {si[t] = M[f](M.random() * 4) + 0; break;}	//	Anarchy
			case 1: {si[t] = M[f](M.random() * 4) + 1; break;}	//	Feudal
			case 2: {si[t] = M[f](M.random() * 4) + 2; break;}	//	Multi_government
			case 3: {si[t] = M[f](M.random() * 7) + 3; break;}	//	Communist
			case 4: {si[t] = M[f](M.random() * 7) + 5; break;}	//	Dictatorship
			case 5: {si[t] = M[f](M.random() * 4) + 9; break;}	//	Confederacy
			case 6: {si[t] = M[f](M.random() * 4) + 10; break;}	//	Democracy
			case 7: {si[t] = M[f](M.random() * 4) + 11;}				//	Corporate State
		}
		log(oxp.RLE.name, "mSI finished..." + "si.locked:  " + si.locked + "; si.government:  " + si.government);
		log(oxp.RLE.name, "si.locked:  " + oxp.iFS(si.galaxyID, si.systemID).locked + "; si.government:  " + oxp.iFS(si.galaxyID, si.systemID).government);
		log(oxp.RLE.name, "* * * system.info.arbitraryProperty:  " + oxp.iFS(si.galaxyID, si.systemID).arbitraryProperty);
	}
	for(let i = 0; i < 256; i++)
	{
		si = oxp.iFS(gN, i);
		if(!si.locked) {modifySystemInfo(si);}	//	fixing up all the systems in the present galaxy...
		else {return;}
	}
}

The thing sort of half works... it makes changes to system/systemInfo gov and TL as you would expect...

Code: Select all

[from the log...]
00:56:54.202 [RealLifeEconomics]: mSI called okay...system: Lave; si.economy:  5; si.government:  3
00:56:54.805 [RealLifeEconomics]: mSI finished...si.locked:  true; si.government:  7
00:56:54.805 [RealLifeEconomics]: si.locked:  true; si.government:  7
00:56:54.805 [RealLifeEconomics]: * * * system.info.arbitraryProperty:  true

...but when I save and check the save-file, what I get is this:

Code: Select all

    <key>scripted_planetinfo_overrides</key>
    <dict>
    </dict>

Nothing... :? The modified SystemInfo.government and SystemInfo.techlevel should be saved, even if nothing else is...

I'm stumped...

another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 5394
Joined: Wed Feb 28, 2007 7:54 am

Re: Scripters cove

Post by another_commander » Fri Jul 27, 2018 6:16 am

Is there a Latest.log we can look at?

FYI, I copypasted your script inside a script.js file and it would not work out of the box. Using latest trunk, I had to change the line reading si.setProperty("locked", true, 3); to si.setProperty(0, "locked", true, 3); and the line reading system.info.arbitraryProperty = !!1; to si.arbitraryProperty = !!1; to make it produce the output you show. Following that, I saved the game right after running it and I can see in the savefile

Code: Select all

<key>scripted_planetinfo_overrides</key>
    <dict>
	<key>3~|~0 0~|~locked~|~0</key>
	<integer>1</integer>
	<key>3~|~0 100~|~locked~|~0</key>
	<integer>1</integer>
	<key>3~|~0 101~|~locked~|~0</key>
	<integer>1</integer>
	<key>3~|~0 102~|~locked~|~0</key>
	<integer>1</integer>
	<key>3~|~0 103~|~locked~|~0</key> 
	.
	.
	.
	[snip]

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

Re: Scripters cove

Post by Phasted » Tue Jul 31, 2018 7:39 am

another_commander wrote:
Fri Jul 27, 2018 6:16 am
Is there a Latest.log we can look at?

Code: Select all

Opening log for Oolite version 1.86 (x86-64) under Windows 6.2.9200  64-bit at 2018-07-31 02:15:03 -0500.
8 processors detected.
Build options: OpenAL, new planets.

Note that the contents of the log file can be adjusted by editing logcontrol.plist.

02:15:03.747 [display.mode.list.native]: Windows native resolution detected: 1366 x 768
02:15:03.949 [joystick.init]: Number of joysticks detected: 1
02:15:03.950 [rendering.opengl.version]: OpenGL renderer version: 4.0.0 ("4.0.0 - Build 10.18.10.4358"). Vendor: "Intel". Renderer: "Intel(R) HD Graphics 4000".
02:15:03.950 [rendering.opengl.extensions]: OpenGL extensions (169):
GL_ARB_framebuffer_sRGB, GL_ARB_transform_feedback_instanced, GL_ARB_depth_texture, GL_ARB_texture_env_add, GL_ARB_internalformat_query2, GL_ARB_draw_instanced, GL_ARB_half_float_vertex, GL_ARB_buffer_storage, GL_EXT_texture3D, GL_EXT_compiled_vertex_array, GL_ARB_gpu_shader_fp64, GL_EXT_texture_shared_exponent, GL_ARB_framebuffer_object, GL_EXT_separate_specular_color, GL_EXT_shadow_funcs, GL_ARB_gpu_shader5, GL_EXT_rescale_normal, GL_ARB_texture_rgb10_a2ui, GL_ARB_transpose_matrix, GL_ARB_texture_cube_map_array, GL_ARB_texture_compression_rgtc, GL_ARB_multisample, GL_ARB_half_float_pixel, GL_EXT_stencil_two_side, GL_ARB_texture_border_clamp, GL_ARB_texture_non_power_of_two, GL_ATI_separate_stencil, GL_ARB_shading_language_packing, GL_EXT_bgra, GL_ARB_texture_storage_multisample, GL_ARB_sync, GL_ARB_compatibility, GL_ARB_sampler_objects, GL_SUN_multi_draw_arrays, GL_EXT_clip_volume_hint, GL_ARB_map_buffer_range, GL_ARB_vertex_shader, GL_ARB_shader_objects, GL_NV_texgen_reflection, GL_EXT_multi_draw_arrays, GL_ARB_vertex_program, GL_ARB_get_program_binary, GL_ARB_base_instance, GL_INTEL_performance_queries, GL_ARB_texture_float, GL_ARB_draw_buffers_blend, GL_ARB_texture_compression_bptc, GL_ARB_fragment_coord_conventions, GL_EXT_stencil_wrap, GL_EXT_texture_swizzle, GL_ARB_shader_precision, GL_ARB_uniform_buffer_object, GL_NV_primitive_restart, GL_EXT_framebuffer_blit, GL_ARB_vertex_array_bgra, GL_ARB_texture_gather, GL_ARB_texture_compression, GL_KHR_debug, GL_ARB_vertex_array_object, GL_EXT_blend_color, GL_ARB_texture_query_lod, GL_EXT_blend_minmax, GL_EXT_texture_integer, GL_ARB_texture_swizzle, GL_EXT_gpu_shader4, GL_ARB_sample_shading, GL_ARB_shader_bit_encoding, GL_EXT_transform_feedback, GL_EXT_texture_compression_s3tc, GL_ARB_tessellation_shader, GL_ARB_occlusion_query2, GL_ARB_ES3_compatibility, GL_ARB_debug_output, GL_ARB_timer_query, GL_ARB_depth_clamp, GL_ARB_point_sprite, GL_ARB_framebuffer_no_attachments, GL_EXT_abgr, GL_ARB_vertex_buffer_object, GL_NV_blend_square, GL_ARB_vertex_attrib_binding, GL_ARB_instanced_arrays, GL_EXT_framebuffer_multisample, GL_NV_conditional_render, GL_ARB_multitexture, GL_ARB_seamless_cube_map, GL_ARB_copy_buffer, GL_EXT_texture_storage, GL_ARB_draw_elements_base_vertex, GL_ARB_geometry_shader4, GL_ARB_transform_feedback2, GL_ARB_multi_draw_indirect, GL_ARB_transform_feedback3, GL_ARB_viewport_array, GL_ARB_shadow, GL_EXT_blend_subtract, GL_ARB_fragment_program_shadow, GL_ARB_internalformat_query, GL_ARB_texture_storage, GL_ARB_window_pos, GL_ARB_texture_multisample, GL_EXT_texture_lod_bias, GL_IBM_texture_mirrored_repeat, GL_ARB_stencil_texturing, GL_EXT_texture_snorm, GL_ARB_texture_env_crossbar, GL_ARB_point_parameters, GL_ARB_depth_buffer_float, GL_EXT_texture_sRGB_decode, GL_ARB_shading_language_420pack, GL_ARB_vertex_type_2_10_10_10_rev, GL_ARB_robustness, GL_ARB_texture_rg, GL_EXT_texture_edge_clamp, GL_EXT_texture_sRGB, GL_KHR_blend_equation_advanced, GL_ARB_texture_env_combine, GL_WIN_swap_hint, GL_ARB_fragment_program, GL_ARB_explicit_attrib_location, GL_EXT_packed_float, GL_ARB_texture_buffer_object_rgb32, GL_EXT_texture_filter_anisotropic, GL_EXT_draw_range_elements, GL_ARB_pixel_buffer_object, GL_ARB_shader_subroutine, GL_ARB_draw_indirect, GL_EXT_packed_depth_stencil, GL_ARB_texture_rectangle, GL_ARB_separate_shader_objects, GL_EXT_geometry_shader4, GL_EXT_fog_coord, GL_ARB_ES2_compatibility, GL_SGIS_texture_lod, GL_ARB_texture_buffer_range, GL_3DFX_texture_compression_FXT1, GL_EXT_gpu_program_parameters, GL_ARB_fragment_shader, GL_ARB_shader_atomic_counters, GL_ARB_shading_language_100, GL_EXT_secondary_color, GL_ARB_draw_buffers, GL_SGIS_generate_mipmap, GL_EXT_draw_buffers2, GL_EXT_texture_rectangle, GL_ARB_program_interface_query, GL_ARB_blend_func_extended, GL_ARB_arrays_of_arrays, GL_EXT_blend_func_separate, GL_ARB_texture_cube_map, GL_EXT_texture_array, GL_ARB_occlusion_query, GL_INTEL_map_texture, GL_ARB_compressed_texture_pixel_storage, GL_ARB_vertex_attrib_64bit, GL_EXT_framebuffer_object, GL_EXT_packed_pixels, GL_ARB_texture_env_dot3, GL_ARB_map_buffer_alignment, GL_ARB_provoking_vertex, GL_EXT_shader_integer_mix, GL_EXT_blend_equation_separate, GL_INTEL_performance_query, GL_ARB_color_buffer_float, GL_EXT_texture_env_add, GL_EXT_texture_buffer, GL_EXT_texture_env_combine, GL_SGIS_texture_edge_clamp, GL_ARB_conservative_depth
02:15:03.966 [rendering.opengl.shader.support]: Shaders are supported.
02:15:03.990 [searchPaths.dumpAll]: Resource paths: 
    Resources
    ../AddOns
    ../AddOns/test.oxp
02:15:04.738 [shipData.load.begin]: Loading ship data.
02:15:05.597 [startup.complete]: ========== Loading complete in 2.14 seconds. ==========
02:15:15.409 [shipData.load.begin]: Loading ship data.
02:15:16.568 [script.load.world.listAll]: Loaded 17 world scripts:
    Oolite Equipment Control 1.86
    Oolite Ship Library 1.86
    oolite-cloaking-device 1.86
    oolite-constrictor-hunt 1.86
    oolite-contracts-cargo 1.86
    oolite-contracts-helpers 1.86
    oolite-contracts-parcels 1.86
    oolite-contracts-passengers 1.86
    oolite-libPriorityAI 1.86
    oolite-nova 1.86
    oolite-populator 1.86
    oolite-primable-equipment-register 1.86
    oolite-registership 1.86
    oolite-thargoid-plans 1.86
    oolite-trumbles 1.86
    oolite-tutorial 1.86
    RealLifeEconomics 3.0.01
02:15:16.853 [RealLifeEconomics]: mSI called okay...system: Tibedied; si.economy:  2; si.government:  1
02:15:16.853 [RealLifeEconomics]: mSI finished...si.locked:  true; si.government:  0
02:15:16.854 [RealLifeEconomics]: si.locked:  true; si.government:  0
02:15:16.854 [RealLifeEconomics]: * * * system.info.arbitraryProperty:  undefined
02:15:16.854 [RealLifeEconomics]: mSI called okay...system: Qube; si.economy:  5; si.government:  7
02:15:16.854 [RealLifeEconomics]: mSI finished...si.locked:  true; si.government:  7
02:15:16.854 [RealLifeEconomics]: si.locked:  true; si.government:  7
02:15:16.854 [RealLifeEconomics]: * * * system.info.arbitraryProperty:  undefined
02:15:16.854 [RealLifeEconomics]: mSI called okay...system: Leleer; si.economy:  3; si.government:  3
02:15:16.855 [RealLifeEconomics]: mSI finished...si.locked:  true; si.government:  4
02:15:16.855 [RealLifeEconomics]: si.locked:  true; si.government:  4
02:15:16.855 [RealLifeEconomics]: * * * system.info.arbitraryProperty:  undefined
02:15:16.855 [RealLifeEconomics]: mSI called okay...system: Biarge; si.economy:  0; si.government:  2
02:15:16.855 [RealLifeEconomics]: mSI finished...si.locked:  true; si.government:  6
02:15:16.855 [RealLifeEconomics]: si.locked:  true; si.government:  6
02:15:16.855 [RealLifeEconomics]: * * * system.info.arbitraryProperty:  undefined
02:15:16.855 [RealLifeEconomics]: mSI called okay...system: Xequerin; si.economy:  3; si.government:  4
02:15:16.856 [RealLifeEconomics]: mSI finished...si.locked:  true; si.government:  3
02:15:16.856 [RealLifeEconomics]: si.locked:  true; si.government:  3
02:15:16.856 [RealLifeEconomics]: * * * system.info.arbitraryProperty:  undefined
02:15:16.856 [RealLifeEconomics]: mSI called okay...system: Tiraor; si.economy:  0; si.government:  4
02:15:16.856 [RealLifeEconomics]: mSI finished...si.locked:  true; si.government:  6
02:15:16.856 [RealLifeEconomics]: si.locked:  true; si.government:  6
02:15:16.856 [RealLifeEconomics]: * * * system.info.arbitraryProperty:  undefined
02:15:16.856 [RealLifeEconomics]: mSI called okay...system: Rabedira; si.economy:  1; si.government:  2
02:15:16.856 [RealLifeEconomics]: mSI finished...si.locked:  true; si.government:  2
02:15:16.856 [RealLifeEconomics]: si.locked:  true; si.government:  2
02:15:16.856 [RealLifeEconomics]: * * * system.info.arbitraryProperty:  undefined
02:15:16.857 [RealLifeEconomics]: mSI called okay...system: Lave; si.economy:  5; si.government:  3
02:15:16.857 [RealLifeEconomics]: mSI finished...si.locked:  true; si.government:  6
02:15:16.857 [RealLifeEconomics]: si.locked:  true; si.government:  6
02:15:16.857 [RealLifeEconomics]: * * * system.info.arbitraryProperty:  true
02:15:16.857 [RealLifeEconomics]: mSI called okay...system: Zaatxe; si.economy:  0; si.government:  7
02:15:16.857 [RealLifeEconomics]: mSI finished...si.locked:  true; si.government:  6
02:15:16.857 [RealLifeEconomics]: si.locked:  true; si.government:  6
02:15:16.857 [RealLifeEconomics]: * * * system.info.arbitraryProperty:  undefined
02:15:16.857 [RealLifeEconomics]: mSI called okay...system: Diusreza; si.economy:  2; si.government:  1
02:15:16.857 [RealLifeEconomics]: mSI finished...si.locked:  true; si.government:  0
02:15:16.857 [RealLifeEconomics]: si.locked:  true; si.government:  0
02:15:16.857 [RealLifeEconomics]: * * * system.info.arbitraryProperty:  undefined


	[etc... the log is over 1000 lines, but most of it is just more of this stuff...]


02:28:27.484 [exit.context]: Exiting: Exit Game selected on options screen.
02:28:27.484 [gameController.exitApp]: .GNUstepDefaults synchronized.

Closing log at 2018-07-31 02:28:27 -0500.

another_commander wrote:
Fri Jul 27, 2018 6:16 am
FYI, I copypasted your script inside a script.js file and it would not work out of the box. Using latest trunk, I had to change the line reading si.setProperty("locked", true, 3); to si.setProperty(0, "locked", true, 3); and the line reading system.info.arbitraryProperty = !!1; to si.arbitraryProperty = !!1; to make it produce the output you show. Following that, I saved the game right after running it and I can see in the savefile

Code: Select all

<key>scripted_planetinfo_overrides</key>
    <dict>
	<key>3~|~0 0~|~locked~|~0</key>
	<integer>1</integer>
	<key>3~|~0 100~|~locked~|~0</key>
	<integer>1</integer>
	<key>3~|~0 101~|~locked~|~0</key>
	<integer>1</integer>
	<key>3~|~0 102~|~locked~|~0</key>
	<integer>1</integer>
	<key>3~|~0 103~|~locked~|~0</key> 
	.
	.
	.
	[snip]
I'm encouraged to see that the arbitrary properties were saved for you, even though I still can't save anything...

I'm using standard off-the-shelf v1.86...
Could there be a bug...?

another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 5394
Joined: Wed Feb 28, 2007 7:54 am

Re: Scripters cove

Post by another_commander » Tue Jul 31, 2018 8:02 am

Two observations:

1. You will see that in your log, arbitraryProperty is shown as undefined. This would not be saved in a usable form, even if it did get saved, The change of system.info.arbitraryProperty = !!1; to si.arbitraryProperty = !!1 fixes the undefinedness, but it still will not save the variable.

2. If you look at the format of the variables that have been saved in my savefile extract, you will see that only the "locked" property is in. Nothing else. The reason for this is that only "locked" is marked for saving and this is done using the setProperty method. In 1.86 and later, setProperty takes 4 arguments rather than 3 (the syntax is setProperty(layer, property, value [,manifest]). The format of the keys in the save file is <key>[manifest]~|~[galaxy id] [system id]~|~[variable]~|~[layer]</key>. The modified script below saves all required variables in the savefile and should do what you want.

Code: Select all

if(!oxp) {var oxp = {};}
oxp.RLE = this;
oxp.iFS = System.infoForSystem;

this.startUp = function() {this._RLE_event_newGameSession();}

this._RLE_event_newGameSession = function()
{
	var gN = galaxyNumber, si;
	function modifySystemInfo(si)
	{
		log(oxp.RLE.name, "mSI called okay..." + "system: " + si.name + "; si.economy:  " + si.economy + "; si.government:  " + si.government);
		//system.info.arbitraryProperty = !!1;
		si.arbitraryProperty = Math.random();//!!1;
		var M = Math, chance = M.random(), c = "ceil", f = "floor", g = "government", t = "techlevel";
		si.locked = !!1;
		si.setProperty(0, "locked", true, 3);
		switch(si.economy)
		{
			case 0:	//	RI
			case 5:	//	RA
			{
				if(chance < .4) 			{si[g] = 7;}	//	Corporate State
				else if(chance < .75) 		{si[g] = 6;}	//	Democracy
				else 					{si[g] = 5;}	//	Confederacy
				break;
			}
			case 1:	//	AI
			case 6:	//	AA
			{
				if(chance < .15) 			{si[g] = 5;}	//	Confederacy
				else if(chance < .5) 		{si[g] = 4;}	//	Dictatorship
				else if(chance < .85)		{si[g] = 3;}	//	Communist
				else					{si[g] = 2;}	//	Multi_government
				break;
			}
			case 2:	//	PI
			case 7:	//	PA
			{
				if(chance < .4)			{si[g] = 0;}	//	Anarchy
				else if(chance < .75)		{si[g] = 1;}	//	Feudal
				else					{si[g] = 2;}	//	Multi_government
				break;
			}
			case 3:	//	MI
			case 4:	//	MA
			{
				if(chance < .05)			{si[g] = 6;}	//	Democracy
				else if(chance < .25)		{si[g] = 5;}	//	Confederacy
				else if(chance < .5)		{si[g] = 4;}	//	Dictatorship
				else if(chance < .75)		{si[g] = 3;}	//	Communist
				else if(chance < .95)		{si[g] = 2;}	//	Multi_government
				else									{si[g] = 1;}	//	Feudal
			}
		}
		switch(si[g])
		{
			case 0: {si[t] = M[f](M.random() * 4) + 0; break;}	//	Anarchy
			case 1: {si[t] = M[f](M.random() * 4) + 1; break;}	//	Feudal
			case 2: {si[t] = M[f](M.random() * 4) + 2; break;}	//	Multi_government
			case 3: {si[t] = M[f](M.random() * 7) + 3; break;}	//	Communist
			case 4: {si[t] = M[f](M.random() * 7) + 5; break;}	//	Dictatorship
			case 5: {si[t] = M[f](M.random() * 4) + 9; break;}	//	Confederacy
			case 6: {si[t] = M[f](M.random() * 4) + 10; break;}	//	Democracy
			case 7: {si[t] = M[f](M.random() * 4) + 11;}				//	Corporate State
		}
		log(oxp.RLE.name, "mSI finished..." + "si.locked:  " + si.locked + "; si.government:  " + si.government);
		log(oxp.RLE.name, "si.locked:  " + oxp.iFS(si.galaxyID, si.systemID).locked + "; si.government:  " + oxp.iFS(si.galaxyID, si.systemID).government);
		log(oxp.RLE.name, "* * * system.info.arbitraryProperty:  " + oxp.iFS(si.galaxyID, si.systemID).arbitraryProperty);
		si.setProperty(0, "government", si.government, 3);
		si.setProperty(0, "economy", si.economy, 3);
		si.setProperty(0, "techlevel", si.techlevel, 3);
		si.setProperty(0, "arbitraryProperty", si.arbitraryProperty, 3);
	}
	for(let i = 0; i < 256; i++)
	{
		si = oxp.iFS(gN, i);
		if(!si.locked) {modifySystemInfo(si);}	//	fixing up all the systems in the present galaxy...
		else {return;}
	}
}

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

Re: Scripters cove

Post by Phasted » Tue Jul 31, 2018 8:35 am

another_commander wrote:
Tue Jul 31, 2018 8:02 am
Two observations:

1. You will see that in your log, arbitraryProperty is shown as undefined. This would not be saved in a usable form, even if it did get saved, The change of system.info.arbitraryProperty = !!1; to si.arbitraryProperty = !!1 fixes the undefinedness, but it still will not save the variable.

2. If you look at the format of the variables that have been saved in my savefile extract, you will see that only the "locked" property is in. Nothing else. The reason for this is that only "locked" is marked for saving and this is done using the setProperty method. In 1.86 and later, setProperty takes 4 arguments rather than 3 (the syntax is setProperty(layer, property, value [,manifest]). The format of the keys in the save file is <key>[manifest]~|~[galaxy id] [system id]~|~[variable]~|~[layer]</key>. The modified script below saves all required variables in the savefile and should do what you want.
Works like a charm! :D Thank you kindly!

So I guess the documentation for SystemInfo.setProperty() is all wrong... that's what I was going by...

Anyway, thank you again... you have removed a giant roadblock from my path...

UK_Eliter
---- E L I T E ----
---- E L I T E ----
Posts: 1099
Joined: Sat Sep 12, 2009 11:58 pm
Location: Essex (mainly industrial and occasionally anarchic)

Re: Scripters cove

Post by UK_Eliter » Tue Aug 21, 2018 12:31 am

Hey all, and if I may (I've been off the boards and have rather forgotten how they work)

I'm trying to alter Thargoid's OXP HiredGuns - which he gave me to take over - so that the escorts provided by that OXP crash into things less often. To that end, I'm playing around with these AI messages (which fire only when something relevant changes):

Code: Select all

"CLOSE_TO_PLANET"
"CLOSE_TO_SECONDARY_PLANET"
"CLOSE_TO_MOON"
"CLOSE_TO_SUN"
I am also looking at the Javascript function addCollisionException, but I am confused by it. For one thing, the name seems odd. For, the documentation seems to say that one uses it to prevent ships colliding. Also, how does that prevention work? Are the ships allowed to occupy the same space, but without taking damage? I presume that rather the ships are prevented from occupying the same space. How, though? Is it that, if the ship to which one adds the exception is powered, it will be made to try to avoid the other ship?

I'd be grateful for any information.

Post Reply