Excruciating FOCS doubts

Creation, discussion, and balancing of game content such as techs, buildings, ship parts.

Moderators: Oberlus, Committer

Message
Author
User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Excruciating FOCS doubts

#16 Post by Geoff the Medio »

If you script something and it doesn't appear in game, first thing to do is check the client log file for relevant errors. If I paste your script into ST_COATING.focs.txt and put it in the scripting/ship_parts/stealth directory, then start the client, the log contains:

Code: Select all

17:34:12.876545 {0x00005aa8} [error] client : reportparseerror.cpp:92 : C:/Users/Geoff/Desktop/FOSDK11/FreeOrion/default\scripting/ship_parts\Stealth\ST_COATING.focs.txt:4:18: Parse error.  Expected string here:
Part
    name = "ST_COATING_GG"
    description = "ST_COATING_GG_DESC"
    exclusions = [[ST_COATING_GG]]
                  ^
    mountableSlotTypes = Internal
    buildcost = 2 * (1 +
    (1 - (GameRule name = "RULE_SHIP_PART_BASED_UPKEEP")) * (
        (0.01 * ShipDesignsOwned empire = Source.Owner) +
        (0.01 * ShipDesignsInProduction empire = Source.Owner)) +

17:34:12.881049 {0x00005aa8} [warn] client : parse.cpp:526 : A parser failed while parsing "C:/Users/Geoff/Desktop/FOSDK11/FreeOrion/default\scripting/ship_parts\Stealth\ST_COATING.focs.txt"
It doesn't recognized [[ST_COATING_GG]] as a string, because there is no ST_COATING_GG macro defined. Changing the [[]] to "" and saving, I get

Code: Select all

17:39:57.330146 {0x0000603c} [error] client : reportparseerror.cpp:92 : C:/Users/Geoff/Desktop/FOSDK11/FreeOrion/default\scripting/ship_parts\Stealth\ST_COATING.focs.txt:5:4: Parse error.  Expected unnamed-rule here:
Part
    name = "ST_COATING_GG"
    description = "ST_COATING_GG_DESC"
    exclusions = "ST_COATING_GG"
    mountableSlotTypes = Internal
    ^
    buildcost = 2 * (1 +
    (1 - (GameRule name = "RULE_SHIP_PART_BASED_UPKEEP")) * (
        (0.01 * ShipDesignsOwned empire = Source.Owner) +
        (0.01 * ShipDesignsInProduction empire = Source.Owner)) +
    (GameRule name = "RULE_SHIP_PART_BASED_UPKEEP") * (
That's not very helpful for an error message, but I suspect it's because there's no part class or capacity scripted. Pasting in

Code: Select all

    class = Stealth
    capacity = 20
from another stealth part, I get

Code: Select all

17:42:36.764861 {0x00003d18} [error] client : reportparseerror.cpp:92 : C:/Users/Geoff/Desktop/FOSDK11/FreeOrion/default\scripting/ship_parts\Stealth\ST_COATING.focs.txt:31:39: Parse error.  Expected unnamed-rule here:
    effectsgroups = [
        EffectsGroup
            scope = Source
            activation = ContainedBy And [
                System 
                Contains Planet type = Gas_Giant
                                       ^
            ]
            accountinglabel = "GAS_GIANT_FIELD_STEALTH"
            effects = SetStealth value = Value + 20
            stackinggroup = "STEALTH_GG_STACK"
which is due to "Gas_Giant" not being a valid planet type. I searched for "Planet type =" in other .focs.txt files and found a relevant example, so correct it to "Planet type = GasGiant".

Another error complains about stackinggroup being in the wrong place, so I move it before effects =. Then another search to realize it should be before accountinglabel.

Then there are no errors in the log and it shows up in the pedia.

User avatar
LienRag
Cosmic Dragon
Posts: 2148
Joined: Fri May 17, 2019 5:03 pm

Re: Excruciating FOCS doubts

#17 Post by LienRag »

Thanks !
Where are the log files?
I searched for them in the snap folder and in /var/log and they're in neither (or at least I couldn't find them)...

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Excruciating FOCS doubts

#18 Post by Geoff the Medio »

LienRag wrote: Wed Jul 01, 2020 3:34 amWhere are the log files?
see: https://www.freeorion.org/index.php/Config.xml

FOCS parse errors are also output to stdout when launching the client.

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Excruciating FOCS doubts

#19 Post by Ophiuchus »

LienRag wrote: Wed Jul 01, 2020 3:34 am Thanks !
Where are the log files?
I searched for them in the snap folder and in /var/log and they're in neither (or at least I couldn't find them)...
Somewhere in the snap dir in your home directory.
Like ~/snap/freeorion or similar. Maybe ~/.snap
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Excruciating FOCS doubts

#20 Post by Oberlus »

This piece of code:

Code: Select all

            priority = [[CONCENTRATION_CAMP_PRIORITY]]
            effects = [
                SetPopulation value = min(Value, Target.Population - 3)
                SetIndustry value = Target.TargetIndustry
            ]
It is executed near the end of the effects processing, after all (relevant) SetTargetPopulation and SetPopulation effects.
Would this work too?

Code: Select all

                SetPopulation value = max(0, Value - 3)
What's the difference between using "Target.<meter>" and "Value" (of the meter to be changed)?
Is Target.<meter> the value of the meter at the start of the turn, dismissing all the changes made previously in SetPopulation effects?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Excruciating FOCS doubts

#21 Post by Geoff the Medio »

Oberlus wrote: Tue Oct 27, 2020 9:50 amWhat's the difference between using "Target.<meter>" and "Value" (of the meter to be changed)?
Is Target.<meter> the value of the meter at the start of the turn, dismissing all the changes made previously in SetPopulation effects?
Yes; Target.Population should be the initial value of the meter on the current turn, while Value (when setting the target's Population meter) or Value(Target.Population) should be the instantateous value of the meter being modified that may depend on effects exectued since the last meter back propagation / during the current round of meter executions.

User avatar
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Excruciating FOCS doubts

#22 Post by Oberlus »

I need some help:


If I write

Code: Select all

        EffectsGroup
            scope = Object id = Source.PlanetID
            activation = Species
            priority = [[TARGET_POPULATION_AFTER_SCALING_PRIORITY]]
            accountinglabel = "TIDAL_LOCK_LABEL"
            effects = SetTargetPopulation value = Value + Target.HabitableSize 
                        * (NamedReal name = "TIDAL_LOCK_TARGET_POPULATION_PERSIZE" value = -1)
I get

Code: Select all

master-testing-build/default/scripting/specials/planet/TIDAL_LOCK.focs.txt:26:12: Parse error.  Expected unnamed-rule here:

        EffectsGroup
            scope = Object id = Source.PlanetID
            activation = Species
            priority = 14
            accountinglabel = "TIDAL_LOCK_LABEL"
            ^
            effects = SetTargetPopulation value = Value + Target.HabitableSize 
                        * (NamedReal name = "TIDAL_LOCK_TARGET_POPULATION_PERSIZE" value = -1)

    ]
    graphic = "icons/specials_huge/tidal_lock.png"
If I put accountinglabel after the effects (or is it within the effects?) it doesn't complain:

Code: Select all

        EffectsGroup
            scope = Object id = Source.PlanetID
            activation = Species
            priority = [[TARGET_POPULATION_AFTER_SCALING_PRIORITY]]
            effects = SetTargetPopulation value = Value + Target.HabitableSize 
                        * (NamedReal name = "TIDAL_LOCK_TARGET_POPULATION_PERSIZE" value = -1)
            accountinglabel = "TIDAL_LOCK_LABEL"
Is accountinglabel a property of effects and not of EffectsGroup?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Excruciating FOCS doubts

#23 Post by Geoff the Medio »

priority should be after accountinglabel, like:

Code: Select all

        EffectsGroup
            scope = Planet
            accountinglabel = "BLD_MILITARY_COMMAND"
            priority = [[VERY_EARLY_PRIORITY]]
            effects = [
                SetMaxDefense value = Value + 5
                SetMaxTroops value = Value + 6
            ]

I don't know why accountinglabel after effects isn't an error.

User avatar
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Excruciating FOCS doubts

#24 Post by Oberlus »

Geoff the Medio wrote: Sun Nov 01, 2020 4:50 pm I don't know why accountinglabel after effects isn't an error.
Maybe SetTargetMeter or effects can have accountinglabel? I think, but I can't find right now, I have seen this structure:

Code: Select all

effects = [ 
    SetThis ... accountinglabel ...
    SetThat ... accountinglabel ...
]

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 13587
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: Excruciating FOCS doubts

#25 Post by Geoff the Medio »

Oberlus wrote: Sun Nov 01, 2020 4:59 pmMaybe SetTargetMeter or effects can have accountinglabel?
That's probably it.

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Excruciating FOCS doubts

#26 Post by Ophiuchus »

Geoff the Medio wrote: Sun Nov 01, 2020 5:08 pm
Oberlus wrote: Sun Nov 01, 2020 4:59 pmMaybe SetTargetMeter or effects can have accountinglabel?
That's probably it.
AFAICR you can have different effects in an effectsgroup with different accountinglabels
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Excruciating FOCS doubts

#27 Post by Oberlus »

Looks like I'm again in the same place, but now priority/accountinglabel ordering isn't the culprit:

This code

Code: Select all

        EffectsGroup
            scope = Source
            activation = Planet
            stackinggroup = "POPULATION_TROOPS_STACK"
            accountinglabel = "DEF_ROOT_DEFENSE"
            priority = [[TARGET_EARLY_BEFORE_SCALING_PRIORITY]]
            effects = SetMaxTroops Value = Value + Target.Population
                        * (NamedReal name = "BASIC_DEFENSE_TROOPS_MAX_TROOPS_PERPOP"
                                     value = 1.0 * [[TROOPS_PER_POP]])
gives me this runtime error on game start:

Code: Select all

09:32:04.229945 {0x00007fdf81e68700} [error] client : ReportParseError.cpp:92 : master-testing-build/default/scripting/species/SP_RAAAGH.focs.txt:902:22: Parse error.  Expected unnamed-rule here:
            scope = Source
            activation = Planet
            stackinggroup = "POPULATION_TROOPS_STACK"
            accountinglabel = "DEF_ROOT_DEFENSE"
            priority = 98
            effects = SetMaxTroops Value = Value + Target.Population
                      ^
                        * (NamedReal name = "BASIC_DEFENSE_TROOPS_MAX_TROOPS_PERPOP"
                                     value = 1.0 * 0.2)
The error comes from the capitalization of first "Value". This works:

Code: Select all

            effects = SetMaxTroops value = Value + Target.Population
I'm quite confused about capitalization conventions in FOCS.
I had a look at PR#3210 but it's too confusing for me. Is there a way to learn about this?

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Excruciating FOCS doubts

#28 Post by Ophiuchus »

Oberlus wrote: Thu Nov 05, 2020 8:58 am I'm quite confused about capitalization conventions in FOCS.
I had a look at PR#3210 but it's too confusing for me. Is there a way to learn about this?
Before that PR, FOCS parsing was case-insensitive, but evaluation was often case-sensitive. Now also the parsing is case-sensitive. I left a comment there with the conventions, but i should also add it to the wiki somewhere.

* labels/parameter names lowercase (e.g. name = "BLA", buildcost)
* definition names CamelCase (e.g. ShipDesign)
* containers are CamelCase Source, Target, *Candidate
* valuerefs are CamelCaseID - e.g. Source.X, Target.DesignID - also immediate value flags Value and Value()
* arithmetic operations are lowercase (abs,min,max, ceil, round, cos, log, sign...) - may be these should be different. Max(enums) is not treated as arithmetics but like valuerefs.
* conditionas are CamelCase, e.g. Ship, HasSpecialSinceTurn
* effects are CamelCase, e.g. SetEmpireMeter
* statistics are CamelCase - e.g. Statistics Max
* And, Or, Not
* Enums are CamelCase: Hostile, Tiny, GasGiant, Basic,...
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

User avatar
Oberlus
Cosmic Dragon
Posts: 5715
Joined: Mon Apr 10, 2017 4:25 pm

Re: Excruciating FOCS doubts

#29 Post by Oberlus »

Thank you, Ophiuchus.
My smoketest had passed successfully but I was able to find an instance of "NOT" in Eccentric Orbit (probably from my several rebases and conflict resolutions).
If that didn't fail, is it because there was no Eccentric Orbit special in the galaxy to trigger the effect? Shouldn't parsing detect that regardless of the presence of the triggering special?

Ophiuchus
Programmer
Posts: 3433
Joined: Tue Sep 30, 2014 10:01 am
Location: Wall IV

Re: Excruciating FOCS doubts

#30 Post by Ophiuchus »

Oberlus wrote: Thu Nov 05, 2020 9:20 am Thank you, Ophiuchus.
My smoketest had passed successfully but I was able to find an instance of "NOT" in Eccentric Orbit (probably from my several rebases and conflict resolutions).
If that didn't fail, is it because there was no Eccentric Orbit special in the galaxy to trigger the effect? Shouldn't parsing detect that regardless of the presence of the triggering special?
probably parsing did fail partially
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Look, ma... four combat bouts!

Post Reply