Energy bomb [Solved]

General discussion for players of Oolite.

Moderators: winston, another_commander

Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: Energy bomb [Solved]

Post by Switeck »

I ran into a problem with the Energy Bomb in trunk...any OXP that gives an Energy Bomb as a reward will now have its script crash at the point of the reward.

Example code:
if(player.ship.equipmentStatus("EQ_ENERGY_BOMB") !== "EQUIPMENT_OK") player.ship.awardEquipment("EQ_ENERGY_BOMB");
...Will generate a script crash when it "hits" that line.

Time to rewrite a few OXPs?
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Energy bomb [Solved]

Post by JensAyton »

Switeck wrote:
I ran into a problem with the Energy Bomb in trunk...any OXP that gives an Energy Bomb as a reward will now have its script crash at the point of the reward.
An unhandled exception in a script is not a crash, dagnabbit.

In any case, the example is simply wrong. The correct test is if (player.ship.canAwardEquipment("EQ_ENERGY_BOMB")). Don’t go second-guessing the game.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Energy bomb [Solved]

Post by JensAyton »

I’ve looked into the possibility of converting the award to a Q-mine, but it wouldn’t really work since the malformed test can’t reasonably be interpreted as a test of whether there’s a free missile slot.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: Energy bomb [Solved]

Post by Switeck »

Ahruman wrote:
Switeck wrote:
I ran into a problem with the Energy Bomb in trunk...any OXP that gives an Energy Bomb as a reward will now have its script crash at the point of the reward.
An unhandled exception in a script is not a crash, dagnabbit.

In any case, the example is simply wrong. The correct test is if (player.ship.canAwardEquipment("EQ_ENERGY_BOMB")). Don’t go second-guessing the game.
Sorry, I meant only that script quits running. (...and even then, only that part of the script quits running!)

Ok, so for guessing...is there any importance of the space between the if and (player?
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:

Re: Energy bomb [Solved]

Post by Commander McLane »

Switeck wrote:
is there any importance of the space between the if and (player?
No. What Ahruman says is that there is an importance of the difference between

Code: Select all

if(player.ship.equipmentStatus("EQ_ENERGY_BOMB") !== "EQUIPMENT_OK")
and

Code: Select all

if(player.ship.canAwardEquipment("EQ_ENERGY_BOMB"))
In other words: there is a method especially for the purpose of what you want to check (canAwardEquipment). So why do you not use it, but insist on using a homemade workaround (equipmentStatus) instead? Especially if the workaround throws an exception, but the proper method doesn't?
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: Energy bomb [Solved]

Post by Switeck »

I get that canAwardEquipment is important NOW, but why I didn't before:

Because in the past that worked and I had missed reading everything necessary to avoid potential problems. Even though the commands are well-documented, finding the exact documentation I need to read to correct my misunderstandings (plural, as they are MANY!) is not quick for me...and WHY things are best done a certain way is not clearly documented in the wiki. Even if I fully understand how the parts (individual commands) work perfectly, how to assemble them into a complex OXP without making silly mistakes is beyond me.

Being self-taught as well as having taken numerous courses in more primitive languages (Basic, COBOL, FORTRAN, Pascal, etc...) and NO formal training in modern languages (besides a touch of Visual Basic v2-3), I've had multiple decades of acquiring bad programming habits. One of those bad habits is copying existing code without enough understanding and foresight to spot potential problems because the circumstances differ. And what better place to copy from than the game's own .js files?

Similar code in oolite-thargoid-plans-mission.js and oolite-cloaking-device-pod.js makes no use of player.ship.canAwardEquipment -- probably because there is no consideration that those pieces of equipment may not be allowed or exist.

player.ship.canAwardEquipment is likewise lacking from the overwhelming majority of OXPs that I have studied. I did a windows search for "canAwardEquipment" (sans quotes) to find a single OXP that used it in one script out of 100's of OXPs I have in my Oolite primary folder at the moment! (No doubt there's other OXPs that use it, but I oddly missed them when trying to learn how to properly reward equipment.) All the other OXPs probably lack that command primarily because the equipment they are awarding is overwhelmingly native equipment OR equipment created by the same OXPs and thus they do not consider that such equipment is not present.
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:

Re: Energy bomb [Solved]

Post by Commander McLane »

Well, what I'm doing when I want to script something is browse through the documentation (I can only repeat that that's what the documentation is for) until I find the thing that does what I want do to.

So if I want to script a check for whether a ship can get some equipment or not, I turn to the JS-documentation for ship, and browse through the table of contents at the top of the document, especially through its methods-part. canAwardEquipment really catches the eye, then.

And I would regard this as a common-sense thing to do when writing OXPs. It's neither rocket science, nor does it require being a programmer (speaking as somebody who has much less experience with programming languages than your list reflects; the only "formal" training I ever had was some Pascal back in school).
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Energy bomb [Solved]

Post by Eric Walch »

Switeck wrote:
I ran into a problem with the Energy Bomb in trunk...any OXP that gives an Energy Bomb as a reward will now have its script crash at the point of the reward.......
Time to rewrite a few OXPs?
Probably, now the oxps need to do an explicit check for availability. Asteroid Storm was already updated to fix this problem about 6 weeks ago with version 4.03.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: Energy bomb [Solved]

Post by Switeck »

From AsteroidStorm.js version 4.03:

Code: Select all

this.addEnergyBomb = function () {
    // equipment can be unknown after Oolite 1.76
    if (player.ship.equipmentStatus("EQ_ENERGY_BOMB") !== "EQUIPMENT_UNKNOWN")
    {
        player.ship.awardEquipment("EQ_ENERGY_BOMB");
        return true;
    }
    return false;
}
sigh...

I was almost expecting it to be using player.ship.canAwardEquipment("EQ_ENERGY_BOMB").
User avatar
CommRLock78
---- E L I T E ----
---- E L I T E ----
Posts: 1138
Joined: Sat Apr 07, 2012 7:35 pm
Location: US
Contact:

Re: Energy bomb, yes they really did it

Post by CommRLock78 »

Fatleaf wrote:
For me the Ebomb is a Test Pilot only weapon. But I agree with you on the sound it makes. For a laugh swap the file names around so that in the F8 Commodity Market screen, every time you buy something it goes 'BOOM' instead :lol:
:lol: That must be entertaining :D

I'm glad that there is a work around.
"I'll laser the mark all while munching a fistful of popcorn." - Markgräf von Ededleen, Marquess, Brutal Great One, Assassins' Guild Exterminator
---------------------------
At the helm of the Caduceus Omega, 'Murderous Morrígan'
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Energy bomb [Solved]

Post by Thargoid »

I must chip in also and add that I didn't know canAwardEquipment existed until now. That said I don't think I've ever really needed it in the way that it is designed, instead it would have been "self-repairing" items via the equipmentDamaged event.

As awarding equipment wouldn't normally be something to check in my OXPs (most situations it would be just award it, and if it comes back false then you can't) I've never fallen over the issue Switeck mentioned. But I'm probably responsible for some of the ones that don't contain it.

And I'm similarly fairly self-taught like Switeck, so have at least as many programming bad habits.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Energy bomb [Solved]

Post by Smivs »

I have to confess canAwardEquipment passed me by as well. Mind you there is a huge wealth of information on those wiki js pages, and I don't claim to have an encyclopedic knowledge of all of it by any means.
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
SandJ
---- E L I T E ----
---- E L I T E ----
Posts: 1048
Joined: Fri Nov 26, 2010 9:08 pm
Location: Help! I'm stranded down here on Earth!

Re: Energy bomb [Solved]

Post by SandJ »

Smivs wrote:
I have to confess canAwardEquipment passed me by as well. Mind you there is a huge wealth of information on those wiki js pages, and I don't claim to have an encyclopedic knowledge of all of it by any means.
There is, and it is of the form that if you already know it, it is a good reference. But if you don't then looking at other people's code is a much better and easier-to-understand one.
Flying a Cobra Mk I Cobbie 3 with nothing but Explorers Club.OXP and a beam laser 4 proper lasers for company :D
Dropbox referral link 2GB of free space online + 500 Mb for the referral: good for securing work-in-progress.
User avatar
Tricky
---- E L I T E ----
---- E L I T E ----
Posts: 821
Joined: Sun May 13, 2012 11:12 pm
Location: Bradford, UK. (Anarchic)

Re: Energy bomb [Solved]

Post by Tricky »

I think I know the AI Howto back-to-front after much reading of the wiki pages. :?

Point is... READ, READ and READ!!!
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:

Re: Energy bomb [Solved]

Post by Commander McLane »

Tricky wrote:
Point is... READ, READ and READ!!!
Three most valid points indeed! :D
Post Reply