In below code i want to award cargo on death of ship. the code works to the extent of setting mission variable but wont award the cargo. I have tried many different permiatations of doing this but cant get it to work. How do i do this?
Many thanks in advance.
should also work and is better as it uses the same casing as the on screen tekst. However it must be player.ship, not player. But even without ship it still should work in current oolite. It only leaves a deprication message in the log. In this case I think something else in your code is wrong and that award line is never executed.
Conditions must have been matched as the mission variable bolts = "stage2"
and mission briefing is initiated upon docking at main station. Cargo hold is empty.
You were quite correct my condition can't of been met. I forgot i also updated missionvariable in shipdata.plist slipped my mind.
Targetdead and witness variable is changed in shipdata.plist in death actions script. Unfortunately doesn't work when using shipdied. Is the reason for this because the this.shipDied is called before the shipdata.plist updates the variables?
Targetdead and witness variable is changed in shipdata.plist in death actions script. Unfortunately doesn't work when using shipdied. Is the reason for this because the this.shipDied is called before the shipdata.plist updates the variables?
No, it is because this.shipDied() only fires when the player dies. To let it fire for that ship, you must give that ship a script of its own. But that death_actions are not executed but must also get handled in shipDied(). And you must check who killed the ship. Look in some oxp's for examples.
Targetdead and witness variable is changed in shipdata.plist in death actions script. Unfortunately doesn't work when using shipdied. Is the reason for this because the this.shipDied is called before the shipdata.plist updates the variables?
No, it is because this.shipDied() only fires when the player dies. To let it fire for that ship, you must give that ship a script of its own. But that death_actions are not executed but must also get handled in shipDied(). And you must check who killed the ship. Look in some oxp's for examples.
For an example look in ups-courier.oxp. and than the upsBoa.js script.
Look at the setInstructionsKey. You use it wrong here. And when not called from within the main script, you must specify the mainscript this instruction belong to.
Originally i thought this.shipDied was an event handler if any ships died. so thanks for clearing that up.
I was unclear after looking at upsBoa.js how oolite knew which ship it was for until i went in shipdata.plist.
So in your shipdata.plist
the last line tells it upsBoa.js is associated with it, is this true?
Yes. ship scripts replace the legacy script actions in ship data. When a script is defined none of deach_actions, launch_actions etc is executed. They all have equivalent js handlers.
The beauty of event handlers is of cause their code is only triggered when needed. This in difference to legacy script that evaluates every bit of code, over and over again. The only trick is of cause to create oolite in a way that every important event triggers such an handler.
And part of the "events" in that boa script are triggered by calls from the AI.
Look also at world_script_handlers
This list only contains the handlers that are also used by the player. Meaning the handlers that can be used in the normal world_script. We miss still a wiki page for NPC only handlers. Or even station-only handlers.
Things starting with player are player only, things starting with ship can also be used in ship scripts.
The last line (script = <whatever>.js) associates the given javascript with that particular ship entity. this.shipDied can be used with any ship, not just the player, as long as it's in the script associated with that ship (if it's just in a general worldscript, then it is associated with the player ship).
If you put this.shipDied into the script for a given ship, then it is triggered when that ship dies. If you want an example of this, look at the constrictor in the trunk shipdata.plist and its associates script ("oolite-constrictor.js").
But if you use a script with a ship, then the shipdata.plist actions (setup_actions, death_actions etc) don't fire, as the script supercedes them.
In your case, I would personally associate a script with your ship, and then use that ship and this.shipDied to set your variables and do your assignment of cargo etc.
Last edited by Thargoid on Sun Aug 16, 2009 6:52 pm, edited 1 time in total.