Macros!
Moderator: Oberlus
Macros!
Will macros be able take "paramteters," like C function-like macros? This would probably be a useful feature for macros.
Also, just how far away from an interactive space combat system are we? From looking around at old dev logs, it seems we already have a basic engine down.
Also, just how far away from an interactive space combat system are we? From looking around at old dev logs, it seems we already have a basic engine down.
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13603
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Features for post v0.4
I've committed a basic but functional macro, or text substitution, mechanism for content script files. It works much like the equivalent substitution mechanism for stringtables. For example, I can add to space_monster_spawn_fleets.txt a macro definition:eleazar wrote:2) Macros
Code: Select all
LOCATION_NO_MONSTER_AND_NOT_WITHIN_2
'''location = And [
Not Contains Monster
Not WithinStarlaneJumps 2 Contains And [
Planet
OwnedBy AnyEmpire
]
]'''
I can insert the macro text by referencing the label:
Code: Select all
MonsterFleet
name = "SM_FLOATER"
ships = [
"SM_FLOATER"
]
spawnrate = 0.7
spawnlimit = 50
[[LOCATION_NO_MONSTER_AND_NOT_WITHIN_2]]
This was the best syntax for defining and inserting macros that I could think of, and was chosen because ''' should not be otherwise needed in a script file, and this format and delimiter is already used for multi-line stringtable entries. The ''' surrounding the macro text are needed, even for single-line macros, to differentiate macro definitions from normal script file contents. If another suggested format is better, things can be changed.
Presently macro text cannot contain macro insertions, though I plan to add this capability (again, much like stringtable nested references).
- eleazar
- Design & Graphics Lead Emeritus
- Posts: 3858
- Joined: Sat Sep 23, 2006 7:09 pm
- Location: USA — midwest
Re: Features for post v0.4
Sweet.
EDIT:
"Macros may be used anywhere in and only in the same file as they are defined."
Is that a "just the way i first implemented it" thing, or part of the big plan?
I can foresee for example a player's personal species being created or saved in a separate text file. For simplicity, and to survive updates, i'd think we'd want a single set of standard macros to be used for both.
EDIT:
"Macros may be used anywhere in and only in the same file as they are defined."
Is that a "just the way i first implemented it" thing, or part of the big plan?
I can foresee for example a player's personal species being created or saved in a separate text file. For simplicity, and to survive updates, i'd think we'd want a single set of standard macros to be used for both.
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13603
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Features for post v0.4
There could be one or more general-use macro definition files, but I think a more powerful additoin would be a mechanism to insert the whole text of one file into another (much like the C++ #include preprocessor command) file before processing it. The inserted text would be added before macro processing, so could include macro definitions.eleazar wrote:Is that a "just the way i first implemented it" thing, or part of the big plan?
However, I'm a bit concerned that adding too many mechanisms of this sort starts to make things harder to read and follow (through several files of macro references) and (in the case of parameters into macros) makes things more complicated to write and understand without being a programmer...
Re: Features for post v0.4
Would it be useful to maintain a tree graphic, showing the basic relationship of script files, to aid new volunteers?
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13603
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Features for post v0.4
Perhaps, but that sort of documentation tends to not actually be maintained very well, even if initially set up with good intentions.Adrian wrote:Would it be useful to maintain a tree graphic, showing the basic relationship of script files, to aid new volunteers?
-
- Space Kraken
- Posts: 143
- Joined: Sat Jun 11, 2011 1:27 am
- Location: Modesto, CA USA
Re: Features for post v0.4
Maybe some comments at the top of the script files saying which files they are involved in....Geoff the Medio wrote:Perhaps, but that sort of documentation tends to not actually be maintained very well, even if initially set up with good intentions.Adrian wrote:Would it be useful to maintain a tree graphic, showing the basic relationship of script files, to aid new volunteers?
Re: Features for post v0.4
Yes, good point; i trust your long term experience on this.Geoff the Medio wrote:Perhaps, but that sort of documentation tends to not actually be maintained very well, even if initially set up with good intentions.
I'll see if i can tackle one of the minor tasks/improvements to get a feel for python and the txt files. Just need to make sure Dart00_Tech isn't working on that particular part too
- eleazar
- Design & Graphics Lead Emeritus
- Posts: 3858
- Joined: Sat Sep 23, 2006 7:09 pm
- Location: USA — midwest
Re: Features for post v0.4
Either way addresses my concerns.Geoff the Medio wrote:There could be one or more general-use macro definition files, but I think a more powerful additoin would be a mechanism to insert the whole text of one file into another (much like the C++ #include preprocessor command) file before processing it. The inserted text would be added before macro processing, so could include macro definitions.eleazar wrote:Is that a "just the way i first implemented it" thing, or part of the big plan?
Well, based on my only partly applicable experience with Wesnoth macros, it could be confusing when something got messed up, and a macro was called before the text that defined it was read, or something like that.Geoff the Medio wrote:However, I'm a bit concerned that adding too many mechanisms of this sort starts to make things harder to read and follow (through several files of macro references) and (in the case of parameters into macros) makes things more complicated to write and understand without being a programmer...
But generally speaking, it made things more approachable, and readable. If a macro is clearly labeled, it is easier for somebody to read, understand and use: "[[LOCATION_NO_MONSTER_AND_NOT_WITHIN_2]]" than the actual scripting that makes it up. Quite a lot of Wesnoth's important scripting is handled by macros, and some of the macros (for terrain for instance) are so complicated that only a handful really understand what's going on. In other words, a lot of people just use macros for many things blissfully unaware of the underlying scripting, and often unable to read it if they tried. I don't think that's a bad thing.
Wesnoth allowed parameters in there macros, but i have no opinion if they are needed for FO.
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13603
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Features for post v0.4
As implemented now, FO macros do not depend on where they are defined, as long as it's in the same file. They can all be at the end, before they are referenced, or mixed through the text of the file; it shouldn't matter. The macros are all read and stored, and their definitions replaced by whitespace, which subsequent actual parsing ignores.eleazar wrote:...it could be confusing when something got messed up, and a macro was called before the text that defined it was read...
Having parameters would make macros a lot more powerful, but would also be much more likely to result in very complicated macros that are hard to understand....some [Wesnoth's] macros (for terrain for instance) are so complicated that only a handful really understand what's going on.[...]
Wesnoth allowed parameters in there macros, but i have no opinion if they are needed for FO.
Once you get a build of FO that allows recursive macros and start using them, see if you find yourself wanting to use parameters. I suspect they'll be felt necessary quite quickly...
For example, [[LOCATION_NO_MONSTER_AND_NOT_WITHIN_2]] is good, but you'd presently need to define a whole separate macro for [[LOCATION_NO_MONSTER_AND_NOT_WITHIN_3]] whereas a parameter would be obviously useful to specify the range.
There's a potential workaround without parameters, which would be to have two macros, one of which has all the text up to the place where the 2 appears, and another that has all the text after that, and then you'd use [[MACRO_BEFORE_NUMBER]]2[[MACRO_AFTER_NUMBER]] to effectively create your own parametrized macros without built-in support for it, but that would be awkward in anything but simple cases.
- eleazar
- Design & Graphics Lead Emeritus
- Posts: 3858
- Joined: Sat Sep 23, 2006 7:09 pm
- Location: USA — midwest
Re: Features for post v0.4
excellent.Geoff the Medio wrote:As implemented now, FO macros do not depend on where they are defined, as long as it's in the same file. They can all be at the end, before they are referenced, or mixed through the text of the file; it shouldn't matter.
Could be. I'm very eager to macro-ify and diversify the species, it will be my top FO priority. But for the next week, i'll be on a family vacation, so i may disappear from FO for much/all of that time.Geoff the Medio wrote:Once you get a build of FO that allows recursive macros and start using them, see if you find yourself wanting to use parameters. I suspect they'll be felt necessary quite quickly...
I like to think that there will be a strong correspondence between the individual macros used for species, and the species picks we eventually will have. But i haven't closely looked at much of the scripting in species.txt. The way stuff interrelates may make that much more difficult than i wish. But the hope is to allow players to mostly create a custom species via standardized macros, without needing to understand effects.
-
- Space Kraken
- Posts: 143
- Joined: Sat Jun 11, 2011 1:27 am
- Location: Modesto, CA USA
Re: Features for post v0.4
Haha, Nah, Im just working on attempting to refine the English string-table. Im currently waiting on a deciion if my last edit will be committed or not...in the mean time im working on some more icons....I was thinking about playing with the AI a bit maybe next...Also the v.4 Quick Start guide is in need of updates from v.3....Adrian wrote:Just need to make sure Dart00_Tech isn't working on that particular part too
Re: Features for post v0.4
Have fun and get some rest When you're back, well rested and re-energized, a new FO build (with macros) is waiting for you!eleazar wrote:...Could be. I'm very eager to macro-ify and diversify the species, it will be my top FO priority. But for the next week, i'll be on a family vacation, so i may disappear from FO for much/all of that time...Geoff the Medio wrote:Once you get a build of FO that allows recursive macros and start using them, see if you find yourself wanting to use parameters. I suspect they'll be felt necessary quite quickly...
- eleazar
- Design & Graphics Lead Emeritus
- Posts: 3858
- Joined: Sat Sep 23, 2006 7:09 pm
- Location: USA — midwest
Re: Macros!
Yah! I stole a little time to try this out...
revision 4667
""First sucessful application of macros. Species EP scripting now macro-ified."
Focus and other sorts of scripting seem to work fine.
But I'm having trouble getting it to work within effects groups. It looks like there might be an bug.
logs and species.txt attached.
revision 4667
""First sucessful application of macros. Species EP scripting now macro-ified."
Focus and other sorts of scripting seem to work fine.
But I'm having trouble getting it to work within effects groups. It looks like there might be an bug.
Code: Select all
2012-02-21 11:25:39,998 ERROR Client : Unresolved macro reference: STANDARD_HEALTH_AND_POPULATION
2012-02-21 11:25:40,006 ERROR Client : /Users/jbjerk/Desktop/FreeOrion.app/Contents/Resources/default/species.txt:157:8: Parse error. Expected EffectsGroup here:
[[STANDARD_HEALTH_AND_POPULATION]]
^
- Attachments
-
- macro-problem.zip
- (11.39 KiB) Downloaded 113 times
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13603
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Macros!
You need to have a newline at the end of the file.