Page 1 of 118
Scripters cove
Posted: Sun Mar 11, 2007 6:18 pm
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.
Basic temporary status replacement method
Posted: Sun Mar 11, 2007 6:22 pm
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"
);
}
);
}
);
}
Posted: Sun Mar 11, 2007 7:19 pm
by Captain Hesperus
Could someone Sticky this and the 'Things I wished I knew...' thread for ease of referencing, please?
Captain Hesperus
Posted: Sun Mar 11, 2007 8:05 pm
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?
Posted: Sun Mar 11, 2007 10:05 pm
by winston
If these tips aren't already in the Wiki, consider making a section for them in the wiki too.
Posted: Mon Mar 12, 2007 10:36 am
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.
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.?
Posted: Mon Mar 12, 2007 12:00 pm
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).
Posted: Mon Mar 12, 2007 12:22 pm
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.
<editing script now>
Posted: Mon Mar 12, 2007 1:41 pm
by JensAyton
You’ve got the /* and */ the wrong way around in the first comment. Still untested, then. ;-)
Posted: Mon Mar 12, 2007 1:44 pm
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.
Posted: Tue Mar 13, 2007 12:23 pm
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.
Posted: Tue Mar 13, 2007 4:39 pm
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:
Posted: Sat Mar 17, 2007 3:05 pm
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.
Posted: Sat Mar 17, 2007 5:36 pm
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.
Posted: Sat Mar 17, 2007 11:44 pm
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.)