Can't spawn missile in script

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

Moderators: winston, another_commander

Post Reply
Joshua Calvert
Harmless
Harmless
Posts: 1
Joined: Thu Oct 20, 2011 9:44 pm

Can't spawn missile in script

Post by Joshua Calvert »

Greetings all,

I have the latest and greatest version of Oolite (1.75.3). I am working on my own OXP. I am using railgun.oxp as a base (copy 'n paste and edit job).
Instead of spawning a railgun projectile I wish to spawn a missile, so I've edited the code to look like:

Code: Select all

        
        this.missile = player.ship.spawnOne("rmb-intercept-missile");
	if(!!this.missile){
		player.consoleMessage("Intercept Missile Spawned OK.", 2);
	}else{
		player.consoleMessage("NOT Spawned !!!!!!!!!!!!!!!!!!!!!!", 2);
	}     
The RMB intercept missile is defined in the Missiles and Bombs OXP. The trouble is I get the NOT Spawned message so it doesn't work. So I tried to spawn a regular missile, using this:

Code: Select all

        
        this.missile = player.ship.spawnOne("missile");
	if(!!this.missile){
		player.consoleMessage("Intercept Missile Spawned OK.", 2);
	}else{
		player.consoleMessage("NOT Spawned !!!!!!!!!!!!!!!!!!!!!!", 2);
	}     
and things got really freaky; as far as I could tell it was spawning all kinds of stuff apart from missiles, including interdictor mines and thargons! :? :shock:

This is not my first time at OXP scripting and yes I've read the Javascript manual entry for spawnOne (unfortunately the docco doesn't come with examples and I find the one line "function spawnOne(role : String) : Ship" not terribly helpful). I blatantly swiped the if(!!this.missile)... construct from a website as I want to do a NULL test (yes I can google); the language I work with on a day to day basis has a completely different way of checking for NULLs (var is null, if anyone is wondering).

Anybody any helpful suggestions?

Ta,

Lagrange
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Can't spawn missile in script

Post by Smivs »

You would normally spawn by 'roles', so by using 'missile', yes you'd get anything that has 'missile' in its role. Have you tried spawning the override missile by role, ie 'EQ_RMB_OVERRIDE_MISSILE' ?
Commander Smivs, the friendliest Gourd this side of Riedquat.
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: Can't spawn missile in script

Post by Eric Walch »

Slightly related: missiles need a target or they will destroy themselves shortly after spawning. In your code, immediately after spawning, the missile should be there.
e.g. when I type: "PS.spawnOne("missile").name", the console displays the name of the missile as sign it selected one and I see briefly a missile on screen. Than it explodes and my ship receives damage.
User avatar
DaddyHoggy
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 8515
Joined: Tue Dec 05, 2006 9:43 pm
Location: Newbury, UK
Contact:

Re: Can't spawn missile in script

Post by DaddyHoggy »

Of, the previous responders also wanted/meant to say:

"Welcome to the Friendliest Board this side of Riedquat"(tm)
Selezen wrote:
Apparently I was having a DaddyHoggy moment.
Oolite Life is now revealed here
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: Can't spawn missile in script

Post by Svengali »

Hello Joshua, welcome onboard.
Joshua Calvert wrote:
I blatantly swiped the if(!!this.missile)... construct from a website as I want to do a NULL test (yes I can google);
Checking explicitely for null is not necessary here as the property is either undefined or a array (typeof object).
A simple if(this.missile) is absolutely enough to differentiate between a spawned entity and a not spawned one.

But in case you want to check for null, do it explicitely, e.g.

Code: Select all

if(whatever === null)
Note 3x=. This is similiar to the language you are familiar with .-)
The above mentioned if(!!whatever) does not differentiate between undefined, null, false or 0 (zero) and will fail in other use-cases.
Post Reply