Scripters cove
Moderators: winston, another_commander
- Arexack_Heretic
- 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:
Scripters cove
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.
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!
- Arexack_Heretic
- 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:
Basic temporary status replacement method
The following method should disable legalStatus in anarchy systems, but restore it in lawfull systems.
It contains several comments. (/*) which can be taken out.
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!
- Captain Hesperus
- Grand High Clock-Tower Poobah
- Posts: 2310
- Joined: Tue Sep 19, 2006 1:10 pm
- Location: Anywhere I can sell Trumbles.....
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Sure. You might want to ask Mr. Heretic to test his code, though. Sample code that doesn’t work can be frustrating. :-)Captain Hesperus wrote:Could someone Sticky this and the 'Things I wished I knew...' thread for ease of referencing, please?
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?
E-mail: [email protected]
- Arexack_Heretic
- 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:
Indeed you should, because I haven't.You might want to ask Mr. Heretic to test his code, though. Sample code that doesn’t work can be frustrating.
how did you recognise it?
You are right about that, but before poluting the wiki with spam, it would be better perhaps to discuss stuff here.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?
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!
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
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.Arexack_Heretic wrote:how did you recognise it?
By the way, you can put comments in a plist using /* comment */ syntax (or <!-- comment --> for XML plists).
E-mail: [email protected]
- Arexack_Heretic
- 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:
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
You’ve got the /* and */ the wrong way around in the first comment. Still untested, then. ;-)
E-mail: [email protected]
- Arexack_Heretic
- 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:
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.
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!
- Arexack_Heretic
- 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:
That is what oolite tells me too.Ahruman wrote:I looked at and thought “hey, that’s not a valid plist.”
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!
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
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
}
);
);
}
E-mail: [email protected]
- Arexack_Heretic
- 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:
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.
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!
- Arexack_Heretic
- 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:
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
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.)
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.)
E-mail: [email protected]