FreeOrion

Forums for the FreeOrion project
It is currently Sun Oct 22, 2017 6:13 am

All times are UTC




Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Sun Jan 31, 2016 3:57 pm 
Offline
Space Kraken
User avatar

Joined: Sat Jan 30, 2016 11:29 am
Posts: 123
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:
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:
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.


Top
 Profile  
 
PostPosted: Sun Jan 31, 2016 4:23 pm 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12004
Location: Munich
IndustryTarget should probably be TargetIndustry


Top
 Profile  
 
PostPosted: Sun Jan 31, 2016 4:32 pm 
Offline
Space Kraken
User avatar

Joined: Sat Jan 30, 2016 11:29 am
Posts: 123
Geoff the Medio wrote:
IndustryTarget should probably be TargetIndustry


Thanks for the quick answer.

Anyways, now I get this:

Code:
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.


Top
 Profile  
 
PostPosted: Sun Jan 31, 2016 5:04 pm 
Offline
AI Contributor

Joined: Tue Feb 17, 2015 11:54 am
Posts: 222
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


Top
 Profile  
 
PostPosted: Sun Jan 31, 2016 5:18 pm 
Offline
Space Kraken
User avatar

Joined: Sat Jan 30, 2016 11:29 am
Posts: 123
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.


Top
 Profile  
 
PostPosted: Sun Jan 31, 2016 5:50 pm 
Offline
AI Contributor

Joined: Tue Feb 17, 2015 11:54 am
Posts: 222
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


Top
 Profile  
 
PostPosted: Sun Jan 31, 2016 6:06 pm 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12004
Location: Munich
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.


Top
 Profile  
 
PostPosted: Mon Feb 01, 2016 2:47 am 
Offline
Space Kraken
User avatar

Joined: Sat Jan 30, 2016 11:29 am
Posts: 123
Geoff the Medio wrote:
Try wrapping (the whole Sum expression) in brackets.


Did that:
Code:
            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:
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:
            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.


Top
 Profile  
 
PostPosted: Mon Feb 01, 2016 8:32 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12004
Location: Munich
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.


Top
 Profile  
 
PostPosted: Mon Feb 01, 2016 9:11 am 
Offline
Space Kraken
User avatar

Joined: Sat Jan 30, 2016 11:29 am
Posts: 123
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:
            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.


Top
 Profile  
 
PostPosted: Mon Feb 01, 2016 9:55 am 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12004
Location: Munich
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:
                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.


Top
 Profile  
 
PostPosted: Mon Feb 01, 2016 6:02 pm 
Offline
Space Kraken
User avatar

Joined: Sat Jan 30, 2016 11:29 am
Posts: 123
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.


Top
 Profile  
 
PostPosted: Mon Feb 01, 2016 6:13 pm 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12004
Location: Munich
Cpeosphoros wrote:
However, now - as you predicted - the SitRep message silently fails to show.
Did you try switching the parameter tag to "rawtext"?


Top
 Profile  
 
PostPosted: Mon Feb 01, 2016 6:32 pm 
Offline
Space Kraken
User avatar

Joined: Sat Jan 30, 2016 11:29 am
Posts: 123
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.


Top
 Profile  
 
PostPosted: Mon Feb 01, 2016 6:41 pm 
Offline
Programming, Design, Admin
User avatar

Joined: Wed Oct 08, 2003 1:33 am
Posts: 12004
Location: Munich
Works for me...

In custom_sitreps.txt:
Code:
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:
File comment: custom sitrep in game
sitrep.png
sitrep.png [ 83.02 KiB | Viewed 639 times ]
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 19 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group