Java Script Error, Ship Is Undefined

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

Moderators: winston, another_commander

User avatar
mandoman
---- E L I T E ----
---- E L I T E ----
Posts: 1375
Joined: Thu Apr 28, 2011 3:17 pm

Java Script Error, Ship Is Undefined

Post by mandoman »

What exactly does this mean. I have a Java Script for a particular ship, but I keep getting

Code: Select all

01:37:15.487 [script.javascript.init]: JavaScript reset successful.
01:37:15.522 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (dreadnaught): TypeError: this.ship.dreadnaught is undefined
01:37:15.522 [script.javaScript.exception.unexpectedType]:       /home/mandoman/.Oolite/AddOns/Dreadnaughtv1.0.oxp/Scripts/dreadnaught.js, line 9.
Does that mean that there is no such ship in Oolite, or what? None of the ships I have built are defined in the Core scripts, so why is this one any different? Thanks for any help.
Mandotech Industries Wiki Page.

http://wiki.alioth.net/index.php/User:Mandoman
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: Java Script Error, Ship Is Undefined

Post by Capt. Murphy »

Can you post the script? It looks like a simple JS syntax error and if we can see what you are trying to do with the script then we can point you in the right direction.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Java Script Error, Ship Is Undefined

Post by Thargoid »

Somewhere in the script it's trying to use this.ship.dreadnaught, which is not a function which is associated with the entity type ship (the available ones are on the wiki plus those for higher and lower entity types as linked to at the top of that page).

What you might want is something like this.ship.name = "dreadnaught"; or somesuch perhaps?
User avatar
mandoman
---- E L I T E ----
---- E L I T E ----
Posts: 1375
Joined: Thu Apr 28, 2011 3:17 pm

Re: Java Script Error, Ship Is Undefined

Post by mandoman »

Capt. Murphy wrote:
Can you post the script? It looks like a simple JS syntax error and if we can see what you are trying to do with the script then we can point you in the right direction.
Okay, but I do this with some embarrassment, as I borrowed heavily from the Behemoth's oxp for much of this oxp. Here it is:

Code: Select all

this.name        = "dreadnaught"; 
this.author      = "Aegidian"; 
this.copyright   = "� 2008 the Oolite team."; 
this.description = "Addition script of the Dreadnaught in Witchspace."; 
this.version     = "1.0"; 

this.ship = ["dreadnaught-andricothere", "dreadnaught-andricodred"];
this.dreadnaughtshipList = this.ship.dreadnaught.concat();

this.shipExitedWitchspace = function()
{
    if(system.isInterstellarSpace)
    {
        var number = Math.floor(Math.random()*Math.random()*4.5); //(0 to 3 ships with distribution towards 0)
        if(this.dreadnaughtshipList.length < number) this.dreadnaughtshipList = this.andricothere.concat(); // reset the list
        for(var i=0; i<number; i++) system.legacy_addShips(this.uniquedreadnaughtship(), 1);
		 // this method has a larger deviation in ship numbers than original code and also selects unique names over several jumps.
    }
    else if(Math.random() < 0.015 * system.government) // don't add police ships in anarchies.
    {
        system.legacy_addShipsAt(this.uniquedreadnaught, 1, "pwp", [0.1, 0.2, 2])    
    }
} 
 
this.uniquedreadnaughtship = function()
{
    if(this.andricothereshipList.length === 0) this.dreadnaughtshipList = this.dreadnaughtship.concat(); // reset the list
    return this.dreadnaughtshipList.splice(Math.floor(Math.random()*this.dreadnaughtshipList.length), 1);
    // Make sure that every time a ship with new name is pulled of the list.
}

Thargoid wrote:
Somewhere in the script it's trying to use this.ship.dreadnaught, which is not a function which is associated with the entity type ship (the available ones are on the wiki plus those for higher and lower entity types as linked to at the top of that page).

What you might want is something like this.ship.name = "dreadnaught"; or somesuch perhaps?
The problem with that is that I had decided that I would make a general "class" of ship, labelled "Dreadnaught", kind of like Aegidian's "Behemoth", which is why I borrowed so heavily from that oxp. I was hoping that I changed it just enough so the two oxps wouldn't clash, but I didn't hardly change the "dreadnaught.js" at all. Oh well, the Script curse pokes up it's head once more. :)
Mandotech Industries Wiki Page.

http://wiki.alioth.net/index.php/User:Mandoman
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Java Script Error, Ship Is Undefined

Post by Thargoid »

Code: Select all

this.ship = ["dreadnaught-andricothere", "dreadnaught-andricodred"];
this.dreadnaughtshipList = this.ship.dreadnaught.concat();
OK, these two lines are the first of your problems.

Firstly this.ship has a special meaning in scripting (it's the entity to which the script is attached), so your upper line there isn't good as you're trying to redefine it. Use something else like this.roleList or something and then refer to that as appropriate.

The lower line is also wrong - that's not how concat works. It is used to join two arrays together into one - see here for an example of how it operates.

Also in that line is your this.ship.dreadnaught that I mentioned earlier. dreadnaught isn't a JS property of an entity, which is how you are trying to use it here. Similarly further down you have if(this.dreadnaughtshipList.length < number) this.dreadnaughtshipList = this.andricothere.concat(); // reset the list which is similar (you're trying to use this.andricothere as a property by how you've put it in the script, which isn't correct and the script will choke on it as it's not defined anywhere (as I don't think that is really your intention).

And further there are similar examples of misuse in the same fashion.

The upper two lines (the ones I mentioned at the top of this post) are also not part of a function, which is better to avoid unless there's a specific reason to do so. Common functions to use for initialising things are this.startUp() (called when the current game is loaded) and this.shipSpawned() called when the ship to which the script is attached is first spawned.

I think you're still fundamentally struggling with the JS concept of how the language works. I'll have a hunt on the net and see if I can find something suitable, as without that understanding you're forever going to struggle. Once you get your head around it it's not too difficult a concept, but I think that's where you need to go first then you should be able to put together some functional code. Unfortunately most webpages on JS programming are for writing web-browser based JS, which isn't quite what we're doing here. Better might be to find a decent how-to book from the library? (it's how I learned).
User avatar
mandoman
---- E L I T E ----
---- E L I T E ----
Posts: 1375
Joined: Thu Apr 28, 2011 3:17 pm

Re: Java Script Error, Ship Is Undefined

Post by mandoman »

Thargoid wrote:

Code: Select all

this.ship = ["dreadnaught-andricothere", "dreadnaught-andricodred"];
this.dreadnaughtshipList = this.ship.dreadnaught.concat();
OK, these two lines are the first of your problems.

Firstly this.ship has a special meaning in scripting (it's the entity to which the script is attached), so your upper line there isn't good as you're trying to redefine it. Use something else like this.roleList or something and then refer to that as appropriate.

The lower line is also wrong - that's not how concat works. It is used to join two arrays together into one - see here for an example of how it operates.

Also in that line is your this.ship.dreadnaught that I mentioned earlier. dreadnaught isn't a JS property of an entity, which is how you are trying to use it here. Similarly further down you have if(this.dreadnaughtshipList.length < number) this.dreadnaughtshipList = this.andricothere.concat(); // reset the list which is similar (you're trying to use this.andricothere as a property by how you've put it in the script, which isn't correct and the script will choke on it as it's not defined anywhere (as I don't think that is really your intention).

And further there are similar examples of misuse in the same fashion.

The upper two lines (the ones I mentioned at the top of this post) are also not part of a function, which is better to avoid unless there's a specific reason to do so. Common functions to use for initialising things are this.startUp() (called when the current game is loaded) and this.shipSpawned() called when the ship to which the script is attached is first spawned.

I think you're still fundamentally struggling with the JS concept of how the language works. I'll have a hunt on the net and see if I can find something suitable, as without that understanding you're forever going to struggle. Once you get your head around it it's not too difficult a concept, but I think that's where you need to go first then you should be able to put together some functional code. Unfortunately most webpages on JS programming are for writing web-browser based JS, which isn't quite what we're doing here. Better might be to find a decent how-to book from the library? (it's how I learned).
Okay, I know I don't have it yet, so any help is appreciated greatly. Question, why does the exact script used for the behemoth.js NOT work for the dreadnaught.js? I understand that I don't have a handle on the language itself, but I tried my darndest to meet the same conditions as those of the Behemoth oxp, so what is different? In the end, it will still all come down to my understanding of Java Script, but that inability to use it in what appears to be an exact form of an already existing version throws me.
Mandotech Industries Wiki Page.

http://wiki.alioth.net/index.php/User:Mandoman
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Java Script Error, Ship Is Undefined

Post by Thargoid »

Ok, working from the behemoth.js script in the 2.6 version of the OXP.

Firstly the comment I mentioned originally about this.ship comes into play and needs adjusting as I mentioned above.

In the Behemoth script, we have two variables, this.behemoth and this.behemothList. The former is an array holding all the possible roles of the ships (if you look in the OXP shipdata.plist, you'll see each different Behemoth has its own role as well as name), and the latter will initially hold the same (the command takes this.behemoth and adds nothing to it to form this.behemothList).

The script has two functions in it, this.uniqueBehemoth() and this.shipExitedWitchspace() The first one is a new function defined in this script, and the second one is one of the trunk functions (called when an entity - in this case the player ship as this is a worldscript - exits witchspace).

The first line of this.uniqueBehemoth() simply says if the list (this.behemothList) is empty, then reset it by rebuilding it from this.behemoth in the same way as the very beginning of the script. The second line uses splice to remove a random element from the list, and to use that removed element as the result of the function.

Basically this function takes the list (this.behemothList) and picks one element from it (one ship name in this case) as its result. So in practice every time it is called, the returned value will be a ship name, that name then being removed from the list to give a unique ship name every time. You could almost think of it as "picking a role from the hat" as the available pool of roles (this.behemothList) goes down in size as they are picked out.

The second function (this.shipExitedWitchspace()) is called when the player exits witchspace (ie enters a new system or interstellar space). The if statement is used to differentiate the two conditions. If we're in interstellar space a random number between 0-3 is generated, and this many behemoths are added to the game. Each time the this.uniqueBehemoth() function is used to pick a ship role from the list, and that ship role is then used to add the ship to the game via the system.legacy_addShips(this.uniqueBehemoth(), 1) command.

If we're in normal space (the lower part of the if statement, after the else) and if we're not in an anarchy system (the second if statement, if(Math.random() < 0.015 * system.government) - so chances are higher towards Corporate State systems, anarchies are system.government = 0 so chance will be zero) then if the random roll is low enough then we add the Behemoth to the system in a similar fashion to the above, but using a slightly different command to also define where it's added.

Your code should look something like this (note I haven't tested this code, so beware of typo's):

Code: Select all

this.name        = "dreadnaught"; 
this.author      = "Mandoman, from the Behemoth OXP script by Aegidian via Thargoid"; 
this.copyright   = "? 2008 the Oolite team."; 
this.description = "Addition script of the Dreadnaught in Witchspace."; 
this.version     = "1.0"; 

this.startUp = function()
{
this.dreadnaughtRoles = ["dreadnaught-andricothere", "dreadnaught-andricodred"]; // this is a list of all possible dreadnaught ship roles, as defined in shipdata.plist
this.dreadnaughtShipList = this.ship.dreadnaughtRoles.concat(); // this is the "working" list of roles, which shortens as roles are picked for spawning.
}

this.shipExitedWitchspace = function()
{
    if(system.isInterstellarSpace)
    {
        var number = Math.floor(Math.random()*Math.random()*4.5); //(0 to 3 ships with distribution towards 0)
        if(this.dreadnaughtShipList.length < number) this.dreadnaughtShipList = this.dreadnaughtRoles.concat(); // reset the list if we haven't enough roles "in the hat" to pick out enough for each ship needed.
        for(var i=0; i<number; i++) system.legacy_addShips(this.uniqueDreadnaughtShip(), 1);
       // this method has a larger deviation in ship numbers than original code and also selects unique names over several jumps.
    }
    else if(Math.random() < 0.015 * system.government) // don't add police ships in anarchies.
    {
        system.legacy_addShipsAt(this.uniqueDreadnaughtShip(), 1, "pwp", [0.1, 0.2, 2]);    
    }
} 

this.uniqueDreadnaughtShip = function()
{
    if(this.dreadnaughtShipList.length === 0) this.dreadnaughtShipList = this.dreadnaughtRoles.concat(); // reset the list
    return this.dreadnaughtShipList.splice(Math.floor(Math.random()*this.dreadnaughtShipList.length), 1);
    // Make sure that every time a ship with new name is pulled of the list.
}
Compare it to yours and see the differences and how it works. Also note that you'll need a range of ships with different roles, defined in shipdata.plist in the same way that it's done in the Behemoth OXP. That's most simply done by defining a "template" version and then using like_ship to make each variant.[/color]
User avatar
mandoman
---- E L I T E ----
---- E L I T E ----
Posts: 1375
Joined: Thu Apr 28, 2011 3:17 pm

Re: Java Script Error, Ship Is Undefined

Post by mandoman »

Thargoid wrote:
Ok, working from the behemoth.js script in the 2.6 version of the OXP.

Firstly the comment I mentioned originally about this.ship comes into play and needs adjusting as I mentioned above.

In the Behemoth script, we have two variables, this.behemoth and this.behemothList. The former is an array holding all the possible roles of the ships (if you look in the OXP shipdata.plist, you'll see each different Behemoth has its own role as well as name), and the latter will initially hold the same (the command takes this.behemoth and adds nothing to it to form this.behemothList).

The script has two functions in it, this.uniqueBehemoth() and this.shipExitedWitchspace() The first one is a new function defined in this script, and the second one is one of the trunk functions (called when an entity - in this case the player ship as this is a worldscript - exits witchspace). I'll talk about the second one first, for simplicity as one refers to the other.

The first line of this.uniqueBehemoth() simply says if the list (this.behemothList) is empty, then reset it by rebuilding it from this.behemoth in the same way as the very beginning of the script). The second line uses splice to remove a random element from the list, and to use that removed element as the result of the function.

Basically this function takes the list (this.behemothList) and picks one element from it (one ship name in this case) as its result. So in practice every time it is called, the returned value will be a ship name, that name then being removed from the list to give a unique ship name every time. You could almost think of it as "picking a role from the hat" as the available pool of roles (this.behemothList goes down in size as they are picked out.

The second function (this.shipExitedWitchspace()) is called when the player exits witchspace (ie enters a new system or interstellar space). The if statement is used to differentiate the two conditions. If we're in interstellar space a random number between 0-3 is generated, and this many behemoths are added to the game. Each time the this.uniqueBehemoth() function is used to pick a ship role from the list, and that ship role is then used to add the ship to the game via the system.legacy_addShips(this.uniqueBehemoth(), 1) command.

If we're in normal space (the lower part of the if statement, after the else) and if we're not in an anarchy system (the second if statement, if(Math.random() < 0.015 * system.government) - so chances are higher towards Corporate State systems, anarchies are system.government = 0 so chance will be zero) then if the random roll is low enough then we add the Behemoth to the system in a similar fashion to the above, but using a slightly different command to also define where it's added.

Your code should look something like this (note I haven't tested this code, so beware of typo's):

Code: Select all

this.name        = "dreadnaught"; 
this.author      = "Mandoman, from the Behemoth OXP script by Aegidian via Thargoid"; 
this.copyright   = "? 2008 the Oolite team."; 
this.description = "Addition script of the Dreadnaught in Witchspace."; 
this.version     = "1.0"; 

this.startUp = function()
{
this.dreadnaughtRoles = ["dreadnaught-andricothere", "dreadnaught-andricodred"]; // this is a list of all possible dreadnaught ship roles, as defined in shipdata.plist
this.dreadnaughtShipList = this.ship.dreadnaughtRoles.concat(); // this is the "working" list of roles, which shortens as roles are picked for spawning.
}

this.shipExitedWitchspace = function()
{
    if(system.isInterstellarSpace)
    {
        var number = Math.floor(Math.random()*Math.random()*4.5); //(0 to 3 ships with distribution towards 0)
        if(this.dreadnaughtShipList.length < number) this.dreadnaughtShipList = this.dreadnaughtRoles.concat(); // reset the list if we haven't enough roles "in the hat" to pick out enough for each ship needed.
        for(var i=0; i<number; i++) system.legacy_addShips(this.uniqueDreadnaughtShip(), 1);
       // this method has a larger deviation in ship numbers than original code and also selects unique names over several jumps.
    }
    else if(Math.random() < 0.015 * system.government) // don't add police ships in anarchies.
    {
        system.legacy_addShipsAt(this.uniqueDreadnaughtShip(), 1, "pwp", [0.1, 0.2, 2]);    
    }
} 

this.uniqueDreadnaughtShip = function()
{
    if(this.dreadnaughtShipList.length === 0) this.dreadnaughtShipList = this.dreadnaughtRoles.concat(); // reset the list
    return this.dreadnaughtShipList.splice(Math.floor(Math.random()*this.dreadnaughtShipList.length), 1);
    // Make sure that every time a ship with new name is pulled of the list.
}
Compare it to yours and see the differences and how it works. Also note that you'll need a range of ships with different roles, defined in shipdata.plist in the same way that it's done in the Behemoth OXP. That's most simply done by defining a "template" version and then using like_ship to make each variant.[/color]
Okay, I think I see it. In the shipdata.plist I have two different classes of "Dreadnaught", defined as "dreadnaught_type1" and "dreadnaught_type2", type two being substantially larger than type one. I also have "is_template = yes" in each dreadnaught type. I then made a "like_ship" reference of the Andricothere to type1, and Andricodred to type2. Latest.log couldn't process that, and said

Code: Select all

ERROR: one or more shipdata.plist entries have like_ship references that cannot be resolved: dreadnaught-andricodred, dreadnaught-andricothere
Is this the same basic problem showing up in the dreadnaught.js? They appear in Latest.log, one after the other.

Should I have written instead "dreadnaught_type2-andricodred, dreadnaught_type1-andricothere"?
Mandotech Industries Wiki Page.

http://wiki.alioth.net/index.php/User:Mandoman
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Java Script Error, Ship Is Undefined

Post by Thargoid »

Firstly you want the two template entries, one for each ship type. So let's call them "dreadnaught_Andricothere_Template" and "dreadnaught_Andricodred_Template". Those will have is_template = true; in their definition arrays.

We then have the individual ships, which we will call "alpha", "beta", "gamma" etc. So we then have:

Code: Select all

dreadnaught_Andricothere_Template ={
is_template = true;
<all the other definition items in here>
};

dreadnaught_Andricodred_Template = {
is_template = true;
<all the other definition items in here>
};

dreadnaught_Andricothere_Alpha = {
like_ship = "dreadnaught_Andricothere_Template";
name = "Andricothere Alpha";
roles = "dreadnaught_Andricothere_Alpha";
};

dreadnaught_Andricothere_Beta = {
like_ship = "dreadnaught_Andricothere_Template";
name = "Andricothere Beta";
roles = "dreadnaught_Andricothere_Beta";
};

dreadnaught_Andricothere_Gamma = {
like_ship = "dreadnaught_Andricothere_Template";
name = "Andricothere Gamma";
roles = "dreadnaught_Andricothere_Gamma";
};

dreadnaught_Andricodred_Alpha = {
like_ship = "dreadnaught_Andricored_Template";
name = "Andricored Alpha";
roles = "dreadnaught_Andricored_Alpha";
};

dreadnaught_Andricored_Beta = {
like_ship = "dreadnaught_Andricored_Template";
name = "Andricored Beta";
roles = "dreadnaught_Andricored_Beta";
};

dreadnaught_Andricored_Gamma = {
like_ship = "dreadnaught_Andricored_Template";
name = "Andricored Gamma";
roles = "dreadnaught_Andricored_Gamma";
}

etc etc 
Then the roles each go into the list (this.dreadnaughtRole) in the script to form the pool of ships. This has the advantage that each individual ship can be different from all its sisters (as each will basically have its own shipdata entry) but the disadvantage that the shipdata.plist file ends up huge (for much the same reason). Essentially each ship (by name/role) is truly a unique entity).

Look in the shipdata.plist of Behemoth OXP and tie it in with the script there to see how they co-exist and interact.[/color]
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Java Script Error, Ship Is Undefined

Post by Smivs »

if your 'template' is "dreadnaught_type1", then in shipdata you will need

Code: Select all

"andricothere"
{
like_ship = "dreadnaught_type1";
};
etc

Ninja'd (in a much more comprehensive way) by Thargoid :)
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
mandoman
---- E L I T E ----
---- E L I T E ----
Posts: 1375
Joined: Thu Apr 28, 2011 3:17 pm

Re: Java Script Error, Ship Is Undefined

Post by mandoman »

Here is the shipdata.plist. It sure looks to me like I'm defining the roles correctly. At least it looks like the way it is done in the behemoth shipdata.plist. I was planning on adding several more ships to each class type. I was just trying to work out the kinks before doing so. Looks like it's more than just a few kinks. I'm always trying to bite off more than I can chew......but doggonnit, I can't help myself. I have a million ideas, and I want to materialise them right now, LOL!! :lol:

Code: Select all

{
        "dreadnaught-andricothere" = {
		"like_ship" = "dreadnaught-type1";
                "materials" = "dreadnaught_type1.png";
		"model" = "dreadnaught_type1.dat";
		"name" = "Dreadnaught - Andricothere";
		"roles" = "dreadnaught dreadnaught-andricothere";
	};
        "Dreadaught Type 1" = 
	{
                "ai_type" = "dreadnaughPatrolAI.plist";
		"auto_ai" = yes;
	        "aft_weapon_type" = "NONE";
		"bounty" = 0;
		"cargo_type" = "CARGO_NOT_CARGO";
		"energy_recharge_rate" = 7;
                "escort_ship" = "dreadnaught-SunBat-fighter";
                "escorts" = 6;
                "exhaust" = (
                   "-217.76 -7.73 -451.67 45.0 45.5 30.5",
                   "38.0 2.36 -401.7 0.6 67 85.0 45.5 30.5",
                   "-38.0 2.36 -401.7 -0.6 67 85.0 45.5 30.5",
                   "217.76 -7.73 -451.67 45.0 45.5 30.5",
                );
                "frangible" = yes;
		"fuel" = 150;
		"has_ecm" = "yes";
                "has_fuel_injection" = yes;
                "has_fuel_scoop" = yes;
                "has_heat_shield" = yes;
                "has_hyperspace_motor" = yes;
                "has_shield_booster" = yes;
                "has_shield_enhancer" = yes;
                "has_npc_traffic" = no;
                "is_carrier" = yes;
                "is_template" = yes;
                "market" = "dreadnaught";
                "max_cargo" = 600;
		"max_energy" = 700;
		"max_flight_pitch" = 0.2;
		"max_flight_roll" = 0.4;
		"max_flight_speed" = 400;
		"materials" = "dreadnaught_type1.png";
		"model" = "dreadnaught_type1.dat";
		"name" = "Dreadnaught Type 1";
		"roles" = "dreadnaught_type1-carrier";
                "scan_class" = "CLASS_POLICE";
                "script" = "dreadnaught-carrier.js";
        "subentities" = (
                        {
                                type = "ball_turret";"is_template" = yes;
				subentity_key = "dreadnaught_ball_turret_type1";
				position = (0.2, 54.0, 197.0);
				orientation = (1, 1, 0, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
				position = (0.2, 54.0, 197.0);
				orientation = (1, 0, 1, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (0.0, -120.5, 96.5);
                                orientation = (-1, 1, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (0.0, -120.5, 96.5);
                                orientation = (1, 0, -1, 0);
                        },
            {
                                type = "ball_turret";
				subentity_key = "dreadnaught_ball_turret_type1";
				position = (-100.25, 79.0, -72.69);
				orientation = (1, 1, 0, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (-100.25, 79.0, -72.69);
                                orientation = (1, 0, 1, 0);
                        },
            {
                                type = "ball_turret";
				subentity_key = "dreadnaught_ball_turret_type1";
				position = (100.25, 79.0, -72.0);
				orientation = (1, 1, 0, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (100.25, 79.0, -72.0);
                                orientation = (1, 0, 1, 0);
                        },
            {
                                type = "ball_turret";
				subentity_key = "dreadnaught_ball_turret_type1";
				position = (0.0, 104.5, -243.5);
				orientation = (1, 1, 0, 0);
			},
            {
                                type = "ball_turret";
				subentity_key = "dreadnaught_ball_turret_type1";
				position = (0.0, 104.5, -243.5);
				orientation = (1, 0, 1, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (0.7, -123.0, -142.0);
                                orientation = (1, -1, 0, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (0.7, -123.0, -142.0);
                                orientation = (1, 0, -1, 0);
			},
            {
                                is_dock = "true";
                                subentity_key = "dreadnaught_dock_type1";
                                position = (0.003347, -1.233, 2.26);
                                orientation = (0, 0, 0, 1);
                        }
		);
                "forward_weapon_type" = "NONE";
                "thrust" = 3.5;
        };        
        "Dreadnaught Type 2" = 
	{
                "ai_type" = "dreadnaughtPatrolAI.plist";
		"auto_ai" = no;
	        "aft_weapon_type" = "WEAPON_MILITARY_LASER";
		"bounty" = 0;
		"cargo_type" = "CARGO_NOT_CARGO";
                "defense_ship_role" = "dreadnaught-battleship";
		"energy_recharge_rate" = 9;
                "equipment_price_factor" = 2.0;
		"equivalent_tech_level" = 13;
		"escort-role" = "dreadnaught-fighter";
                "escort_ship" = "dreadnaught-sunbat-fighter";
                "escorts" = 12;
                "exhaust" = (
                   "-385.37 81.5 -824.5 67 85.0 45.5 30.5",
                   "-361.2 -247 -805.4 67 85.0 45.5 30.5",
                   "-71.7 71.4 -742.7 67 85.0 45.5 30.5",
                   "71.7 71.4 -742.7 67 85.0 45.5 30.5",
                   "361.2 -247 -805.4 67 85.0 45.5 30.5",
                   "385.37 81.5 -824.5 67 85.0 45.5 30.5",
                );
                "frangible" = yes;
		"fuel" = 500;
		"has_ecm" = yes;
                "has_heat_shield" = yes;
                "has_hyperspace_motor" = yes;
                "has_shield_booster" = yes;
                "has_shield_enhancer" = yes;
                "has_npc_traffic" = no;
                "is_carrier" = yes;
                "is_template" = yes;
                "market" = "dreadnaught";
                "max_cargo" = 1500;
		"max_energy" = 900;
		"max_flight_pitch" = 0.2;
		"max_flight_roll" = 0.2;
		"max_flight_speed" = 180;
		"materials" = "dreadnaught_type2.png";
		"model" = "dreadnaught_type2.dat";
		"name" = "Dreadnaught Type 2";
		"roles" = "dreadnaught_type2-carrier";
                "scan_class" = "CLASS_POLICE";
                "script" = "dreadnaught-carrier.js";
                "weapon_position_aft" = "0.0 157.3 -711.8";
                "weapon_position_forward" = "0.0 5.1 1010.0";
        "subentities" = (
                        {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (-94.9, 344.3, 487.0);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (-53.5, 344.3, 487.0);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (0.0, 344.3, 487.0);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (53.5, 344.3, 487.0);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (94.9, 344.3, 487.0);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (-94.9, 303.4, 528.7);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (-53.5, 303.4, 528.7);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (0.0, 303.4, 528.7);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (53.5, 303.4, 528.7);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (94.9, 303.4, 528.7);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (-94.9, 261.6, 571.2);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (-53.5, 261.6, 571.2);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (0.0, 261.6, 571.2);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (53.5, 261.6, 571.2);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (94.9, 261.6, 571.2);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (-94.9, 219.2, 612.9);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (-53.5, 219.2, 612.9);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (0.0, 219.2, 612.9);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (53.5, 219.2, 612.9);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type2";
                                position = (94.9, 219.2, 612.9);
                                orientation = (1, 0, 0, 0);
                        },
            {
                                type = "ball_turret";
				subentity_key = "dreadnaught_ball_turret_type1";
				position = (-132.1, 102.6, 766.9);
				orientation = (1, 1, 0, 0);
			},
            {
                                type = "ball_turret";
				subentity_key = "dreadnaught_ball_turret_type1";
				position = (-132.1, 102.6, 766.9);
				orientation = (1, 0, 1, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
				position = (132.1, 102.6, 766.9);
				orientation = (1, 1, 0, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
		                position = (132.1, 102.6, 766.9);
				orientation = (1, 0, 1, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (-149.9, -58.3, 723.9);
                                orientation = (1, 1, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (-149.9, -58.3, 723.9);
                                orientation = (1, 0, 1, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (149.9, -58.3, 723.9);
                                orientation = (1, 1, 0, 0);
                        },
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (149.9, -58.3, 723.9);
                                orientation = (1, 0, 1, 0);
                        },
            {
                                type = "ball_turret";
				subentity_key = "dreadnaught_ball_turret_type1";
				position = (0.0, 58.3, -89.47);
				orientation = (1, 1, 0, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (0.0, 58.3, -89.47);
                                orientation = (1, 0, 1, 0);
                        },
            {
                                type = "ball_turret";
				subentity_key = "dreadnaught_ball_turret_type1";
				position = (100.25, 79.0, -72.0);
				orientation = (1, 1, 0, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (0.0, -152.1, 574.0);
                                orientation = (1, 0, 1, 0);
                        },
            {
                                type = "ball_turret";
				subentity_key = "dreadnaught_ball_turret_type1";
				position = (0.0, -152.1, 574.0);
				orientation = (1, 1, 0, 0);
			},
            {
                                type = "ball_turret";
				subentity_key = "dreadnaught_ball_turret_type1";
				position = (0.0, -152.1, 111.5);
				orientation = (1, 0, 1, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (0.0, -152.1, 111.5);
                                orientation = (1, 1, 0, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (0.0, -152.1, -344.1);
                                orientation = (1, 1, 0, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (0.0, -100.3, -696.8);
                                orientation = (1, 1, 0, 0);
			},
            {
                                type = "ball_turret";
                                subentity_key = "dreadnaught_ball_turret_type1";
                                position = (0.0, -100.3, -696.8);
                                orientation = (1, 0, 1, 0);
			},
            {
                                is_dock = "true";
                                subentity_key = "dreadnaught_dock_type2";
                                position = (0.0, -90.4, 672.2);
                                orientation = (1, 0, 0, 0);
                        }
		);
                "forward_weapon_type" = "WEAPON_MILITARY_LASER";
                "thrust" = 3.5;
        };
        "dreadnaught_ball_turret_type1" =
	{
                "ai_type" = "dreadnaughtBallTurretAI.plist";
		"model" = "dreadnaughtballturrettype1.dat";
		"smooth" = "yes";
		"materials" = "dreadnaughtBallTurretType1.png";
		"name" = "Dreadnaught Ball Turret Type 1";
		"roles" = "dreadnaught-ball-turret";
		"thrust" = 1;
		"weapon_energy" = 50;
        };
        "dreadnaught_ball_turret_type2" =
        {
                "ai_type" = "dreadnaughtBallTurretAI.plist";
                "model" = "dreadnaughtballturrettype2.dat";
                "smooth" = "yes";
                "materials" = "dreadnaughtBallTurretType2.png";
                "name" = "Dreadnaught Ball Turret Type 2";
                "roles" = "dreadnaught-ball-turret";
                "thrust" = 1;
                "weapon_energy" = 50;
        };
        "dreadnaught_dock_type1" =
        {
		"ai_type" = "nullAI.plist";
                "materials" = "dreadnaughtDockType1.png";
		"model" = "dreadnaughtdocktype1.dat";
		"name" = "Dreadnaught Dock Type 1";
		"roles" = "Dreadnaught-dock-type1";
	};
        "dreadnaught_dock_type2" =
        {
		"ai_type" = "nullAI.plist";
                "materials" = "dreadnaughtDockType2.png";
		"model" = "dreadnaughtdocktype2.dat";
		"name" = "dreadnaught-dock-type2)";
		"roles" = "dreadnaught-dock-type2";
	};
        "Dreadnaught SunBat Fighter" =
        {
              "ai_type" = "dreadnaughtFighterInterceptAI.plist";
              "laser_color" = "blueColor";
              "like_ship" = "SunBat";
              "model" = "sunbat.dat";
                 "materials" = {
	              "SunBat.png" = {
		             "diffuse_map" = "SunBat-fighter.png";
                                     };
                           };
                 "name" = "dreadnaught-sunbat-fighter";
             "roles" = "dreadnaught-fighter";
             "script" = "dreadnaught-fighter.js";
         };
         "dreadnaught-andricodred" = {
		"like_ship" = "dreadnaught-type2";
                "materials" = "dreadnaught_type2.png";
		"model" = "dreadnaught_type2.dat";
		"name" = "Dreadnaught - Andricodred";
		"roles" = "dreadnaught dreadnaught-andricodred";
        };     
}
I do see what you did different in the .js, but am still not quite understanding why it should be that way, especially when it appears to me that I defined the roles correctly in the shipdata.plist. Maybe I didn't though, eh? I thought I at leas had a handle on shipdata.plists. :roll:
Mandotech Industries Wiki Page.

http://wiki.alioth.net/index.php/User:Mandoman
User avatar
mandoman
---- E L I T E ----
---- E L I T E ----
Posts: 1375
Joined: Thu Apr 28, 2011 3:17 pm

Re: Java Script Error, Ship Is Undefined

Post by mandoman »

I just noticed the frickin' "is_template" where it shouldn't be right after "type = "ball_turret";. I don't know how it got there, but I obviously mistakenly dumped it there. It is now corrected. Why, when I put the oxp code between the "Code" brackets in this forum, does it spew it out completely different than the way I have it in the actual plist? So many questions, so little brains. :mrgreen:

Maaan, now I'm finding one mistake, after another in the shipdata.plist. I think I had better take a closer look at everything. It doesn't seem to matter how long it takes me to put something together, I still end up fixing more problems than I thought would appear. :)
Mandotech Industries Wiki Page.

http://wiki.alioth.net/index.php/User:Mandoman
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Java Script Error, Ship Is Undefined

Post by Thargoid »

Code: Select all

"like_ship" = "dreadnaught-type1";

Code: Select all

"Dreadaught Type 1" =
Spot the difference ;)

The like_ship refers to the top level key of the template entity (your "DreadNaught Type 1" above). Hence the

Code: Select all

ERROR: one or more shipdata.plist entries have like_ship references that cannot be resolved: dreadnaught-andricodred, dreadnaught-andricothere
as you're trying to reference a ship template ("dreadnaught-type1") that techinically doesn't exist.

One of the first things to learn about Javascript (and all other) language programming is to be exact in your naming, including all punctuation and capitalisation.

You've also defined "defense_ship_role" = "dreadnaught-battleship"; for one of them, but there are no ships in the plist which have that role defined. There may be other glitches too, but one thing at a time ;)[/color]
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: Java Script Error, Ship Is Undefined

Post by Eric Walch »

Thargoid wrote:
that's not how concat works. It is used to join two arrays together into one - see here for an example of how it operates.
concat not only merges two arrays, but also puts the result in a new array and leaves the original array intact. In the behemoth use I am effectively just copying the array into a new one (and not adding anything to it).
Somehow I never could find a JS copy command and this command did the copying also.
User avatar
mandoman
---- E L I T E ----
---- E L I T E ----
Posts: 1375
Joined: Thu Apr 28, 2011 3:17 pm

Re: Java Script Error, Ship Is Undefined

Post by mandoman »

Thargoid wrote:

Code: Select all

"like_ship" = "dreadnaught-type1";

Code: Select all

"Dreadaught Type 1" =
Spot the difference ;)

The like_ship refers to the top level key of the template entity (your "DreadNaught Type 1" above). Hence the

Code: Select all

ERROR: one or more shipdata.plist entries have like_ship references that cannot be resolved: dreadnaught-andricodred, dreadnaught-andricothere
as you're trying to reference a ship template ("dreadnaught-type1") that techinically doesn't exist.

One of the first things to learn about Javascript (and all other) language programming is to be exact in your naming, including all punctuation and capitalisation.



You've also defined "defense_ship_role" = "dreadnaught-battleship"; for one of them, but there are no ships in the plist which have that role defined. There may be other glitches too, but one thing at a time ;)[/color]
Yeah, that last one you mention I was aware might be a mistake when I put it in. I can just change that, as I don't HAVE a battleship at the moment.

I also SEE the difference in your first point, but don't understand it. In a shipdata.plist, doesn't the "like_ship" come BEFORE the ship it refers too? I'm staring at my shipdata.plist entry (one of them) right now, trying to see how what you are saying fits, and I don't see it. The way I use it LOOKS exactly like the same type of reference in "Behemoths" like_ship references. I'm missing something, I know. Behemoths defines two classes of Behemoth, but I notice it has models for sixteen ships. Each of those ships is given a "like_ship" reference to one of the two Behemoth types. I only have two ships, so far, and am working on a third, but it LOOKS like I did the same thing as done in "Behemoths" references. I'm getting dizzy. Okay, I'll study what you are saying, and try to understand, because I know you know the right of it. Sorry I'm so dense. :oops:
Mandotech Industries Wiki Page.

http://wiki.alioth.net/index.php/User:Mandoman
Post Reply