1.71-proofing oxps

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

Moderators: winston, another_commander

Post Reply
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

1.71-proofing oxps

Post by Kaks »

Thanks to new improved javascript methods & options, 1.71 should be much better for oxp writing purposes than ever before, but... there are quite a few bits and bobs that aren't the same between 1.70 and 1.71.

Bearing in mind that 1.71 is still very much a moving target, and what I'm about to say might be slightly irrelevant by the time 1.71 is released, I found a few general incompatibilites between 1.70 and 1.71 that are fairly easy to correct. Here are my initial findings, including code that will 'do the right thing' in both 1.70 & 1.71. Please take this advice with a pinch of salt! :)

Code: Select all

for (let i in array){//whatever} 
Please avoid. While it should work without problems, at the moment the javascript object model in 1.71 adds extra elements at the end of arrays.

A safe alternative:

Code: Select all

for (let i=0;i<array.length;i++){//whatever} 

Writing to the log from your oxp can be a bit of a problem now, since in 1.71 you will get a lot of warnings in the log if you use older log commands to write to the log. Did I mention 'log'?

My solution?

Code: Select all

this.Log=function(str){
	if (typeof log != 'undefined') log("script."+this.name, str);
	else LogWithClass("script."+this.name, str);
}
then whenever I want to write to the log I use

Code: Select all

this.Log('testing, testing..');
I've just redone a few oxps that had problems with 1.71, and those two kept cropping up all the time :?
Hope this helps others not to make the same mistakes, etc... ;)
Last edited by Kaks on Sun Mar 30, 2008 5:07 pm, edited 1 time in total.
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Post by Svengali »

Thanks Kaks :-)

It's a good reminder to overhaul my own work.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

Oopsie! I made a cut & paste error with the this.Log function... got too many version of the darned thing floating around...

Apologies! The new improved this.Log function should work ok now!
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
Post Reply