Page 1 of 2

Help with script Parse Error - Expected unnamed-rule

Posted: Sun Jan 31, 2016 3:57 pm
by Cpeosphoros
I'm trying to create a custom SitRep message which would tell me the total Industry Target for all my planets.

Grabbing some code from empire_statistics.txt and the example custom messages, I've put this into custom_sitreps.txt:

Code: Select all

EffectsGroup
    scope = And [
        Capital
        Ownedby empire = Source.Owner
    ]
    activation = Turn low = 0
    effects =
        GenerateSitRepMessage
            message = "Industry Target: %ind_target%."
            label = "CUSTOM_1"
            NoStringtableLookup
            icon = "icons/playing.png"
            parameters = [
                tag = "ind_target" data = 
                    Sum value = LocalCandidate.IndustryTarget condition And [
                        Planet
                        OwnedBy empire = Source.Owner
                    ]
            ]
            empire = Source.Owner
However, instead of giving me the statistics, I get this parse error:

Code: Select all

2016-01-31 13:53:01.904177 [error] Client : ReportParseError.cpp:95 : C:\Program Files (x86)\FreeOrion\default\techs.txt:3725:56: Parse error.  Expected unnamed-rule here:
            label = "CUSTOM_1"
            NoStringtableLookup
            icon = "icons/playing.png"
            parameters = [
                tag = "ind_target" data = 
                    Sum value = LocalCandidate.IndustryTarget condition And [
                                                        ^
                        Planet
                        OwnedBy empire = Source.Owner
                    ]
            ]
            empire = Source.Owner
Can someone tell me what am I doing wrong, please?

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Sun Jan 31, 2016 4:23 pm
by Geoff the Medio
IndustryTarget should probably be TargetIndustry

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Sun Jan 31, 2016 4:32 pm
by Cpeosphoros
Geoff the Medio wrote:IndustryTarget should probably be TargetIndustry
Thanks for the quick answer.

Anyways, now I get this:

Code: Select all

2016-01-31 14:30:35.039550 [error] Client : ReportParseError.cpp:95 : C:\Program Files (x86)\FreeOrion\default\techs.txt:3725:62: Parse error.  Expected unnamed-rule here:
            label = "CUSTOM_1"
            NoStringtableLookup
            icon = "icons/playing.png"
            parameters = [
                tag = "ind_target" data = 
                    Sum value = LocalCandidate.TargetIndustry condition And [
                                                              ^
                        Planet
                        OwnedBy empire = Source.Owner
                    ]
            ]
            empire = 

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Sun Jan 31, 2016 5:04 pm
by Morlic
I guess missing an equals sign after condition.

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Sun Jan 31, 2016 5:18 pm
by Cpeosphoros
Morlic wrote:I guess missing an equals sign after condition.
Same error as before (pointing to the "c" in condition). And I'm pretty sure "condition" syntax doesn't take an equals sign.

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Sun Jan 31, 2016 5:50 pm
by Morlic
Cpeosphoros wrote:I'm pretty sure "condition" syntax doesn't take an equals sign.
In current content files/scripts there are plenty of examples where condition is used with a following equals sign... Anyway, no idea about whatever other error there is.

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Sun Jan 31, 2016 6:06 pm
by Geoff the Medio
Try wrapping (the whole Sum expression) in brackets.

I also suggest starting with something simple, then incrementally adding complexity and making sure it keeps working at each step.

Most / all sitrep data expressions in the existing scripts are pretty simple, not involving a statistic like Sum, so it's possible there's a problem with parsing of statistics within a GenerateSitRepMessage parameters list.

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Mon Feb 01, 2016 2:47 am
by Cpeosphoros
Geoff the Medio wrote:Try wrapping (the whole Sum expression) in brackets.
Did that:

Code: Select all

            parameters = [
                tag = "ind_target" data = 
                    [Sum value = LocalCandidate.TargetIndustry condition And [
                        Planet
                        OwnedBy empire = Source.Owner
                    ]]
            ]
And ended up with a flat out crash on game start up, I don't even get to the "Load Game" panel, with no indication whatsoever in freeorion.log:

Code: Select all

2016-02-01 00:28:53.510903 [debug] Client : Logger initialized
2016-02-01 00:28:53.511905 [debug] Client : v0.4.5+ [build 2016-01-26.4b9a098] MSVC 2013
2016-02-01 00:28:53.511905 [debug] Client : GL Version String: 4.5.0 NVIDIA 359.00
2016-02-01 00:28:53.511905 [debug] Client : Dependency versions from headers:
2016-02-01 00:28:53.511905 [debug] Client : Boost: 1_58
2016-02-01 00:28:53.511905 [debug] Client : FreeType: 2.5.5
2016-02-01 00:28:53.511905 [debug] Client : PNG: 1.6.17
2016-02-01 00:28:53.511905 [debug] Client : Python: 2.7.9
2016-02-01 00:28:53.511905 [debug] Client : SDL: 2.0.3
2016-02-01 00:28:53.511905 [debug] Client : zlib: 1.2.8
2016-02-01 00:28:53.668907 [debug] Client : OpenAL initialized. Version 1.1 ALSOFT 1.15.1Renderer OpenAL SoftVendor OpenAL Community
Extensions: AL_EXT_ALAW AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_LOKI_quadriphonic AL_SOFT_buffer_samples AL_SOFT_buffer_sub_data AL_SOFTX_deferred_updates AL_SOFT_direct_channels AL_SOFT_loop_points AL_SOFT_source_latency

2016-02-01 00:28:53.669408 [error] Client : CUIWnd.cpp:636 : CUIWnd::SaveOptions() : "map.sidepanel" has not been initialized.
(This is the entire log, and, BTW, I think the sidepanel thing has nothing to do with this problem - it's been there all the time).

Also tried with parentehsis instead of brackets:

Code: Select all

            parameters = [
                tag = "ind_target" data = 
                    (Sum value = LocalCandidate.TargetIndustry condition And [
                        Planet
                        OwnedBy empire = Source.Owner
                    ])
            ]
Got the same error as before, expected unnamed-rule, pointing to the "c" in condition.
Geoff the Medio wrote:I also suggest starting with something simple, then incrementally adding complexity and making sure it keeps working at each step.
Yeps, I did that. I'm well acquainted with the concept of incremental development. I had it working with a flat message, and with a parameterized one which did not use statistics.
Geoff the Medio wrote:Most / all sitrep data expressions in the existing scripts are pretty simple, not involving a statistic like Sum, so it's possible there's a problem with parsing of statistics within a GenerateSitRepMessage parameters list.
Well, ok. If we concluded that is the case, then I think this is a bug. Should I register an Issue at Github?

BTW, I want to let it registered that you guys have been doing a very, very good work in building this amazing game. I used to be a Java programmer (changed careers, I'm a lawyer now), and I really can apreciate the amount of dedication and effort that has been devoted to this project.

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Mon Feb 01, 2016 8:32 am
by Geoff the Medio
Cpeosphoros wrote:condition And
You definitely need the = after condition, so anything else you try should have that as well.
Cpeosphoros wrote:parentehsis instead of brackets:
By "brackets" I meant (). Definitely don't put [] around an expression.

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Mon Feb 01, 2016 9:11 am
by Cpeosphoros
Geoff the Medio wrote:
Cpeosphoros wrote:condition And
You definitely need the = after condition, so anything else you try should have that as well.
Cpeosphoros wrote:parentehsis instead of brackets:
By "brackets" I meant (). Definitely don't put [] around an expression.
All right, but still the same error:

Code: Select all

            parameters = [
                tag = "ind_target" data = 
                    (Sum value = LocalCandidate.TargetIndustry condition = And [
                                                               ^
                        Planet
                        OwnedBy empire = Source.Owner
                    ])
            ]

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Mon Feb 01, 2016 9:55 am
by Geoff the Medio
The problem appears to be that it's interpreting the Sum statistic as an integer-valued value reference, so when it gets to LocalCandidate.TargetIndustry, it gets confused because that is not an integer value reference. You can force it to treat the Sum as a double-valued value reference by putting it inside a definitely double-valued expression, like

Code: Select all

                GenerateSitRepMessage
                    message = "Industry Target: %ind_target%."
                    label = "CUSTOM_1"
                    NoStringtableLookup
                    icon = "icons/playing.png"
                    parameters = [
                        tag = "ind_target" data = 0.0 + (Sum value = LocalCandidate.TargetIndustry condition = And [
                            Planet
                            OwnedBy empire = Source.Owner
                        ])
                    ]
                    empire = Source.Owner
This probably still won't work as you expect though, because the tag identifier is irregular... It only recognizes certain tag labels, which it then knows how to handle (eg. as a ship id, as a tech name, ...). You probably want "rawtext" for the tag.

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Mon Feb 01, 2016 6:02 pm
by Cpeosphoros
Right. The parse error went away.

However, now - as you predicted - the SitRep message silently fails to show. No error message anywhere iin the logs, it simply doesn't show.

I can see your point, that the parameter tag is not a safe environment to use statistics, all right. I will drop it now and pursue some other crazy ideas I have in my mind.

I understand that should not be a priority for the dev team at this point of the project, but for the future, I think it would be a reasonable expectation that FOCS would work uniformly in any environment, i.e., all commands, functions, statistics, etc., if syntaticly correct, should work no matter where they are called from.

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Mon Feb 01, 2016 6:13 pm
by Geoff the Medio
Cpeosphoros wrote:However, now - as you predicted - the SitRep message silently fails to show.
Did you try switching the parameter tag to "rawtext"?

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Mon Feb 01, 2016 6:32 pm
by Cpeosphoros
Geoff the Medio wrote:
Cpeosphoros wrote:However, now - as you predicted - the SitRep message silently fails to show.
Did you try switching the parameter tag to "rawtext"?
Yes. Still silently fails.

Re: Help with script Parse Error - Expected unnamed-rule

Posted: Mon Feb 01, 2016 6:41 pm
by Geoff the Medio
Works for me...

In custom_sitreps.txt:

Code: Select all

EffectsGroup
    scope = Source
    effects =
        GenerateSitRepMessage
            message = "Industry Target: %rawtext%."
            label = "CUSTOM_1"
            NoStringtableLookup
            icon = "icons/playing.png"
            parameters = [
                tag = "rawtext" data = 0.0 + (Sum value = LocalCandidate.TargetIndustry condition = And [
                    Planet
                    OwnedBy empire = Source.Owner
                ])
            ]
            empire = Source.Owner