Scripters cove

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

Moderators: winston, another_commander

User avatar
hiran
Theorethicist
Posts: 2415
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Scripters cove

Post by hiran »

Whohoo! Another finding!

There is a way to retrieve a sorted dictionary already! Dictionary? Sorted? Well, that's what it seems to be...
https://github.com/OoliteProject/oolite ... y.m#L12854

I would so much like to see a unit test that verifies the list is sorted. To be run on all the operating systems we compile on.
Sunshine - Moonlight - Good Times - Oolite
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2482
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

hiran wrote: Fri Oct 25, 2024 8:39 pm
Could it be that a dictionary internally ends up to be a hashmap and therefore the sequence is not predictable? Could we change this to some container that preserves a sequence? As soon as it does, sorting can be applied...
I think you're barking up a dead tree, hiran. If world scripts were sorted into a consistent, predictable order what good would result? I'd predict a lot of scripts named "AAA my script", etc.
Make Zimbabwe Rhodesia Again. :lol: :shock:
User avatar
hiran
Theorethicist
Posts: 2415
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Scripters cove

Post by hiran »

Wildeblood wrote: Fri Oct 25, 2024 9:08 pm
hiran wrote: Fri Oct 25, 2024 8:39 pm
Could it be that a dictionary internally ends up to be a hashmap and therefore the sequence is not predictable? Could we change this to some container that preserves a sequence? As soon as it does, sorting can be applied...
I think you're barking up a dead tree, hiran. If world scripts were sorted into a consistent, predictable order what good would result? I'd predict a lot of scripts named "AAA my script", etc.
The use case was made some posts above in this thread. I see that case legit.
What would you suggest to get around that in a meaningful way?

Be aware your example assumes everybody wants to be first. But then you forget the authors that do not care, and the authors that just want to be before a specific script but by no means the first. If all this imposes problems we can still come up with rules. Currently there is no consistent sorting so the scripts live in kind of anarchy.
Sunshine - Moonlight - Good Times - Oolite
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2886
Joined: Tue Apr 04, 2006 7:02 pm
Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.

Re: Scripters cove

Post by LittleBear »

I'm a bit stuck with doing a simple loop to remove all the missiles from the player's pylon. This is used in a mission screen as the player is required to explore a station on foot using the mission screen as a 'choose your own adventure' style text adventure and having solved the text adventure, the player loads up on a special type of missile stored at the base which will be used in the next mission to destroy a particular target which is immune to normal weapons. So, I want to remove all the players missiles (if any are on the pylons) and replace them with the special missiles.

For removing I've got:

Code: Select all

this.assassins_missileloadup = function assassins_missileloadup() {
var loop = player.ship.missiles;
var i = 0;
if (loop.length !== 0) {
for (i = 0; i < loop.length; i++) {
var eq = player.ship.missiles[i].equipmentKey;
player.ship.removeEquipment(eq);
}
}
return;
// Closeing Bracket for Missile Load Up Function.
}
This kinda works, but it is only looping twice (and removing 2 missiles) when I have 4 on my pylons. I can't see what it wrong with the loop as it is correctly setting the loop variable to the number of missiles I have, but the loop is only run twice. Can anyone see something obviously wrong with it?
Last edited by LittleBear on Tue Dec 17, 2024 12:27 pm, edited 1 time in total.
OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6736
Joined: Wed Feb 28, 2007 7:54 am

Re: Scripters cove

Post by another_commander »

Assume you have this pylon configuration (HH = Hard Head, QM = Quirium Mine):

Code: Select all

HH, HH, QM, HH
0   1   2   3
Your loop length is 4 as correctly identified. Now check what happens to this array as your loop executes:
Iteration #1 (i = 0): We are removing the item at index 0 of the loop array. What remains is this:

Code: Select all

	HH. QM. HH
	0   1   2
The array has been re-indexed after removal of the first element. Now observe what happens when we go into iteration #2 (loop index is now 1, so we remove element at index 1 of the current array):

Code: Select all

	HH, HH
	0   1
Our updated array is now indexed as above, after removal of the q-mine which was taking the place at index #1 earlier. Now, one more attempt at removal, this time with index #2:

Code: Select all

ERROR - No index 2 exists anymore!

And of course index #3 which would be the next and final loop iteration, does not exist either. That's why you are failing after two attempts. I have not tested this, but I would expect that simply removing the item at index 0 on every loop iteration should be enough. So this line:

Code: Select all

var eq = player.ship.missiles[i].equipmentKey;
should become

Code: Select all

var eq = player.ship.missiles[0].equipmentKey;
This way items are removed only from one end of the array. This will execute as many times as pylon weapons exist, so hopefully you should have no problem anymore.
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2886
Joined: Tue Apr 04, 2006 7:02 pm
Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.

Re: Scripters cove

Post by LittleBear »

Thanks. That worked perfectly and I'm now missileless. I should be able to award the special missiles with the same loop but this time with loop set to the player.ship.missileCapacity and awarding them instead of removing them.
OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2482
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

LittleBear wrote: Tue Dec 17, 2024 1:00 pm
Thanks. That worked perfectly and I'm now missileless. I should be able to award the special missiles with the same loop but this time with loop set to the player.ship.missileCapacity and awarding them instead of removing them.
Um. The way to become missile-less is to awardEquipment() the missile removal equipment item (EQ_REMOVE_MISSILES ???) and let Oolite take care of all the details.
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2886
Joined: Tue Apr 04, 2006 7:02 pm
Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.

Re: Scripters cove

Post by LittleBear »

It's cos in terms of the 'story' the player is meant to be outside their ship in a space suit exploring the station as the main power and life support have failed. As there's no power and the inhabitants are all dead, there's no way to use the ship yard. As part of the text adventure the player has to physically unload their missiles and manually fit the missiles themselves once they have found the stockpile. So I want to do the awarding as part of the mission screen rather than the player going to the F3 screen and loading themselves up with the remove / buy missile options as the shipyard shouldn't be useable in the creepy abandoned station.
OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2482
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

Okay, but whether you use awardEquipment() in a mission screen callback function is irrelevant to whether the player has access to the F3 screen. You're using removeEquipment() in your script posted above.

So, to unload 4 missiles, you want the player to click on "unload a missile" four times? Looking at what you posted, it appears to loop through the pylons array and delete them all with a single activation. If the intention is to delete them all at once, I would have tried something like this first:-

Code: Select all

var temp = player.credits;
player.ship.awardEquipment(EQ_MISSILE_REMOVAL); // Check the proper eq name?
player.credits = temp;
What have I misunderstood about what you're doing? :?:
User avatar
Phasted
Competent
Competent
Posts: 52
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripters cove

Post by Phasted »

I'm wracking my brains and coming up empty...

How do I get a reference to a non-worldScript script? I want to be able to address/modify a market script from functions in my worldScript... It might seem silly, but I think it's kind of important... and I'd like to avoid tossing any garbage into the global space if it's at all possible...

Can this be done? Am I typing out of my ass here?
Post Reply