Help with script Parse Error - Expected unnamed-rule

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Message
Author
User avatar
Cpeosphoros
Space Kraken
Posts: 124
Joined: Sat Jan 30, 2016 11:29 am

Help with script Parse Error - Expected unnamed-rule

#1 Post 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?
All contributions are released under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidelines.

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

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

#2 Post by Geoff the Medio »

IndustryTarget should probably be TargetIndustry

User avatar
Cpeosphoros
Space Kraken
Posts: 124
Joined: Sat Jan 30, 2016 11:29 am

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

#3 Post 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 = 
All contributions are released under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidelines.

Morlic
AI Contributor
Posts: 296
Joined: Tue Feb 17, 2015 11:54 am

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

#4 Post by Morlic »

I guess missing an equals sign after condition.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

User avatar
Cpeosphoros
Space Kraken
Posts: 124
Joined: Sat Jan 30, 2016 11:29 am

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

#5 Post 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.
All contributions are released under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidelines.

Morlic
AI Contributor
Posts: 296
Joined: Tue Feb 17, 2015 11:54 am

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

#6 Post 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.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0

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

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

#7 Post 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.

User avatar
Cpeosphoros
Space Kraken
Posts: 124
Joined: Sat Jan 30, 2016 11:29 am

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

#8 Post 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.
All contributions are released under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidelines.

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

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

#9 Post 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.

User avatar
Cpeosphoros
Space Kraken
Posts: 124
Joined: Sat Jan 30, 2016 11:29 am

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

#10 Post 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
                    ])
            ]
All contributions are released under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidelines.

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

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

#11 Post 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.

User avatar
Cpeosphoros
Space Kraken
Posts: 124
Joined: Sat Jan 30, 2016 11:29 am

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

#12 Post 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.
All contributions are released under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidelines.

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

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

#13 Post 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"?

User avatar
Cpeosphoros
Space Kraken
Posts: 124
Joined: Sat Jan 30, 2016 11:29 am

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

#14 Post 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.
All contributions are released under GPL or LGPL v2 or later, or under appropriate Creative Commons licence, consistent with project guidelines.

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

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

#15 Post 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
Attachments
custom sitrep in game
custom sitrep in game
sitrep.png (83.02 KiB) Viewed 2306 times

Post Reply