FreeOrion

Forums for the FreeOrion project
It is currently Sun May 27, 2018 5:42 pm

All times are UTC




Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Thu Feb 08, 2018 11:38 pm 
Offline
Krill Swarm

Joined: Tue Feb 06, 2018 7:22 pm
Posts: 10
Thanks you guys are awesome!
Will look into it tomorrow :D


Top
 Profile  
 
PostPosted: Sat Feb 10, 2018 12:02 am 
Offline
Krill Swarm

Joined: Tue Feb 06, 2018 7:22 pm
Posts: 10
I went through some more testing and made some progress.

Code:
scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      Number low = ((LocalCandidate.NumShips * 1 / 2) +1) condition = And [   
         Ship
         ContainedBy RootCandidate
         Structure high = (LocalCandidate.MaxStructure * 0.50)   
      ]
]

Its my way to get around the "Sum" not working. I count the ships that are below x% up to at least x% of NumShips in fleet.
The exact numbers are not final and this is just for testing.

I tried to do

Code:
Statistic If condition = (LocalCandidate.Structure < LocalCandidate.MaxStructure)


But it always gives me the "]" Error. I use Notepad++ to check for matching parentheses.
If i replace the line "Structure high = (LocalCandidate.MaxStructure * 0.50) " with the code above,
i would expect to get 1 = true for damaged ships(any), and 0 = false for ships at MaxStructure.

But the "<" does not seem to be valid, i guess only "low 0" or "high =" works with comparing values?
I tried all sorts of combinations

Code:
Statistic If condition = (LocalCandidate.Structure < LocalCandidate.MaxStructure)
If condition = (LocalCandidate.Structure < LocalCandidate.MaxStructure)
Statistic If condition = (LocalCandidate.Structure high = LocalCandidate.MaxStructure)
If condition = (LocalCandidate.Structure high = LocalCandidate.MaxStructure)


I also dont get why "Statistic" needs to be before the If, if i leave it out it i also get "]" error.

Code:
scripting/empire_statistics/MILITARY_STRENGTH.focs.txt:2:    Statistic Sum value = (LocalCandidate.Attack * (LocalCandidate.Structure + 2 * LocalCandidate.MaxShield))


Here its used for Sum.
When i first saw this file i did not know what "Statistic" meant and thought its just a variable used for game graphs.
Then "Sum" is only used 3 times in all accessable scripts?

In the wiki the example is just

Code:
Sum value = LocalCandidate.Population condition = Planet


Thats why im confused. Statistic yes/no?
I still dont get it why i cant use "Sum" or "If" in a supposed valid boolean expression.
To check if Sum of values is lower/greater some other Sum.

I currently try to do all conditions in the scope to fire the SitRep only when all conditions are met.
The SitRep output is just fleet values, no conditions atm.
Also text is not final, but should not matter for testing anyways.
So why do i get "]" error if i try to use "If" or "Sum" and other code runs fine, like the "Number" solution i use for now.

Complete SitRep

Code:
EffectsGroup
scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      Number low = ((LocalCandidate.NumShips * 1 / 2) +1) condition = And [   
         Ship
         ContainedBy RootCandidate
         Structure high = (LocalCandidate.MaxStructure * 0.50)   
      ]
]
activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the ship is at %rawtext% percent test 123."
            label = "Fleet_Detail"
            NoStringtableLookup
            icon = "icons/planet/gasgiant.png"
            parameters = [
            tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips  // works, shows number of ships in fleet
         ]
            empire = Source.Owner


Top
 Profile  
 
PostPosted: Sat Feb 10, 2018 4:44 am 
Offline
AI Lead, Programmer
User avatar

Joined: Sat Sep 22, 2012 6:25 pm
Posts: 4619
Klaus wrote:
But the "<" does not seem to be valid, i guess only "low 0" or "high =" works with comparing values?
No, "<", ">", "<=" etc should all work fine in the general manner you showed there, but they are not interchangeable with "low" and "high"-- the latter are keywords used by various specific conditions, as opposed to the comparison operators which specify value comparison conditions themselves. (The concepts are related, but distinct). If you want more specific feedback post the exact sitrep you tried for that, and the error log lines / message you are getting.


Quote:
I also dont get why "Statistic" needs to be before the If, if i leave it out it i also get "]" error....
When i first saw this file i did not know what "Statistic" meant and thought its just a variable used for game graphs.
"Statistic" is required, and I've now edited that tutorial section to clarify. Without being preceded by the keyword "Statistic", I believe the keyword "If" is only valid in the Effects section, so the parser was telling you that your scripting parts were not fitting together properly (the parser was waiting for a terminating bracket when you used "If" in a place it was not valid).

_________________
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: Sat Feb 10, 2018 6:20 pm 
Offline
Krill Swarm

Joined: Tue Feb 06, 2018 7:22 pm
Posts: 10
Ok here a some of my failed tries with Parser error. Im also posting the tries with "<" to "high =" change.
At the end is the current work around example without error.

Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      
      Contains And [
         Ship
         Statistic If condition = (LocalCandidate.Structure high = LocalCandidate.MaxStructure)   // Parse Error: Expected ] here
      ]
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner

Parse Error: Expected ] here

Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      
      Contains And [
         Ship
         Statistic If condition = (LocalCandidate.Structure < LocalCandidate.MaxStructure)   // Parse Error: Expected ] here
      ]
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner

Parse Error: Expected ] here

Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      
      Number low = ((LocalCandidate.NumShips * 1 / 2) +1) condition = And [   
         Ship
         ContainedBy RootCandidate
         Statistic If condition = (LocalCandidate.Structure < LocalCandidate.MaxStructure)   // Parse Error: Expected ] here
         
      ]
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner


Parse Error: Expected ] here


Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      
      Number low = ((LocalCandidate.NumShips * 1 / 2) +1) condition = And [   
         Ship
         ContainedBy RootCandidate
         Statistic If condition = (LocalCandidate.Structure high = LocalCandidate.MaxStructure)   // Parse Error: Expected ] here
         
      ]
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner

Parse Error: Expected ] here


Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      
      Number low = ((LocalCandidate.NumShips * 1 / 2) +1) condition = And [   
         Ship
         ContainedBy RootCandidate
         Structure high = (LocalCandidate.MaxStructure * 0.50)   // works
         
      ]
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner

working


Top
 Profile  
 
PostPosted: Sat Feb 10, 2018 7:04 pm 
Offline
AI Lead, Programmer
User avatar

Joined: Sat Sep 22, 2012 6:25 pm
Posts: 4619
Ah, it took a little while to sink in, but here you are trying to use this "If" type Statistic as part of a list of Conditions, but Statistics are ValueRefs (the If type returns either a 1 or a 0).

Changing it to something like the following works just fine
Code:
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      Contains And [
         Ship
         (LocalCandidate.Structure < 0.5* LocalCandidate.MaxStructure)   
      ]
   ]

_________________
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 Feb 11, 2018 12:27 pm 
Offline
Krill Swarm

Joined: Tue Feb 06, 2018 7:22 pm
Posts: 10
Ah, now im learnding!

Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      
      Number low = ((LocalCandidate.NumShips * 1 / 2) +1) condition = And [   // low = (LocalCandidate.NumShips * 1 / 3) works
         Ship
         ContainedBy RootCandidate
         ((Statistic Sum value = LocalCandidate.Structure condition = ContainedBy RootCandidate) / (Statistic Sum value = LocalCandidate.MaxStructure condition = ContainedBy RootCandidate) < 0.5)
         
      ]
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner


I had to add "Statistic" to make this work and compare "<" the result to some number.

Question is now, how do i do it without "Number".
Could i just do

Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      ((Statistic Sum value = LocalCandidate.Structure condition = ContainedBy RootCandidate) / (Statistic Sum value = LocalCandidate.MaxStructure condition = ContainedBy RootCandidate) < 0.5)
         
      
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair."
             label = "Fleet_Detail_Test"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner




Edit:

In my test with

Code:
EffectsGroup
   scope = And [
      Fleet
      OwnedBy empire = Source.Owner
      ((Statistic Sum value = LocalCandidate.Structure condition = ContainedBy RootCandidate) / (Statistic Sum value = LocalCandidate.MaxStructure condition = ContainedBy RootCandidate) < 0.75)
   ]
   activation = Source
   effects =
         GenerateSitRepMessage
            message = "At %system% the test fleet with %rawtext% ships needs repair75."
             label = "Fleet_Detail_Test75"
             NoStringtableLookup
             icon = "icons/planet/gasgiant.png"
             parameters = [
                tag = "system" data = Target.SystemID
            tag = "rawtext" data = Target.NumShips 
          ]
             empire = Source.Owner


A fleet with ~90% Structure/MaxStructure reported to be below 75%. Which means it does not quite do what i think it does/should.
Is it maybe because of RootCandidate and LocalCandidate now have a different meaning than before when i had this check in my "Number" block?


Top
 Profile  
 
PostPosted: Sun Feb 11, 2018 7:00 pm 
Offline
Vacuum Dragon
User avatar

Joined: Mon Apr 10, 2017 4:25 pm
Posts: 538
If fleets with 100% does not trigger the sitrep, may it be that the division is operating over integers?
Try
Code:
((Statistic Sum value = LocalCandidate.Structure condition = ContainedBy RootCandidate) < (0.75 * (Statistic Sum value = LocalCandidate.MaxStructure condition = ContainedBy RootCandidate)))

(No idea about operators preference in FOCS, so I added extra parenthesis).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

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