Scripters cove
Moderators: winston, another_commander
Re: Scripters cove
I wonder if it is a bad interaction between the condition script and the requires setup. Try temporarily removing the condition script and see if the equipment appears for sale. If so you may need to move the equipment requirements also into the script.
I haven't yet tried the condition script in my OXPs but it could be that the two restrictions are interfering with one another.
I haven't yet tried the condition script in my OXPs but it could be that the two restrictions are interfering with one another.
My OXPs via Boxspace or from my Wiki pages
.
Thargoid TV
Dropbox Referral Link
![Very Happy :D](./images/smilies/icon_biggrin.gif)
Thargoid TV
Dropbox Referral Link
Re: Scripters cove
The problem is that passenger berths are not equipment in the same way as every other piece of equipment in the game, and are never considered to be present by the
Since you have a condition script anyway, the simplest workaround is probably to remove the check from
requires_equipment
checks. Since you have a condition script anyway, the simplest workaround is probably to remove the check from
requires_equipment
, and check for it in the condition script instead.Code: Select all
this.allowAwardEquipment = function(eqKey, ship, context) {
if (eqKey == "EQ_IN_SYSTEM_TAXI_LICENCE" && player.ship.passengerCapacity == 0)
return false;
if (player.ship.dockedStation.hasRole("taxi_station"))
return true;
else return false;
}
Re: Scripters cove
Thanks, that's the way to go then.
- JazHaz
- ---- E L I T E ----
- Posts: 2991
- Joined: Tue Sep 22, 2009 11:07 am
- Location: Enfield, Middlesex
- Contact:
Re: Scripters cove
I'm trying to make an equipment item, and have made an equipment.plist. However it's not appearing in the game. Not getting any errors in my log. The only thing I can think of being wrong is the EQ entry. Can I make up my own EQ names?
Note for testing purposes I have dropped the tech level and price.
Note for testing purposes I have dropped the tech level and price.
Code: Select all
(
(
1,
100000,
"Behemoth Base Lease",
"EQ_BEHEMOTH_BASE_LEASE",
"Lease of a Behemoth from the Navy",
{
"available_to_NPCs" = no;
"available_to_player" = yes;
"isPortableBetweenShips" = true;
}
)
)
- Commander McLane
- ---- E L I T E ----
- Posts: 9520
- Joined: Thu Dec 14, 2006 9:08 am
- Location: a Hacker Outpost in a moderately remote area
- Contact:
Re: Scripters cove
Your missing the
available_to_all
key. Without it, you'd have to define it as an optional equipment in your current ship's shipyard.plist (and in all other ships' shipyard.plist).- JazHaz
- ---- E L I T E ----
- Posts: 2991
- Joined: Tue Sep 22, 2009 11:07 am
- Location: Enfield, Middlesex
- Contact:
Re: Scripters cove
Ah thanks. I was wondering about that key.
Re: Scripters cove
I want to check if certain key exists in a descriptions.plist. At the moment I'm doing something like this:
Not exactly a clean solution,
as using expandDescription seems to thrown a JS warning. Is there some nice elegant way to do this check?
Code: Select all
var key = expandDescription("[foo]");
if (key == "[foo]")
//key not found
![Very Happy :D](./images/smilies/icon_biggrin.gif)
Behaviour of the Timer
Hi all,
I modified my copy of the [wiki]Imperial Star Destroyer[/wiki]. I gave it 4 Thargoid Lasers, made it much more robust and less agile and so on
I am now also trying to give the Star Destroyer a chance of becoming a big explosion when it get's destroyed, by placing a Q-Bomb (or more precisely: a ship with role "energy-bomb") at it's last position. But the Q-Bomb I add doesn't detonate, although my Q-Mine-Detector raises an alarm. So I thought to myself "
hmm, maybe the Q-Bomb gets instantly destroyed by the explosion of the Star Destroyer?
Let's add it after a short delay, so the explosion has run off!"
But placing a timer inside the script for the Star Destroyer (I called it's
So I changed the code and moved the timing functionality into a new world script (
stardestroyer, which is the
Note that this calls "$starDestroyer_BigBang" with countdown = 5.
stardestroyer_worldscript:
Note that this creates a timer which is supposed to call "$starDestroyer_BigBang" again after 5 seconds (countdown), but this time with countdown = 0!
But, from my logfiles I get this:
As you can see, the second call to "$starDestroyer_BigBang", which I intended to be made after a delay of 5 seconds, is instead be done instantly, when the Timer is created!
Is this behaviour intentionally or a bug? I thought the function call that is given as parameter to the timer is called for the first time after the delay has passed...![Question :?:](./images/smilies/icon_question.gif)
Also, did you notice any other errors or wrong assumptions I've made?![Question :?:](./images/smilies/icon_question.gif)
What I'm gonna test next is if it works when I move the timer creation to another function.
I modified my copy of the [wiki]Imperial Star Destroyer[/wiki]. I gave it 4 Thargoid Lasers, made it much more robust and less agile and so on
![Twisted Evil :twisted:](./images/smilies/icon_twisted.gif)
![Rolling Eyes :roll:](./images/smilies/icon_rolleyes.gif)
![Question :?:](./images/smilies/icon_question.gif)
But placing a timer inside the script for the Star Destroyer (I called it's
this.name = "stardestroyer"
) didn't work, so I thought that is because the ship is destroyed and with it the timer get's removed.So I changed the code and moved the timing functionality into a new world script (
this.name = "stardestroyer_worldscript"
. I wanted to add only a single function, so I made it that the Timer calls the same function that created him again, but with a different parameter. Here is the code:stardestroyer, which is the
script = "stardestroyer.js"
from shipdata.plist:
Code: Select all
this.name = "stardestroyer";
this.author = "GGShinobi";
this.copyright = "© 2013 GGShinobi, Creative Commons: attribution, non-commercial, sharealike.";
this.description = "some special actions for the stardestroyer.";
this.version = "0.0.0";
"use strict";
this.shipDied = function(whom, why) {
// if (Math.random() > 0.77) {
worldScripts.stardestroyer_worldscript.$starDestroyer_BigBang(this.ship.position, 5); //3.33);
// }
}
stardestroyer_worldscript:
Code: Select all
this.name = "stardestroyer_worldscript";
this.author = "GGShinobi";
this.copyright = "© 2013 GGShinobi, Creative Commons: attribution, non-commercial, sharealike.";
this.description = "some special actions for the stardestroyer.";
this.version = "0.0.0";
"use strict";
this.$selfDestructCountdown;
this.$starDestroyer_BigBang = function(position, countdown) {
log("Star Destroyer", "starDestroyer_BigBang called: position" + position + " / countdown: " + countdown);
if (countdown > 0) {
player.commsMessage("detonation in " + countdown + " seconds!");
this.$selfDestructCountdown = new Timer(this, $starDestroyer_BigBang(position, 0), countdown);
} else {
player.commsMessage("Warning! Explosion detected!");
system.addShips("energy-bomb", 1, position, 0);
// system.addShips("EQ_QC_MINE", 1, this.ship.position, 0);
this.$selfDestructCountdown.stop(); this.$selfDestructCountdown.delete();
}
}
But, from my logfiles I get this:
Code: Select all
05:58:22.015 [Star Destroyer]: starDestroyer_BigBang called: position(39892, -85261.1, 456021) / countdown: 5
05:58:22.015 [Star Destroyer]: starDestroyer_BigBang called: position(39892, -85261.1, 456021) / countdown: 0
05:58:22.033 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (stardestroyer 0.0.0): TypeError: this.$selfDestructCountdown is undefined
05:58:22.033 [script.javaScript.exception.unexpectedType]: /home/ggshinobi/.Oolite/AddOns/stardestroyerV1.3.oxp/Scripts/stardestroyer_worldscript.js, line 18.
Is this behaviour intentionally or a bug? I thought the function call that is given as parameter to the timer is called for the first time after the delay has passed...
![Question :?:](./images/smilies/icon_question.gif)
Also, did you notice any other errors or wrong assumptions I've made?
![Question :?:](./images/smilies/icon_question.gif)
What I'm gonna test next is if it works when I move the timer creation to another function.
忍 knowing that enough is enough, you'll always have enough.
Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
- Wildeblood
- ---- E L I T E ----
- Posts: 2409
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
Re: Scripters cove
The problem could be that timebombAI isn't being started. It expects to be launched from a ship, not instantiated out of nothing. But perhaps not, I don't know anything about the AIs. Anyway, make sure you know what you need to do to make timebombAI start and detonate correctly, before you start to write any script. It certainly shouldn't need both world and ship scripts.
Re: Scripters cove
Unfortunately the second script has several errors in it, mainly that it's structure isn't correct. The structure should be the function name as the definition line (the
You can see however that the second script (the worldScript) doesn't use that structure, hence the error that the function you're trying to set up isn't defined.
But anyway, you don't need the worldscript at all to do this. An energy bomb action is usually done via the AI command
So the simplest way is to take your initial script, and adjust it to
where
However here I would also say that personally I find such actions very annoying, and with a chance of 77% any such ship would get swiftly removed from my ooniverse. There used to be another OXP ship (whose name I forget as it's a long while ago) which tended to become a cascade explosion when shot up, and it extremely quickly became frustrating as the clouds and devastation were too common and screwed with gameplay by destroying too much of the system infrastructure. It very quickly went into the bit-bucket...[/color]
this.myFunctionName = function(myParameters)
part) with the actual code making up that function within the {} braces. You can see the structure in the first script (ignoring for a moment that part of it is commented out, presumably to temporarily disable the randomness for testing purposes) with the function being used being this.shipDied
and the code to be run just below it. You can see however that the second script (the worldScript) doesn't use that structure, hence the error that the function you're trying to set up isn't defined.
But anyway, you don't need the worldscript at all to do this. An energy bomb action is usually done via the AI command
becomeEnergyBlast
, so you need to either spawn a suitable entity (an energy bomb) or switch the ships AI to that of such a bomb. In this case as you're trying to make the action happen on death, the second action won't work as of course it will be dead and removed before the AI actions can fully take effect.So the simplest way is to take your initial script, and adjust it to
Code: Select all
this.shipDied = function(whom, why) {
if (Math.random() > 0.77) {
this.ship.spawn("energy-bomb",1);
}
energy-bomb
is one of the roles of the trunk q-bomb. Use that function definition to replace the one in your first script, keeping the header information (this.name etc) from your code above.However here I would also say that personally I find such actions very annoying, and with a chance of 77% any such ship would get swiftly removed from my ooniverse. There used to be another OXP ship (whose name I forget as it's a long while ago) which tended to become a cascade explosion when shot up, and it extremely quickly became frustrating as the clouds and devastation were too common and screwed with gameplay by destroying too much of the system infrastructure. It very quickly went into the bit-bucket...[/color]
My OXPs via Boxspace or from my Wiki pages
.
Thargoid TV
Dropbox Referral Link
![Very Happy :D](./images/smilies/icon_biggrin.gif)
Thargoid TV
Dropbox Referral Link
- Eric Walch
- Slightly Grand Rear Admiral
- Posts: 5536
- Joined: Sat Jun 16, 2007 3:48 pm
- Location: Netherlands
Re: Scripters cove
Purple Haze probably. I removed the code lines from the script. Without knowing how to do, I probably would have eradicated the ship also from my universe. But, the main problem was there probably that there was no delay, so you has no chance of getting into safety. Yesterday, it just happened that a random hits target turned 'blue'. There I did escape and it stays fun. A good delay timer in combination with a warning (message or a blinking mine lolipop) may help to not delete the oxp a.s.a.p.Thargoid wrote:....any such ship would get swiftly removed from my ooniverse. There used to be another OXP ship (whose name I forget as it's a long while ago) which tended to become a cascade explosion when shot up, and it extremely quickly became frustrating as the clouds and devastation were too common and screwed with gameplay by destroying too much of the system infrastructure. It very quickly went into the bit-bucket...
![Smile :)](./images/smilies/icon_smile.gif)
UPS-Courier & DeepSpacePirates & others at the box and some older versions
Re: Scripters cove
Thanks Wildeblood and Thargoid for your answers and the solution, I will try that! But I still don't understand what's going on:
Maybe I'm wrong, but I understand that the cause for the error message
is as follows:
![Very Happy :D](./images/smilies/icon_biggrin.gif)
Btw, the chance that I "hit the reactor core" is only 33% not 77% - or am I wrong at this, too?
EDIT: Please don't forget that spara also asked a question (which I can't answer):
Thargoid wrote:You can see however that the second script (the worldScript) doesn't use that structure, hence the error that the function you're trying to set up isn't defined.
this.$selfDestructCountdown
is not a function, but a global variable.. at least that's what I intended. ![Confused :?](./images/smilies/icon_confused.gif)
Maybe I'm wrong, but I understand that the cause for the error message
this.$selfDestructCountdown is undefined
is as follows:
- upon dying, the ship calls
worldScripts.stardestroyer_worldscript.$starDestroyer_BigBang(this.ship.position, 5);
This call succeeds, as you can see from the output
05:58:22.015 [Star Destroyer]: starDestroyer_BigBang called: position(39892, -85261.1, 456021) / countdown: 5
- inside
$starDestroyer_BigBang
, the testif (countdown > 0)
succeds, therefore
this.$selfDestructCountdown = new Timer(this, $starDestroyer_BigBang(position, 0), countdown);
is executed, meaning the variable is being assigned a new Timer. - Mysteriously, the function specified inside the timer is called immediately and not, as I intended, after 5 seconds. You can see that from this output:
05:58:22.015 [Star Destroyer]: starDestroyer_BigBang called: position(39892, -85261.1, 456021) / countdown: 0
which shows that the timestamp is the same as the one from the previous call. - this second call to
$starDestroyer_BigBang
has countdown == 0 as parameter, therefore the test fails and the else-branch is being executed. This includes the cleanUp for the timer:
this.$selfDestructCountdown.stop(); this.$selfDestructCountdown.delete();
- then, for some other mysterious reason, a few moments later, something else tries to use the variable / the Timer, but it has already been deleted, which causes the error message
this.$selfDestructCountdown is undefined
![Question :?:](./images/smilies/icon_question.gif)
I thought theThargoid wrote:But anyway, you don't need the worldscript at all to do this. An energy bomb action is usually done via the AI commandbecomeEnergyBlast
, so you need to either spawn a suitable entity (an energy bomb) or switch the ships AI to that of such a bomb.
system.addShips("energy-bomb", 1, position, 0);
would do the trick - thought the added ship came with it's AI... ![Rolling Eyes :roll:](./images/smilies/icon_rolleyes.gif)
![Question :?:](./images/smilies/icon_question.gif)
Don't worry, I'm just doing some customizations for my own pleasure - the stardestroyer, as it comes shipped, is no real threat as long as you stay out of its' turret range. But I want to fear it!Eric Walch wrote:Purple Haze probably. I removed the code lines from the script. Without knowing how to do, I probably would have eradicated the ship also from my universe. But, the main problem was there probably that there was no delay, so you has no chance of getting into safety. Yesterday, it just happened that a random hits target turned 'blue'. There I did escape and it stays fun. A good delay timer in combination with a warning (message or a blinking mine lolipop) may help to not delete the oxp a.s.a.p.Thargoid wrote:....any such ship would get swiftly removed from my ooniverse. There used to be another OXP ship (whose name I forget as it's a long while ago) which tended to become a cascade explosion when shot up, and it extremely quickly became frustrating as the clouds and devastation were too common and screwed with gameplay by destroying too much of the system infrastructure. It very quickly went into the bit-bucket...
![Twisted Evil :twisted:](./images/smilies/icon_twisted.gif)
![Very Happy :D](./images/smilies/icon_biggrin.gif)
Btw, the chance that I "hit the reactor core" is only 33% not 77% - or am I wrong at this, too?
![Shocked :shock:](./images/smilies/icon_eek.gif)
if (Math.random() > 0.77)
EDIT: Please don't forget that spara also asked a question (which I can't answer):
spara wrote:I want to check if certain key exists in a descriptions.plist. At the moment I'm doing something like this:Not exactly a clean solution,Code: Select all
var key = expandDescription("[foo]"); if (key == "[foo]") //key not found
as using expandDescription seems to thrown a JS warning. Is there some nice elegant way to do this check?
忍 knowing that enough is enough, you'll always have enough.
Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
- Commander McLane
- ---- E L I T E ----
- Posts: 9520
- Joined: Thu Dec 14, 2006 9:08 am
- Location: a Hacker Outpost in a moderately remote area
- Contact:
Re: Scripters cove
First, simply typing a random combination of letters (even if it starts with "this.") into a script at some place doesn't turn that random combination of letters into a global variable. Assigning a value to it would turn it into a variable:GGShinobi wrote:this.$selfDestructCountdown
is not a function, but a global variable.. at least that's what I intended.![]()
Code: Select all
this.$selfDestructCountdown = 0;
this.$selfDestructCountdown = false;
this.$selfDestructCountdown = "This is a string.";
this.$selfDestructCountdown = [125433.67, 86753242.44674, 1234234.367];
Second, why would you even need a global variable in the first place? It doesn't serve any discernible purpose. You're (re-)defining it a couple of lines later as a timer (which is something else than a variable) anyway.
Third, then your timer calls the function that defines itself. In other words, what your timer does is to define another new timer with the same name after
countdown
seconds, which then goes on to define another new timer with the same name after countdown
seconds, which then goes on to define another new timer with the same name after countdown
seconds, which then goes on to define another new timer with the same name after countdown
seconds, ad infinitum. That doesn't make any sense at all.- Wildeblood
- ---- E L I T E ----
- Posts: 2409
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
Re: Scripters cove
It does actually work though. I've done it before when I was in a hurry. But it's not something I'd leave in a script other people would see.Commander McLane wrote:Third, then your timer calls the function that defines itself. In other words, what your timer does is to define another new timer with the same name aftercountdown
seconds, which then goes on to define another new timer with the same name aftercountdown
seconds, which then goes on to define another new timer with the same name aftercountdown
seconds, which then goes on to define another new timer with the same name aftercountdown
seconds, ad infinitum. That doesn't make any sense at all.
![Mr. Green :mrgreen:](./images/smilies/icon_mrgreen.gif)
Re: Scripters cove
Whoops, then I was actually mistaken there. I'm still learning JavaScript, and I thought that writingCommander McLane wrote:First, simply typing a random combination of letters (even if it starts with "this.") into a script at some place doesn't turn that random combination of letters into a global variable. Assigning a value to it would turn it into a variableGGShinobi wrote:this.$selfDestructCountdown
is not a function, but a global variable.. at least that's what I intended.![]()
this.$selfDestructCountdown
would be a variable declaration. Thanks for pointing out my mistake! Does JavaScript treat this line as a function call, then? ![Question :?:](./images/smilies/icon_question.gif)
Initially, the code was much simpler. In the beginning, I had no world script at all. What you see is the final result in a long line of trial and error, and declaring the variable outside of the function was my attempt to make sure that it still existed when the Timer countdown recursively called the same function again.Commander McLane wrote:Second, why would you even need a global variable in the first place? It doesn't serve any discernible purpose. You're (re-)defining it a couple of lines later as a timer (which is something else than a variable) anyway.
I think you are mistaken here. If you look closely at the line that creates the new TimerCommander McLane wrote:Third, then your timer calls the function that defines itself. In other words, what your timer does is to define another new timer with the same name aftercountdown
seconds, which then goes on to define another new timer with the same name aftercountdown
seconds, which then goes on to define another new timer with the same name aftercountdown
seconds, which then goes on to define another new timer with the same name aftercountdown
seconds, ad infinitum. That doesn't make any sense at all.
Code: Select all
this.$selfDestructCountdown = new Timer(this, $starDestroyer_BigBang(position, 0), countdown);
What I'm still wondering about is: Why is the function that I pass to the timer as parameter seemingly called immediately, and not, as I intended, after the countdown (5 seconds) has passed?
![Question :?:](./images/smilies/icon_question.gif)
I'll test the "spawn" instead of "addShips" now
![Smile :)](./images/smilies/icon_smile.gif)
忍 knowing that enough is enough, you'll always have enough.
Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
Running Oolite 1.77 on Ubuntu Linux 12.04 LTS