shipWasScooped() broken?

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

shipWasScooped() broken?

Post by Eric Walch »

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.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: shipWasScooped() broken?

Post by JensAyton »

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.
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.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

Try

Code: Select all

scooper.isPlayer
instead of

Code: Select all

scooper == player.ship
I've had this in my new Localhero several times now and changed my shipscripts today. This version seems to work.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

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:

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");
    
}
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

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.
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 :-).
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

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.
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.)
User avatar
Commander McLane
---- E L I T E ----
---- 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:

Post by Commander McLane »

shipWasScooped is not broken. In my case the bug was—me. :oops: 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... :twisted:
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

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?
Mainly because I didn't think of it at the time when I wrote the script :oops: and partly because I was trying to suppress rogue commsMessages when NPCs picked things up. But I guess scooper.award would do both.

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.
User avatar
Commander McLane
---- E L I T E ----
---- 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:

Post by Commander McLane »

Thargoid wrote:
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?
Mainly because I didn't think of it at the time when I wrote the script :oops: and partly because I was trying to suppress rogue commsMessages when NPCs picked things up. But I guess scooper.award would do both.

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)?
You're right. The awardFoo-functions are of player.ship (not player(!)) only. They produce an error message if performed on other targets.

So no NPCs scooping Q-bombs.

Still, after the test if(scooper == player.ship) you can continue with scooper.awardFoo.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Svengali wrote:
Try

Code: Select all

scooper.isPlayer
instead of

Code: Select all

scooper == player.ship
I've had this in my new Localhero several times now and changed my shipscripts today. This version seems to work.
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.

But I now know to get it working again.
Post Reply