Scripters cove

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

Moderators: another_commander, winston

User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
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:

Scripters cove

Post by Arexack_Heretic »

This thread will hopefully become a usefull resourse for scripting

offering interesting methods,

basic (modular) scripts,

and cooperative assistance by the cOomunity for scriptcoders just starting out or experienced ones with a difficult problem.
Riding the Rocket!
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
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:

Basic temporary status replacement method

Post by Arexack_Heretic »

The following method should disable legalStatus in anarchy systems, but restore it in lawfull systems.
It contains several comments. (/*) which can be taken out.

Code: Select all

{
	"temporary_legal_cutout_script" = (
		{
			conditions = (
				"status_string equal STATUS_EXITING_WITCHSPACE",
				"mission_legalStatus_backup equal UNDEFINED"
			);
			do = ();
			else = (
				"setLegalStatus: [mission_legalStatus_backup]",
				"reset: mission_legalStatus_backup"
			);
		},
		{
			conditions = (
				"systemGovernment_string equal Anarchy"
			);
/* conditions could be replaced by anything, example: a set of planet_numbers representing Your_private_Corporate_Emporium. */
			do = (
				{
					conditions = (
						"status_string equal STATUS_EXITING_WITCHSPACE"
					);
					do = (
						"set: mission_legalStatus_backup [legalStatus_number]",
						"setLegalStatus: 0"
					);
				},
/* Can also set credit_number for instance, "Your money is no good in this system Commander". */
				{
					conditions = (
						"status_string equal STATUS_IN_FLIGHT",
						"legalStatus_number morethan 0"
					);
					do = (
						"setLegalStatus: 0"
					);
				}
			);
		}
	);
}
Last edited by Arexack_Heretic on Tue Mar 13, 2007 11:00 pm, edited 11 times in total.
Riding the Rocket!
User avatar
Captain Hesperus
Grand High Clock-Tower Poobah
Grand High Clock-Tower Poobah
Posts: 2312
Joined: Tue Sep 19, 2006 1:10 pm
Location: Anywhere I can sell Trumbles.....

Post by Captain Hesperus »

Could someone Sticky this and the 'Things I wished I knew...' thread for ease of referencing, please?

Captain Hesperus
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 »

Captain Hesperus wrote:
Could someone Sticky this and the 'Things I wished I knew...' thread for ease of referencing, please?
Sure. You might want to ask Mr. Heretic to test his code, though. Sample code that doesn’t work can be frustrating. :-)

Then again, this whole subforum is supposed to be a “useful resource for scripting”. Perhaps the wiki would be a better place for sample code?
User avatar
winston
Pirate
Pirate
Posts: 731
Joined: Mon Sep 27, 2004 10:21 pm
Location: Port St. Mary, Isle of Man
Contact:

Post by winston »

If these tips aren't already in the Wiki, consider making a section for them in the wiki too.
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
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 »

You might want to ask Mr. Heretic to test his code, though. Sample code that doesn’t work can be frustrating. :-)
Indeed you should, because I haven't. :shock:
how did you recognise it?
Then again, this whole subforum is supposed to be a “useful resource for scripting”. Perhaps the wiki would be a better place for sample code?
You are right about that, but before poluting the wiki with spam, it would be better perhaps to discuss stuff here.

Maybe I should append the first post to also state:
"to discuss the best ways and techniques for tackling plist-scripting challenges and propose wiki entries." ?

---

I intend this thread to also be an "ask-the-experts" kind of feature.

---

So what will be the first challenge?

Code the most elegant way to have planets and moons simulate orbitting eachother in a single system?

Code to check what type of ship Player_entity is driving, without resorting to crude methods like adding a custom piece of EQ to each individual ship.?
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 »

Arexack_Heretic wrote:
how did you recognise it?
I looked at and thought “hey, that’s not a valid plist.” It’s one of my amazing programmer superpowers. There are three quotation marks missing in the first conditions= line, for instance.

By the way, you can put comments in a plist using /* comment */ syntax (or <!-- comment --> for XML plists).
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
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 »

Ha! you are right, by Giles!
I wrote it on the train to Rotterdam, while nursing a hangover.
But that is no excuse for my poor re-typing it here. ;)

thanks for the plist-comment code, that is one of those things that needs to be added to the wiki. :D

<editing script now> :arrow:
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 »

You’ve got the /* and */ the wrong way around in the first comment. Still untested, then. ;-)
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
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 »

yes.
and: "drat!", edit-re-re-corrected back wrongly. :duh:

funny thing though that morethan and greaterthan are both accepted... logical arguments?
---
maybe agree to some format rules.
post only checked, working code in codeboxes.
WIP or unchecked suggestions in blue.
questions in red?

---
OK.
As a personal challenge, I'm going to try to script trader convoys.
The biggest challenge will be to do it elegantly. ;)
Riding the Rocket!
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
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 »

Ahruman wrote:
I looked at and thought “hey, that’s not a valid plist.”
That is what oolite tells me too. :(
Unfortunately, I cannot find any more missing parentheses and such.

edit: Found the buggers.
I'm not used to coding in ASCII.
I used }, everywhere to close segments, whereas it is only needed if two condition-sets are in the same layer.
Only need to test it 'live' in an anarchy. It's a bit late though; have been beavering away at that Convoy I promised. I decided to use it as an introductionary script for the PPC-Alt2. (hunts nicely in packs!)
Unfortunately something gets busted someplace, it doesn't work with a simple test-script.
Last edited by Arexack_Heretic on Tue Mar 13, 2007 10:58 pm, edited 1 time in total.
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 »

As it stands, it validates according to OS X’s parser. There are a couple of trailing commas which might possibly cause problems, though. Change the end to:

Code: Select all

      }
   );
);
}
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
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 »

actually the biggest challenge (in convoy!) is to get the method 'spawn' to work at all.

Isn't it supposed to generate the called ship randomly closeby it's caller?


If the new-entity is being spawned at coordinates from caller 0/0/0, as MacLane suggests, then I would propose to the code-monkeys an additional variable that sets the spawn distance from caller in a sphere...
"spawn: <role> <#> <min_radius> <max_radius>"
with 0 as defaultvalues (maybe name it spawnInRange?)

or perhaps more handy even:
"spawnPrecisely: <role> x y z W X Y Z"
spawning as a quaternion, orientation and origin relative to 'caller' number spawned always 1.
this emulates the script/shipdata method of 'hard'coding the spawninglocations and orientations of entities.
Riding the Rocket!
User avatar
Arexack_Heretic
Dangerous Subversive Element
Dangerous Subversive Element
Posts: 1878
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 »

NSDictionary or plist:

are there utilities around (for WIN/DOS) that can validate or check these files automatically?

I'm getting Murghitis. :(
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 »

Quite probably not. The best bet would seem to be ProjectCenter, the primary GNUstep developer tool. The discuss-gnustep mailing list mentioned on their Getting Help page would be a good page to ask.

Apple’s implementation of property lists provides some validation support and is open source, so building a simple validator shouldn’t be too hard. I’ll look into getting a better definition of “shouldn’t be too hard” tomorrow. If it works out, it’ll be a command-line tool which tells you things like “error on line 47: expected ;" (only one error before bailing).

There are cases where property lists that work on OS X don’t work in GNUstep, but they’re relatively unusual. (We had this problem with logcontrol.plist.) As source for both is available under GPL-compatible languages, standardising on one of them for Oolite is possible in principle but fiddly in practice.

(If we used the OS X one, it could probably simply replace the standard parser, but it’s written in C and relies on a concept called “toll-free bridging” to provide ObjC objects efficiently; it may be possible to hack this into GNUstep, but it’d probably be problematic and would require someone with a good grasp of how the Objective-C runtime works – that’d be me – to work with it on Windows or Linux. To use the GNUstep version, we’d have to change all uses of the many plist-loading methods in Oolite, because the GNUstep one can’t deal with the binary format used for instance by the preference system… or port binary property lists to GNUstep. Actually, I thought of a third path, but I’ll have to look through the Apple implementation to see if it’s tractable.)
Post Reply