Scripters cove

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

Moderators: winston, another_commander

User avatar
docwild
Dangerous
Dangerous
Posts: 64
Joined: Thu Mar 29, 2007 1:36 pm

Post by docwild »

The AI scripts, (JS), stored in an OXPs script folder. i.e the ship scripts, not the world scripts...

Spawning several stations using the same JS script but differing state machines would I be right in assuming that each station will have its unique copy of the ship Jscript with persistent and seperate properties?

For example: defining the global property on a ship script with something like:

this.property = someValue;

will each station in the system have it's own copy and does the AI script persist or is it reloaded according to game mechanics, resetting everything?

Code: Select all

this.sendComm = function ()
{
	if(this.logging1 && this.updateSent == false)
	{
		log(this.name, "In sendComm... \nplayerDetected = " + this.playerDetectedFlag+"\nupdateSent = " + this.updateSent);
	}	
	if(this.playerDetectedFlag == false && this.updateSent == false)
	{
		if(this.logging1 && this.updateSent == false)
		{
			log(this.name, "sending message...");
		}
		player.consoleMessage("Update....");
		this.updateSent = true;
	}
}
This method is accessed after the entity spawns and is called only once, if the flags persist.

Even though I have several stations in the system, I seem to get only one message. Is this a built in redundancy remover because they are atm identical? Or is it because each station is sharing the script with the same properties?

EDIT: If it is the latter would transferring the flags to the world script work and then access them through:

Code: Select all

worldScripts["scriptName"].propertyName
Thanks.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

Each ship will have a unique copy of the script, with persistence until the ship no longer is valid (destroyed, removed etc).

Don't forget that player (or any other ship) detection under AI is ship scanner range only, so you'll only get messages from multiple stations if they can all detect you (if you're in scanner range of them all). But yes there is also repetition elimination for messages - iirc it's a 6 second window, but don't take that as gospel.

Transferring to a worldScript would possibly make things worse, as there's only one sending point and so the repetition elimination could come into play. If you want to scan at longer range than the entities scanner range, then use the JS scanning functions (System.shipsWithRole etc) rather than the AI ones.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

To get round the redundant message suppression, you can have the stations send two separate messages: instead of 'hello commander, how are you.' you can have each one of them send 'hello commander,' followed by 'how are you.'

Since 'hello commander,' is different from 'how are you', that's enough to fool the not too sophisticated message suppression code that there's a completely new, non-redundant message to be shown on screen.
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Kaks wrote:
Since 'hello commander,' is different from 'how are you', that's enough to fool the not too sophisticated message suppression code that there's a completely new, non-redundant message to be shown on screen.
Or just append a space-character to every odd text broadcast, like the ore-processor does to make sure every splinter sends its text. That extra symbol makes the text already different, but it does not show on screen.

However, generally its a good thing that identical messages are suppressed.
User avatar
docwild
Dangerous
Dangerous
Posts: 64
Joined: Thu Mar 29, 2007 1:36 pm

Post by docwild »

Thanks you three...

I'm using the AI state machine as a hacky timer (game time):

Code: Select all

"NOTHING_FOUND" = ( "sendScriptMessage: playerNotDetected", "pauseAI: 20.0", "setStateTo: IDLE"); 
and then:

Code: Select all

this.playerNotDetected = function() //this is called every 20 seconds that player isnt detected by station
{
	if(this.secondsSinceSpawn == 0)
		this.secondsSinceSpawn = clock.seconds;
	
	var temp = clock.seconds;
	
	var claimedTag = this.returnTag(this.ship);//glad I wrote that function

	if(this.updateSent == false && this.secondsSinceSpawn + this.delay < temp && claimedTag == "OWNED")
	{
		
		this.sendComm();
	}
	this.playerDetectedFlag = false;
}
This allows me to give the effect of a stations update message being delayed proportional to the distance from the player.

Is there another way to acheive timing? The tickle event isn't very reliable and javascript is bad at timed events.

At least this way it is asynchronous and event driven.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6627
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

docwild wrote:
Is there another way to acheive timing? The tickle event isn't very reliable and javascript is bad at timed events.

At least this way it is asynchronous and event driven.
I cannot access the wiki from the office so, unfortunately I cannot provide a link right now, but I recommend you search and read up on the OOJSTimer class in the Javascript section. You can do everything you need that involves timing and very efficiently, too.
User avatar
docwild
Dangerous
Dangerous
Posts: 64
Joined: Thu Mar 29, 2007 1:36 pm

Post by docwild »

another_commander wrote:
I cannot access the wiki from the office so, unfortunately I cannot provide a link right now, but I recommend you search and read up on the OOJSTimer class in the Javascript section. You can do everything you need that involves timing and very efficiently, too.
Thanks, I was under the impression that the timer wasn't implemented yet. There is a lot of legacy stuff on the wiki, I'm getting there, it just takes some getting used to. It seems that the timer is real time so using the clock.(method) for game time can be done seperately but driven off real time events. Yes, that is better than what I had.

You guys are most helpful. My thanks.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

There might well be some out of date bits and bobs all over the wiki.
However, all the files reached from

http://wiki.alioth.net/index.php/Catego ... _Reference

Seem to be fairly up to date. IIRC, Ahruman had a good look at all of them before 1.74 got released.

By the way, just to make sure we're clear about it, the timer is designed to fire in game time, not actual real time...
Last edited by Kaks on Fri Jul 16, 2010 2:46 pm, edited 1 time in total.
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

this.ship.spawnTime (from Entity.spawnTime) may also be useful. It's the game time at which the entity was spawned.

You could also use a timer to just repeat the sending function call every 20s until you stop it (to provide the link A_C couldn't).
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

docwild wrote:
Is there another way to acheive timing? The tickle event isn't very reliable and javascript is bad at timed events.
The tickle event is indeed unreliable and generally nasty. It’s there as a sort of crutch for porting legacy scripts (and potentially automatic translation), but I don’t think there’s ever been a JS script that “benefited” from it in any way. In short, don’t use it.
Kaks wrote:
By the way, just to make sure we're clear about it, the timer is designed to fire in game time, not actual real time...
Like the docs say, game real time. There are two different “game time” time scales.
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

What is the current preferred layout for equipment infos?

Most I see now use open-step format, but I personally prefer XML. (but that's format, not layout)

I mean:
Legacy Equipment.plist was an array without keys with entries for TL, price/10, name, key and description, followed by a dict containing another array with more modern properties. In the wiki for EQ expressions there are now keys for those legacy 5 entries.
Should it be the new standard to include expressions in the dict section of the equipment plist for <key>name</key> <string>Name</string> etcetera?
Riding the Rocket!
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

That’s JavaScript documentation. It doesn’t say anything about equipment.plist entries. A dictionary-only format for equipment entries would be nice in principle, but it doesn’t exist yet.
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1876
Joined: Tue Jun 07, 2005 7:32 pm
Location: [%H] = Earth surface, Lattitude 52°10'58.19"N, longtitude 4°30'0.25"E.
Contact:

Post by Arexack_Heretic »

But the javascript expressions do point towards entries in the plists right?

So, in principle one could write the entire equipment info as a dict... or does oolite still require the five lines I mentioned in above post?

also one should be able to use them as such:

Code: Select all

"Uses javascript expressions in plist"
would become:

Code: Select all

"Uses all javascript expressions as keys in plist dictionary"
Last edited by Arexack_Heretic on Tue Jul 20, 2010 12:10 am, edited 4 times in total.
Riding the Rocket!
User avatar
docwild
Dangerous
Dangerous
Posts: 64
Joined: Thu Mar 29, 2007 1:36 pm

Post by docwild »

A couple more:

Beacon codes: becaonCode and isBeacon are read only and I find myself needing to add a beacon to an already existing station without a beacon. It seems the easiest way to do it is to remove() the entity and replace it with an identical entity which is defined slightly differently in shipdata.plist. So I have roles: slaveMine and slaveMineOwned, one with a beacon code and one without.

Is there a way to switch which dictionary entry applies to an existing object on the fly? If not, what is the effect of removing and replacing an entity which the player is docked at? I could use the shipWillDockWithStation () handler to switch before the ship docks or is it possible to create a station, switch the player to it before removing the original? Can it be switched during the shipWillLaunchFromStation() handler. I know there is a dockPlayer method (or something like that) but does it immediately dock the player or does it engage autopilot docking to said station?

Finally, I'm sure I read somewhere that it's possible, using the debug OXP and jScript console, to reload a worldscript on the fly. I can call the startup method which restarts the script already in memory, but is it possible to edit the script, and reload from within the game using the python debug console on linux?

thanks
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

Arexack_Heretic wrote:
But the javascript expressions do point towards entries in the plists right?
Not really.
Arexack_Heretic wrote:
So, in principle one could write the entire equipment info as a dict...
No.
Arexack_Heretic wrote:
also one should be able to use them as such:
No.
Post Reply