Scripters cove
Moderators: winston, another_commander
- 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
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.
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
- Wildeblood
- ---- E L I T E ----
- Posts: 2482
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
- Contact:
Re: Scripters cove
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.
- 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
The use case was made some posts above in this thread. I see that case legit.Wildeblood wrote: ↑Fri Oct 25, 2024 9:08 pmI 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.
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
- LittleBear
- ---- 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
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:
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?
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.
}
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.
-
- Quite Grand Sub-Admiral
- Posts: 6736
- Joined: Wed Feb 28, 2007 7:54 am
Re: Scripters cove
Assume you have this pylon configuration (HH = Hard Head, QM = Quirium Mine):
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:
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):
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:
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: should become
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.
Code: Select all
HH, HH, QM, HH
0 1 2 3
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
Code: Select all
HH, HH
0 1
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;
Code: Select all
var eq = player.ship.missiles[0].equipmentKey;
- LittleBear
- ---- 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
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.
- Wildeblood
- ---- E L I T E ----
- Posts: 2482
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
- Contact:
Re: Scripters cove
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.LittleBear wrote: ↑Tue Dec 17, 2024 1:00 pmThanks. 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.
- LittleBear
- ---- 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
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.
- Wildeblood
- ---- E L I T E ----
- Posts: 2482
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
- Contact:
Re: Scripters cove
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:-
What have I misunderstood about what you're doing?
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;
Re: Scripters cove
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?
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?