shipWasScooped() broken?
Moderators: winston, another_commander, Getafix
- Eric Walch
- Slightly Grand Rear Admiral
- Posts: 5536
- Joined: Sat Jun 16, 2007 3:48 pm
- Location: Netherlands
shipWasScooped() broken?
I just picked up a drone and only got the message "drone scooped". I suddenly remember I had more failures lately in picking the drone up. I can't even remember that it worked the last few times.
Regarding McLane's messages about something similar with an other pickup, I looked into the drone code and noticed it should always send a message failure or not. And as far as I remember there was always the message in 1.71
It can only mean the this.shipWasScooped() handler is not fired anymore as I haven't changed anything at the oxp itself. It probably behaves this since 1.72. The legacy script_actions do work however.
Regarding McLane's messages about something similar with an other pickup, I looked into the drone code and noticed it should always send a message failure or not. And as far as I remember there was always the message in 1.71
It can only mean the this.shipWasScooped() handler is not fired anymore as I haven't changed anything at the oxp itself. It probably behaves this since 1.72. The legacy script_actions do work however.
UPS-Courier & DeepSpacePirates & others at the box and some older versions
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Re: shipWasScooped() broken?
Unless your drone is also being docked with, this is not possible - legacy script_actions are dispatched by a shipWasScooped() handler in oolite-default-ship-script.js.Eric Walch wrote:It can only mean the this.shipWasScooped() handler is not fired anymore as I haven't changed anything at the oxp itself. It probably behaves this since 1.72. The legacy script_actions do work however.
E-mail: [email protected]
Tryinstead ofI've had this in my new Localhero several times now and changed my shipscripts today. This version seems to work.
Code: Select all
scooper.isPlayer
Code: Select all
scooper == player.ship
The handler was firing for me the other day when I had to re-test Pods.oxp . In one of the scripts in there I'd forgotten to add the check that scooper might be "player.ship" (it was still only "player") and so wasn't firing under v1.72.
I made that scripting update in the Drones 1.01 version, can you confirm that's the one you have. If it's the 1.00 version then I think it only checks player, which it won't find under v1.72 since the player/ship split-off.
Editted to add - just tested my installed version, and it's working fine.
Svengali - that will break the script, as it uses the differentiation to say whether the code should use player or player.ship for other commands. Using isPlayer would mean a separate check needing to be added.
For reference, this is the code from my copy of pick-up script:
I made that scripting update in the Drones 1.01 version, can you confirm that's the one you have. If it's the 1.00 version then I think it only checks player, which it won't find under v1.72 since the player/ship split-off.
Editted to add - just tested my installed version, and it's working fine.
Svengali - that will break the script, as it uses the differentiation to say whether the code should use player or player.ship for other commands. Using isPlayer would mean a separate check needing to be added.
For reference, this is the code from my copy of pick-up script:
Code: Select all
this.name = "drones_Pickup";
this.author = "Thargoid & Eric Walsh";
this.copyright = "Creative Commons: attribution, non-commercial, sharealike.";
this.description = "Pickup of a drone after combat, and check if it's reusable (T). New JS Scanning routine (EW).";
this.version = "0.3";
this.shipWasScooped = function(scooper)
{
if (scooper == player)
{
this.thePlayerShip = player;
}
if (scooper == player.ship)
{
this.thePlayerShip = player.ship;
}
if (scooper == player || scooper == player.ship)
{
let choice = (Math.ceil(Math.random()*3));
if (choice == 3)
{
player.consoleMessage(this.ship.name+" circuits blown - only good for scrap machinery.", 6);
this.thePlayerShip.awardCargo("Machinery", 1)
}
else
{
player.consoleMessage(this.ship.name+" recovered, recharged and ready for use.", 6);
this.thePlayerShip.awardEquipment(this.ship.scriptInfo.DroneEquipment)
}
}
}
this.findMastersHostiles = function()
{
function isHostileToMaster(entity)
{
return (entity.isShip && entity.target && entity.target == this.ship.master && entity.hasHostileTarget);
}
let targets = system.filteredEntities(this, isHostileToMaster, this.ship, 25600)
if(targets.length > 0)
{
this.ship.target = targets[0];
this.ship.reactToAIMessage("NEW_DRONE_TARGET");
if(this.ship.master == player || this.ship.master == player.ship) player.commsMessage(this.ship.shipDescription+": Attacking "+targets[0].shipDisplayName)
}
else this.ship.reactToAIMessage("NOTHING_FOUND");
}
My OXPs via Boxspace or from my Wiki pages .
Thargoid TV
Dropbox Referral Link
Thargoid TV
Dropbox Referral Link
The check isn't working, so maybe you should rescript it. I've had the same on my computer and scooper == player.ship and scooper == player is not working. I've logged it and the checks were never true, so my variables were never set - I would say this breaks your script :-).Thargoid wrote:Svengali - that will break the script, as it uses the differentiation to say whether the code should use player or player.ship for other commands. Using isPlayer would mean a separate check needing to be added.
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
You could use scooper instead, that should work either way. (I’d suggest that writing new/updated scripts to support pre-1.72 test releases is counterproductive, though.)Thargoid wrote:Svengali - that will break the script, as it uses the differentiation to say whether the code should use player or player.ship for other commands.
E-mail: [email protected]
- Commander McLane
- ---- E L I T E ----
- Posts: 9520
- Joined: Thu Dec 14, 2006 9:08 am
- Location: a Hacker Outpost in a moderately remote area
- Contact:
shipWasScooped is not broken. In my case the bug was—me. I was editing a shipdata-overrides.plist that wasn't in my AddOns-folder. Very stupid.
Anyway, now it works fine.
@ Thargoid: I've looked at all your scripts in Pods.oxp, and I have the same question/suggestion as Ahruman. Instead of all the if(scooper == player){player.award...}, why don't you simply use scooper.award...? Why shouldn't NPCs profit from their scoops as well?
That's what I did for Status_Quo_Q-bombs 1.1 (uploading in a minute). So NPCs can scoop defused Q-bombs too. Which probably means they can use them as well...
Anyway, now it works fine.
@ Thargoid: I've looked at all your scripts in Pods.oxp, and I have the same question/suggestion as Ahruman. Instead of all the if(scooper == player){player.award...}, why don't you simply use scooper.award...? Why shouldn't NPCs profit from their scoops as well?
That's what I did for Status_Quo_Q-bombs 1.1 (uploading in a minute). So NPCs can scoop defused Q-bombs too. Which probably means they can use them as well...
Mainly because I didn't think of it at the time when I wrote the script and partly because I was trying to suppress rogue commsMessages when NPCs picked things up. But I guess scooper.award would do both.Commander McLane wrote:@ Thargoid: I've looked at all your scripts in Pods.oxp, and I have the same question/suggestion as Ahruman. Instead of all the if(scooper == player){player.award...}, why don't you simply use scooper.award...? Why shouldn't NPCs profit from their scoops as well?
One question though (as I can't easily test it as I'm waiting for a plane at the mo) - on the Wiki awardEquipment is (or currently was) listed under "player" rather than "ship". So can it be used on NPCs? Or when it comes back up again would that command be better listed elsewhere (under ship or perhaps even entity)?
If pods needs a rev-up at any point I'll make the change over, but at the moment it seems to work anyway.
But as with you, I can report on my WinXP box the event handler is working fine.
My OXPs via Boxspace or from my Wiki pages .
Thargoid TV
Dropbox Referral Link
Thargoid TV
Dropbox Referral Link
- Commander McLane
- ---- E L I T E ----
- Posts: 9520
- Joined: Thu Dec 14, 2006 9:08 am
- Location: a Hacker Outpost in a moderately remote area
- Contact:
You're right. The awardFoo-functions are of player.ship (not player(!)) only. They produce an error message if performed on other targets.Thargoid wrote:Mainly because I didn't think of it at the time when I wrote the script and partly because I was trying to suppress rogue commsMessages when NPCs picked things up. But I guess scooper.award would do both.Commander McLane wrote:@ Thargoid: I've looked at all your scripts in Pods.oxp, and I have the same question/suggestion as Ahruman. Instead of all the if(scooper == player){player.award...}, why don't you simply use scooper.award...? Why shouldn't NPCs profit from their scoops as well?
One question though (as I can't easily test it as I'm waiting for a plane at the mo) - on the Wiki awardEquipment is (or currently was) listed under "player" rather than "ship". So can it be used on NPCs? Or when it comes back up again would that command be better listed elsewhere (under ship or perhaps even entity)?
So no NPCs scooping Q-bombs.
Still, after the test if(scooper == player.ship) you can continue with scooper.awardFoo.
- Eric Walch
- Slightly Grand Rear Admiral
- Posts: 5536
- Joined: Sat Jun 16, 2007 3:48 pm
- Location: Netherlands
That would be the best way as it would work both 1.71 and 1.72 code. I have used it in the past for other updates. However I didn't thought that scooper == player would not be recognised by the handler. In other places it does work but only gives a deprecation warning to the log.Svengali wrote:Tryinstead ofCode: Select all
scooper.isPlayer
I've had this in my new Localhero several times now and changed my shipscripts today. This version seems to work.Code: Select all
scooper == player.ship
But I now know to get it working again.
UPS-Courier & DeepSpacePirates & others at the box and some older versions