Page 1 of 2

New Ship's Role

Posted: Sun Oct 23, 2011 8:01 pm
by mandoman
I have made a saucer type ship that I was thinking would be a up-to-now unknown to GalCop, the Empire, and the Federation, but have been mortal enemies of the Thargoids for a long time. I call it the UFOship. I would like it to only appear under certain conditions, such as when a certain number of Thargoid ships are present, and then only in a factor of chance. I have the model all worked out, with a dat file, and png, but that's about it. I tried following some scripts, and plists made for Thargoid Warships by other oxpers, but though those ships seem to have no problems, the UFOship doesn't even parse out as an entity. The game keeps insisting their should be a shipyard.plist for the UFOship, but I have no intentions of players having access to owning one. Am I going beyond what I'm allowed to create? It does indicate in Latest.Log:
14:42:13.049 [script.unpermittedMethod]: ***** SCRIPT ERROR: in Test.0.do.1.do.0.conditions.0 ("thargoid_number lessthan 2"), method "thargoid_number" not allowed.
14:42:13.049 [script.unpermittedMethod]: ***** SCRIPT ERROR: in Test.0.do.1.do.1.conditions.0 ("thargoid_number greaterthan 5"), method "thargoid_number" not allowed.
That seems to be in response to the script.plist trying to make the UFOship hunt the Thargoid ships, and any other ship that fires on it. If not fired upon, it will not retaliate, but will always attack any Thargoid ships present. I don't intend for them to be present in all Thargoid encounters, just every now and then, under certain conditions.

Maybe this isn't even a doable project, I don't know. I guess I'm asking if it is doable, and if someone could give it look for me.

I have the UFOship.oxp zipped, and was wondering if anyone with know-how in this type of oxp would take a look at it, and tell me where I've gone wrong. Any help is very much appreciated.

Re: New Ship's Role

Posted: Sun Oct 23, 2011 8:39 pm
by Ironfist
Mandoman,

A bit difficult to say without seeing the full script, but it looks like the process is assuming thargoid_number is the name of a routine rather than a number. This might be true if there is a routine called thargoid_number which checks for the number of thargoid ships in the system. Could you post the full script so we can check the rest of the syntax.

Ironfist

Re: New Ship's Role

Posted: Sun Oct 23, 2011 8:41 pm
by Zieman
Looks like Oolite doesn't "know" what this thargoid_number in your script is.

If you're using JavaScript, you could define a variable called thargoid_number for your script, then the condition could work. Something like:

Code: Select all

this.shipExitedWitchspace = function()
    {
        var thargoid_number = countShipsWithPrimaryRole(thargoid);
     * your other code *
    }
   
* rest of the script *
Meh, I'm not sure about the usage of countShipsWithPrimaryRole function, Thargoid or some other who actually knows something about JS can correct me if I'm wrong here...

Re: New Ship's Role

Posted: Sun Oct 23, 2011 9:37 pm
by mandoman
Ironfist wrote:
Mandoman,

A bit difficult to say without seeing the full script, but it looks like the process is assuming thargoid_number is the name of a routine rather than a number. This might be true if there is a routine called thargoid_number which checks for the number of thargoid ships in the system. Could you post the full script so we can check the rest of the syntax.

Ironfist
Oh sure. Here it is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Test</key>
<array>

<!-- witchspace conditions -->
<dict>
<key>conditions</key>
<array>
<string>status_string equal STATUS_EXITING_WITCHSPACE</string>
</array>
<key>do</key>
<array>
<string>checkForShips: ufoship_ship</string>
<dict>
<key>conditions</key>
<array>
<string>shipsFound_number equal 0</string>
</array>
<key>do</key>
<array>
<dict>
<key>conditions</key>
<array>
<string>thargoid_number lessthan 2</string>
<string>planet_number equal -1</string>
<string>d100_number lessthan 20</string><!-- 20% chance of a ufo_ship in witchspace -->
</array>
<key>do</key>
<array>
<string>addShips: ufo_ship</string>
</array>
</dict>
<dict>
<key>conditions</key>
<array>
<string>thargoid_number greaterthan 5</string>
<string>planet_number equal -1</string>
<string>d100_number lessthan 75</string><!-- 95% chance of a ufo_ship in witchspace -->
</array>
<key>do</key>
<array>
<string>addShips: ufo_ship</string>
</array>
</dict>
</array>
</dict>
</array>
</dict>
</array>
</dict>
</plist>

Like I said, I kind of borrowed that from the Thargoid Carrier oxp, the creator to whom I would of course give credit in the final edition.
Zieman wrote:
Looks like Oolite doesn't "know" what this thargoid_number in your script is.

If you're using JavaScript, you could define a variable called thargoid_number for your script, then the condition could work. Something like:

Code:
this.shipExitedWitchspace = function()
{
var thargoid_number = countShipsWithPrimaryRole(thargoid);
* your other code *
}

* rest of the script *


Meh, I'm not sure about the usage of countShipsWithPrimaryRole function, Thargoid or some other who actually knows something about JS can correct me if I'm wrong here...

Zieman
I could certainly change it to Java Script. I do like Java Script better than the Apple.

Oh, those high percentage numbers will be much reduced, I was just putting it up high to try to trigger the ship appearance, you know, just to see it it WOULD appear.

Re: New Ship's Role

Posted: Mon Oct 24, 2011 3:59 am
by CommonSenseOTB
Mandoman, legacy scripts were obsolete 3 years ago. Does legacy scripting even actually work properly today? Use javascript man, so people can help you and there are so many good examples to study from by opening up oxps and looking. Oh, and what became of your sunbat oxp? All that work for nothing? Svengali has a new oxp out for adjusting textures in-game. You should try it out on the sunbat, make the adjustments and release it. Let people enjoy it! :D

Re: New Ship's Role

Posted: Mon Oct 24, 2011 4:29 am
by Mauiby de Fug
They do indeed still work (is that not why they're called legacy scripts, or have I missed something?), and as far as I know, changes to Oolite are supposed to ensure that this does not change. But it is far more restrictive and incomprehensible, and much much more can be accomplished with Javascript!

Re: New Ship's Role

Posted: Mon Oct 24, 2011 4:37 am
by mandoman
CommonSenseOTB wrote:
Mandoman, legacy scripts were obsolete 3 years ago. Does legacy scripting even actually work properly today? Use javascript man, so people can help you and there are so many good examples to study from by opening up oxps and looking. Oh, and what became of your sunbat oxp? All that work for nothing? Svengali has a new oxp out for adjusting textures in-game. You should try it out on the sunbat, make the adjustments and release it. Let people enjoy it! :D
I did exactly that, though I haven't tried it yet. I'll post Latest.Log report on the attempt after I reload it into the AddOns folder. This is the script.js I made:

this.name = "UFOship Script"
this.author = "mandoman"
this.copyright = "(C) 2011 Me."
this.licence = "CC-NC-by-SA 2.0"
this.description = "Sets all Thargoid ships as primary target.";
this.version = "1.0 alpha 1"
this.UFOshipExitedWitchspace = function(attackthargoidships)
{
var thargoid_number = countShipsWithPrimaryRole(thargoid);
thargoid_numberlessthan2 = 20% chance of a ufoship in witchspace;
thargoid_numbergreaterthan2 = 30% chance of a ufoship in witchspace;
thargoid_numbergreaterthan10 = 70% chance of a ufoship in witchspace
{
Log("Initialising OXP " + name)
}

Well, I want to release the SunBat, but I was hoping to get permission from the author of the Behemoth.oxp to make one of the SunBat functions as a Navy Picket ship. Because it's so hard to see. I haven't heard back from him since he said he would take a look at it. Not sure what to do now. I have it running on my own Oolite game, and the SunBat has shown up in all of the color textures except the Navy Picket texture. I would suppose that means I haven't entered something in correctly, though I get no errors about it on the Latest.Log. I'll have to try out Svengali's texture adjuster, if I can figure out how to make it work. That seems to be about three quarters of the battle for me. It's fun, though. :)

Re: New Ship's Role

Posted: Mon Oct 24, 2011 5:44 am
by Capt. Murphy
I think you'll need two scripts Mandoman. What you've posted definitely won't work as is.

1 worldscript that controls when the UFO will be spawned (by checking for Thargoid numbers on launching from the station or exiting witchspace), and another ship script that will control each UFO finding and targeting the nearest Thargoid ship, which is probably best done in combination with an interlinked unique AI.

Re: New Ship's Role

Posted: Mon Oct 24, 2011 6:45 am
by mandoman
Capt. Murphy wrote:
I think you'll need two scripts Mandoman. What you've posted definitely won't work as is.

1 worldscript that controls when the UFO will be spawned (by checking for Thargoid numbers on launching from the station or exiting witchspace), and another ship script that will control each UFO finding and targeting the nearest Thargoid ship, which is probably best done in combination with an interlinked unique AI.
Yeah, it didn't work, for sure. I opened up the script.js in the Z-Handler.oxp to get some examples, and I came up with this:

this.name = "UFOship Script"
this.author = "mandoman"
this.copyright = "(C) 2011 Me."
this.licence = "CC-NC-by-SA 2.0"
this.description = "Sets all Thargoid ships as primary target.";
this.version = "1.0 alpha 1"

this.shipAttacksThargoids = function(attack);
{
log(this.UFOship, "Will exit from Witchspace:" + UFOship);
if (less than 2 thargoid ships are present === "20% chance")
{
}
}
this.UFOshipWillExitFromWitchspace = function()
{
log(this.UFOship, "Will exit from Witchspace:" + UFOship);
if (more than 2 thargoid ships are present === "30% chance")
{
}
}
this.UFOshipWillExitFromWitchspace = function()
{
log(this.UFOship, "Will exit from Witchspace:" + UFOship);
if (more than 10 thargoid ships are present === "60% chance")
{
}
}
this.UFOshipWillExitFromWitchspace = function()
{
log(this.UFOship, "Will attack thargoid:" + attack.thargoid);
}


this.UFOshipWillAttackThargoid = function()
{
log(this.UFOship, "Will attack missile:" + attack.missile);
if (Missile attacks UFOship === "attack missile")
{
}
{
this.UFOshipWillAttackMissile = function()
{
log(this.UFOship, "Will attack any ship:" + attack.any ship);
if (Any ship attacks UFOship === "attack any ship")
{
}
{
this.UFOshipWillAttackAnyShip = function()
{
log(this.UFOship, "Will enter Witchspace:" + enter.Witchspace);
if (All thargoids are destroyed === "enter Witchspace")
{
}
{
this.UFOshipWillEnterWitchspace = function()

Then I started getting the error reports from Latest.log. It says there is a syntax error in line 8, but from what I can tell, I wrote it very close to a similar command in the Z-Handler script.js. Here are the Latest.log error reports:

01:37:22.057 [shipData.load.begin]: Loading ship data.
01:37:22.559 [shipData.merge.failed]: ***** ERROR: one or more shipdata.plist entries have like_ship references that cannot be resolved: GW-constore
01:37:23.576 [shipData.load.error]: ***** ERROR: the shipdata.plist entry "GW-radars" specifies non-existent model "td-radars.dat".
01:37:25.866 [script.javaScript.exception.syntaxError]: ***** JavaScript exception (UFOship.anon-script): SyntaxError: syntax error
01:37:25.866 [script.javaScript.exception.syntaxError]: /home/mandoman/.Oolite/AddOns/UFOship.oxp/Config/script.js, line 8: this.shipAttacksThargoids = function(attack);
01:37:25.866 [script.javaScript.load.failed]: ***** Error loading JavaScript script /home/mandoman/.Oolite/AddOns/UFOship.oxp/Config/script.js -- compilation failed

I don't know what all that is about the "GW-radars", but the sytaxErrors come right after.

Re: New Ship's Role

Posted: Mon Oct 24, 2011 7:17 am
by another_commander
mandoman, the JS scripts you have presented so far have no chance of working. They are completely non-JS. You will need to take some time to look at the documentation in the wiki referring to scripts and the JavaScript handlers for Oolite. Before even that, I would recommend reading online tutorials about JavaScript, so that you at least get the syntax part right. Blindly copy pasting code does not help, you need to know how things get put together. It will then be much easier for us to help you, too.

Re: New Ship's Role

Posted: Mon Oct 24, 2011 1:24 pm
by mandoman
another_commander wrote:
mandoman, the JS scripts you have presented so far have no chance of working. They are completely non-JS. You will need to take some time to look at the documentation in the wiki referring to scripts and the JavaScript handlers for Oolite. Before even that, I would recommend reading online tutorials about JavaScript, so that you at least get the syntax part right. Blindly copy pasting code does not help, you need to know how things get put together. It will then be much easier for us to help you, too.
OK, thanks.

Re: New Ship's Role

Posted: Mon Oct 24, 2011 10:46 pm
by mandoman
I think I got it, though I'm not sure how to test it. It isn't drawing any unusual attention in Latest.log, other than to list it as installed. No more script errors. I did as recommended, and studied a tutorial on Javascript, and it didn't take long for me to understand what I was doing wrong. Capt. Murphy, I can see what you meant about it not having a chance the way I had it before. I tend to rush into things that are interesting to me, so I get tangled up fairly easily. I actually ended up making a "Scripts" folder, with four different .js scripts. I tried to use the commands as the tutorial suggested, and also by looking at what others had done (there ARE some differences between them, and the tutorial). For one thing, the tutorial I was studying was showing how to use Javascript within HTML, so I kind of had to phase out all the HTML references to understand any of the Java Script commands, and reactions. After a bit, I started changing my .js script, and began to see that just one .js was not going to do it. I had to make a .js for each entity that interacts with the UFOship, as well as one for the UFOship. I came up with UFOship.js, thargoid.js, missile.js, and aggressor.js. After pouring over what I'd done a few million times, I entered it back into AddOns, held the Shift key down, and clicked on Oolite. I then shut it down to look at all the errors I was sure would pop up in Latest.log, and danged if there were any there at all. Now, I know that doesn't mean that the oxp is working perfectly, but I still have to get a handle on how to run that oxp tester. I never yet have been able to look at one of my oxp ships without just running the game in such a way that I could buy the ship, and try it out. More ignorance on my part. I actually enjoy HTML, and Javascript, even if I'm crappy with it. :)

Re: New Ship's Role

Posted: Tue Oct 25, 2011 5:38 am
by Capt. Murphy
Nice one Mandoman - the online JS tutorials are good for understanding the syntax of JS and also the use of it's inbuilt functions (things like Math.random etc).

For Oolite you also need to get your head around around the game engine hooks onto your scripts, which is normally via blocks of code in functions defined under an event handler. Your code is run everytime the event happens in Oolite. For example code to check conditions and spawn a custom role ship would often be found in a...

Code: Select all

this.shipWillExitWitchspace = function()
{
     // Your code here
}

....code block which runs every time the player is about to exit witch space.

You can also have your own functions that are not defined by an Oolite event handler, but their code would normally be called from elsewhere within the script or in the case of a ship script potentially from the AI.plist of that ship.

Re: New Ship's Role

Posted: Tue Oct 25, 2011 9:26 am
by Gimi
Mandoman, without the slightest knowledge of Java-script, I am going to forward some advice that Ahruman seems quite adamant about. Please use unique non-generic names for your scripts and plists. This to avoid conflicts with other OXP's. So rather than "missile.js", use "myoxp_missile.js".

Re: New Ship's Role

Posted: Tue Oct 25, 2011 10:02 am
by Eric Walch
Gimi wrote:
I am going to forward some advice that Ahruman seems quite adamant about. Please use unique non-generic names for your scripts and plists. This to avoid conflicts with other OXP's. So rather than "missile.js", use "myoxp_missile.js".
Same is true for ship keys in shipdata.plist. e.g. when I look in the shipdata of the wip version of 'XeptatisSword', I see keys that are just waiting to generate name conflicts: 'array', 'target', 'projection', 'spike' etc. When two oxps use the same name for their ship reference, only one will load in game and the other will get quite different 'ships' than expected. Or none at all because of other roles in that other oxp.