missionVariables and hasOwnProperty

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

Moderators: winston, another_commander

Post Reply
herodotus
Competent
Competent
Posts: 45
Joined: Wed Jul 12, 2017 12:53 pm

missionVariables and hasOwnProperty

Post by herodotus »

Hi,

I've been debugging a broken OXP and I got a bit confused about the behaviour of the missionVariables object. The OXP I'm looking at checks to see if a missionVariable exists using missionVariables.hasOwnProperty('mission_prop');. This is probably redundant in the case in question anyway, but it seems like this returns false even if the property does exist and has a value. Does missionVariables use some dark JS magic that prevents properties showing up to hasOwnProperty? If not it's possible that I'm just getting confused, but I thought I'd check before I waste any more time trying to work out what's going on!

Cheers,
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4830
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: missionVariables and hasOwnProperty

Post by phkb »

I ran this test:

Code: Select all

	log(this.name, "test 1 " + (missionVariables.hasOwnProperty("myTest") === true ? "yes" : "no"));
	missionVariables.myTest = "hello world";
	log(this.name, "test 2 " + (missionVariables.hasOwnProperty("myTest") === true ? "yes" : "no"));
The output was:

Code: Select all

	test 1 no
	test 2 yes
So on the surface at least it seems to work.
Post Reply