Saving At Stations

General discussion for players of Oolite.

Moderators: winston, another_commander

User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Saving At Stations

Post by phkb »

Killer Wolf wrote: Thu Nov 23, 2023 11:38 am
but again it won't let me save. will i be able to stick the above code into the "do" bit of the planetinfo?
Spawning anything via the script_actions in planetinfo will not ever allow you to save your game at the station it spawns. That system was designed before the "systemWillPopulate" routines were implemented, and would be a step backwards in terms of compatibility.

Would it be possible to get a copy of your OXP, as it stands, so I can have a deeper dive into whats going on? I should be able to provide some insight and get you going in the right direction. You can PM me a link if you'd like to keep the code private for now. Even just the Config and Script folders should be enough to allow me to debug it.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Re: Saving At Stations

Post by Killer Wolf »

made a little progress, i can forward you the folders if you can't suss this out though;
currently have a world-scripts that points to my script in Scripts. it says

Code: Select all

this.systemWillPopulate = function()
{
	if (galaxyNumber === 0 && system.ID === 129) 
		{
		system.setPopulator("II_station", 
			{
			callback: function (pos) 
				{
				system.addShips("KW_II", 1, Vector3D(26700, 11250, 5235).fromCoordinateSystem("pwm"));
				},
			location: "COORDINATES",
			coordinates: stationPos,
			deterministic:true // < this is important
		});
	}
}
which is appearing now to work - jump to Zaonce and i get my station, jump eslewhere, i don't. Still need to tweak the coords, i don't fully understand why it's not spwaning where i thought it should, BUT - i'm still not allowd to save :-(
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Saving At Stations

Post by phkb »

It doesn’t look like you’re setting stationPos anywhere inside the function. That’s the variable that is defining where your station will spawn. Without it, you’re essentially passing in a null value, which is probably negating the effect of deterministic:true.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Re: Saving At Stations

Post by Killer Wolf »

magic, that's more consistent, thanks. any idea about the saving problem?
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Saving At Stations

Post by phkb »

Killer Wolf wrote: Fri Nov 24, 2023 1:54 pm
any idea about the saving problem?
This line is the problem:

Code: Select all

system.addShips("KW_II", 1, Vector3D(26700, 11250, 5235).fromCoordinateSystem("pwm"));
When you pass in stationPos to the callback, inside that callback you have a new variable, pos, which is the position you want to create your station at. So that line should read:

Code: Select all

system.addShips("KW_II", 1, pos, 0);
Based on this, your full routine should look something like this:

Code: Select all

this.systemWillPopulate = function()
{
	if (galaxyNumber === 0 && system.ID === 129) 
		{
		var stationPos = Vector3D(26700, 11250, 5235).fromCoordinateSystem("pwm");
		system.setPopulator("II_station", 
			{
			callback: function (pos) 
				{
				system.addShips("KW_II", 1, pos, 0);
				},
			location: "COORDINATES",
			coordinates: stationPos,
			deterministic:true // < this is important
		});
	}
}
That should allow you to save at your station.
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Re: Saving At Stations

Post by Killer Wolf »

finally replaced my test script w/ the example above and i'm not getting any spawn again. Doesn't have the log line in that my script does but the station appears as an "I" on the ASC, but i'm seeing nothing. no compile/syntax errors in the log though :-/

is there any significance to your addships having a zero at the end? mine ends w/ the co-ordinates.
User avatar
hiran
Theorethicist
Posts: 2403
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Saving At Stations

Post by hiran »

Killer Wolf wrote: Mon Dec 11, 2023 5:47 pm
is there any significance to your addships having a zero at the end? mine ends w/ the co-ordinates.
The documentation shows the addShips function can be run with two, three and four arguments.
https://wiki.alioth.net/index.php/Oolit ... m#addShips

So if you omit the fourth parameter, the ship will spawn within the scanner range of the third parameter.
The third parameter defines the position. If it is omitted, Oolite will spawn at the witchpoint.

Maybe you still should convert your coordinates, or search closer to the witchpoint?
Sunshine - Moonlight - Good Times - Oolite
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Saving At Stations

Post by phkb »

The 0 parameter at the end is vital, because we want the station to be positioned at the *exact* coordinates we specify. Otherwise the deterministic flag is pointless and we can’t save at the station.

Can you post the entire script file, top to bottom, so I can debug?
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Re: Saving At Stations

Post by Killer Wolf »

this was my test script to get the only-in-Cebior bit working, spawned the station in view of the Witchspace exit but wouldn't allow saves;

Code: Select all

this.name = "oolite-II";
	
this.systemWillPopulate = function()
{
	if (galaxyNumber === 1 && system.ID === 195) 
		{
		this.kwiistationOffset = system.mainPlanet.position.subtract(system.mainStation.position);
		this.kwiistationPosition = system.mainStation.position.add(this.kwiistationOffset.multiply(2)); // put the kwiistation directly on the other side of the planet from the main station.
		this.kwiistation = system.addShips("KWii", 1, this.kwiistationPosition); // this.kwiistation is an array of added ships - in this case a single cell array
		log(this.name, "kwiistation added.");
		};
		
}
this is the current version from what you posted early. i've since chopped the vector3D numbers down by a decimal place to see if it made any difference but still doesn't appear to be doing anything; no compile errors but no spawn i can see, nothing on my ASC;

Code: Select all

this.name = "oolite-II";
	
this.systemWillPopulate = function()
{
	if (galaxyNumber === 1 && system.ID === 195) 
		{
		var stationPos = Vector3D(26.700, 11.250, 5.235).fromCoordinateSystem("pwm");
		system.setPopulator("II_station", 
			{
			callback: function (pos) 
				{
				system.addShips("KW_II", 1, pos, 0);
				},
			location: "COORDINATES",
			coordinates: stationPos,
			deterministic:true // < this is important
		});
	}
}
cheers
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Saving At Stations

Post by phkb »

Well, on the surface, the code looks OK. However, the big difference I can see between the two routines is this:

Code: Select all

system.addShips("KWii", 1, this.kwiistationPosition);

Code: Select all

system.addShips("KW_II", 1, pos, 0);
If the first version, with "KWii" works, and the second version, with "KW_II" doesn't work, then I'd suspect your station doesn't have the role of "KW_II", but does have the role of "KWii". Check the roles and make sure you're using the right one. Edit to add: Capitalisation is important.

As a suggestion, you can add this to your code to help debug:

Code: Select all

this.systemWillPopulate = function()
{
	if (galaxyNumber === 1 && system.ID === 195) 
		{
		var stationPos = Vector3D(26.700, 11.250, 5.235).fromCoordinateSystem("pwm");
		system.setPopulator("II_station", 
			{
			callback: function (pos) 
				{
				var stn = system.addShips("KW_II", 1, pos, 0);
				if (stn && stn.length > 0) {
					log("station_spawn", "station spawned successfully");
				} else {
					log("station_spawn", "**ERROR** - station not spawned");
				},
			location: "COORDINATES",
			coordinates: stationPos,
			deterministic:true // < this is important
		});
	}
}
User avatar
Killer Wolf
---- E L I T E ----
---- E L I T E ----
Posts: 2278
Joined: Tue Jan 02, 2007 12:38 pm

Re: Saving At Stations

Post by Killer Wolf »

for crying out loud, it was staring me in my face - you're right, the ship tag is KW_II and the role was KWii, got myself mixed up. will rename!

works and can now save, just need to tweak position and possibly orientation.

much obliged @phkb :-)
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Saving At Stations

Post by phkb »

Yay! Got there in the end!
Post Reply