Oolite Bulletins

For information and discussion about Oolite.
It is currently Sat Nov 25, 2017 12:19 am

All times are UTC




Post new topic  Reply to topic  [ 816 posts ]  Go to page Previous 151 52 53 54 55 Next
Author Message
 Post subject: Re: Scripting requests
PostPosted: Thu May 21, 2015 4:13 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4015
Quote:
I have this code:
Code:
var shipdata = Ship.shipDataForKey(my_shipkey);
Now, shipdata has a condition_script set for it. I want to run the "allowSpawnShip" function to check whether it's OK to create a ship with this key. But how to I execute the function?
I can't think of any way you could do that at the moment. The shipdata entry just tells you the name of the condition script source file - it doesn't give you a reference to the running script created from that source.

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
 Post subject: Re: Scripting requests
PostPosted: Thu May 21, 2015 4:23 pm 
Offline
Commodore
Commodore
User avatar

Joined: Tue Jan 21, 2014 10:37 pm
Posts: 1806
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...
Ah. Oh well. Thanks for the prompt response!

_________________
My OXP's


Top
   
 Post subject: Re: Scripting requests
PostPosted: Thu May 21, 2015 4:40 pm 
Offline
Commodore
Commodore
User avatar

Joined: Tue Jan 21, 2014 10:37 pm
Posts: 1806
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...
Could I use "setScript" on some ship in the system (say, the main station) to briefly set the script, run the function and then reset it?

_________________
My OXP's


Top
   
 Post subject: Re: Scripting requests
PostPosted: Thu May 21, 2015 4:51 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4015
Quote:
Could I use "setScript" on some ship in the system (say, the main station) to briefly set the script, run the function and then reset it?
I would strongly advise using a disposable entity - hide an alloy plate at 10^13 metres from the sun, or something - rather than anything which might have a meaningful script on it, for that sort of trick. Resetting the script afterwards won't reset the values of any variables (which can include event handlers, of course) changed since load, and nor will it re-run shipSpawned or similar events if that's needed to set up other parts of the script.

Anyway, that would work in terms of granting access to the condition script's initial method definitions, and in many cases that's enough, but won't work in the general case because the condition script might have its own internal state, and creating a copy of it won't copy that internal state.

Condition scripts could also have conditions based on external environment - time, mission variables, state variables in other scripts, who else is currently in-system - so if you're doing this for the traffic reports, you might find that the condition script reports one value when you try to schedule a launch for a few days time, and another value when you actually get around to launching it.

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
 Post subject: Re: Scripting requests
PostPosted: Fri May 22, 2015 4:08 am 
Offline
Commodore
Commodore
User avatar

Joined: Tue Jan 21, 2014 10:37 pm
Posts: 1806
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...
I'm running this code in order to get a list of ships currently docking with a station:
Code:
//-------------------------------------------------------------------------------------------------------------
// returns an array of ships currently attempting to dock at the station
this.$getShipsDocking = function(station) {
    function $isDocking(entity)
    {
        return entity.isShip && entity.isPiloted && !entity.isStation && entity.dockingInstructions && entity.dockingInstructions.station == station;
    }
    return system.filteredEntities(this, $isDocking, station, 25600); // <<-- this is line 3369
}
But I'm starting to see this error:
Code:
14:01:07.381 [gnustep]: 2015-05-22 14:01:07.381 oolite[1632] src/Core/Scripting/OOJavaScriptEngine.m:2176  Assertion failed in OOJSObjectGetterImplPRIVATE.  Invalid parameter not satisfying: context != NULL && object != NULL && requiredJSClass != NULL && outObject != NULL

14:01:07.474 [script.javaScript.exception.ooliteDefined]: ***** JavaScript exception (StationDockControl 0.3.0): Error: Native exception: src/Core/Scripting/OOJavaScriptEngine.m:2176  Assertion failed in OOJSObjectGetterImplPRIVATE.  Invalid parameter not satisfying: context != NULL && object != NULL && requiredJSClass != NULL && outObject != NULL
14:01:07.474 [script.javaScript.exception.ooliteDefined]:       ../AddOns/StationDockControl.oxp/Scripts/stationdockcontrol.js, line 3369.
Any ideas on what I'm doing wrong here? I don't get the error all the time, only sometimes.

_________________
My OXP's


Top
   
 Post subject: Re: Scripting requests
PostPosted: Fri May 22, 2015 4:51 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4015
Quote:
I'm running this code in order to get a list of ships currently docking with a station:Any ideas on what I'm doing wrong here? I don't get the error all the time, only sometimes.
It should fail with a more helpful error than that (and will, in tonight's build), but doing a quick bit of experimentation I would guess that you are sometimes calling that function with station = null. If you log the value of station shortly before the call, that should tell if that's what's happening or not.

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
 Post subject: Re: Scripting requests
PostPosted: Fri Jun 19, 2015 2:09 am 
Offline
Competent
Competent
User avatar

Joined: Wed Jun 09, 2010 3:56 pm
Posts: 40
Here's one out of left field (and maybe I'm not the first to suggest it)...

What are the odds of getting system.ID and player.ship.galaxyCoordinatesInLY made read/write?


Top
   
 Post subject: Re: Scripting requests
PostPosted: Fri Jun 19, 2015 6:16 am 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4015
Quote:
What are the odds of getting system.ID and player.ship.galaxyCoordinatesInLY made read/write?
Virtually zero in that sense - they're essentially derived values that can't meaningfully be written to.

There might be a more practical way to do what you're trying to achieve by writing to them, though.

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
 Post subject: Re: Scripting requests
PostPosted: Sat Sep 05, 2015 7:52 pm 
Offline
Above Average
Above Average

Joined: Sun Jan 01, 2006 3:50 pm
Posts: 27
Hi,

I was looking into OXP programming again and am still missing this functionality:
Code:
setShipProximityAlertForPlayer( distance )
setShipProximityAlertForRole(distance, primaryRole)
event handler:
Code:
shipProximityAlert = function(who)
The first two functions would setup when the event handler would be called. The event handler would be called whenever a ship gets closer than a certain distance.

This would enable a lot of nice extensions: AI that doesn't let you in close range, ships won't let you sneak up behind them and kill them in one salvo, proximity infractions near the station when hindering another ship, playing tag in space, having races near pylons in space, etc.

Is anything like this achievable right now?


Top
   
 Post subject: Re: Scripting requests
PostPosted: Sat Sep 05, 2015 8:39 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4015
Quote:
The event handler would be called whenever a ship gets closer than a certain distance.
For this to be an event handler it would need to every frame check the distance to every other ship: that's quite expensive especially if there's a lot of objects in system and many of them are carrying out these checks.

What the core game does to do the same sort of thing is in the priority AI:
- the AI calls ship.checkScanner() (generally as a preconfiguration after all "urgent" priorities like "currently in a fight" have been rejected)
- the AI checks the results for ships meeting certain criteria (they have to be in the ship's scanner range by definition, but you could require them to be even closer in the criteria check) and acts accordingly if any are found.

Something which would probably be reasonably quick if you did need very frequent checks:
- in a timer every ten seconds use ship.checkScanner() to get a list of nearby ships: this shouldn't generally need running faster
- in a faster timer (every 0.25 seconds should be enough for most checks, which is the fastest repeat a timer can have), check the distances to the ships in the list

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
 Post subject: Re: Scripting requests
PostPosted: Sat Sep 05, 2015 9:09 pm 
Offline
Above Average
Above Average

Joined: Sun Jan 01, 2006 3:50 pm
Posts: 27
Quote:
Quote:
The event handler would be called whenever a ship gets closer than a certain distance.
For this to be an event handler it would need to every frame check the distance to every other ship: that's quite expensive especially if there's a lot of objects in system and many of them are carrying out these checks.
As you stated, it wouldn't have to be processed every frame, but only every 300 frames (5 seconds) or every 600 frames (10 seconds) by the main loop. Furthermore, if it's done in Objective C with a callback, it'll be more efficient than in Javascript with a timer. That's why I was hoping for a callback function instead of coding a timer and check in javascript.


Top
   
 Post subject: Re: Scripting requests
PostPosted: Sat Sep 05, 2015 10:43 pm 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4015
Quote:
Furthermore, if it's done in Objective C with a callback, it'll be more efficient than in Javascript with a timer.
A timer is a callback, and checkScanner makes the really slow bit (finding entities roughly nearby another entity) happen in Obj-C reasonably quickly, so it should be efficient enough. (Using the JS AI "wake time" event - as the core AIs do - is marginally more efficient than a timer, but I doubt by enough to matter)

The flexibility of the JS approach is also another consideration - you've suggested event handlers restricted by distance and primary role, but there are plenty of other potential filters (legal status, ship armament, cargo carried - to name three used by core AIs) which might be needed. Similarly, some OXP applications might need proximity checks against all objects carried out every 10 seconds while others might want proximity checks against a relatively short list of objects but need them to be done in every frame - or at least considerably more regularly than 5-10 seconds, since a ship on injectors can go 10-20km in that time, and a ship on torus could go 50km or more.

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
 Post subject: Re: Scripting requests
PostPosted: Tue Sep 08, 2015 10:40 pm 
Offline
Above Average
Above Average

Joined: Sun Jan 01, 2006 3:50 pm
Posts: 27
Is it possible to force a ship start firing a weapon (e.g., the forward laser)? It seems that ship only as performAttach() which requires a set target. I just want to turn on and off lasers though without a given target.


Top
   
 Post subject: Re: Scripting requests
PostPosted: Wed Sep 09, 2015 6:50 am 
Offline
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
User avatar

Joined: Fri Nov 11, 2011 6:19 pm
Posts: 4015
Not easily. You can use performScriptedAttackAI and [wiki]OXP_Scripted_AI[/wiki] to put it into a more controlled attack mode, including specifying firing of a particular weapon mount - but it still won't fire if its target isn't roughly in its sights.

It's technically fairly easy to add an option to the scripted AI to force firing even if there's no target in sights, but there are a huge pile of AI interaction implications from allowing a ship to (intentionally!) fire at an object it doesn't have targeted so it would have to be used carefully.

_________________
OXPs: [EliteWiki] New Cargoes, [EliteWiki] Skilled NPCs, [EliteWiki] Curse of the Black Sunspot, and more


Top
   
 Post subject: Re: Scripting requests
PostPosted: Fri Sep 11, 2015 6:06 am 
Offline
---- E L I T E ----
---- E L I T E ----

Joined: Mon May 31, 2010 11:11 pm
Posts: 1963
Firing a missile though isn't as hard. BUT you better give the missile a custom script or it'll instantly go boom from lack-of-target.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 816 posts ]  Go to page Previous 151 52 53 54 55 Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
Powered by phpBB® Forum Software © phpBB Limited