Need help with Sitrep to show "fleet health percent"
Moderators: Oberlus, Committer
Re: Need help with Sitrep to show "fleet health percent"
Thanks you guys are awesome!
Will look into it tomorrow
Will look into it tomorrow
Re: Need help with Sitrep to show "fleet health percent"
I went through some more testing and made some progress.
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
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
I also dont get why "Statistic" needs to be before the If, if i leave it out it i also get "]" error.
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
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: Select all
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)
]
]
The exact numbers are not final and this is just for testing.
I tried to do
Code: Select all
Statistic If condition = (LocalCandidate.Structure < LocalCandidate.MaxStructure)
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: Select all
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)
Code: Select all
scripting/empire_statistics/MILITARY_STRENGTH.focs.txt:2: Statistic Sum value = (LocalCandidate.Attack * (LocalCandidate.Structure + 2 * LocalCandidate.MaxShield))
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: Select all
Sum value = LocalCandidate.Population condition = Planet
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: Select all
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
Re: Need help with Sitrep to show "fleet health percent"
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.Klaus wrote:But the "<" does not seem to be valid, i guess only "low 0" or "high =" works with comparing values?
"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).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.
If I provided any code, scripts or other content here, it's released under GPL 2.0 and CC-BY-SA 3.0
Re: Need help with Sitrep to show "fleet health percent"
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.
Parse Error: Expected ] here
Parse Error: Expected ] here
Parse Error: Expected ] here
Parse Error: Expected ] here
working
At the end is the current work around example without error.
Code: Select all
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
Code: Select all
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
Code: Select all
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
Code: Select all
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
Code: Select all
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
Re: Need help with Sitrep to show "fleet health percent"
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
Changing it to something like the following works just fine
Code: Select all
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
Re: Need help with Sitrep to show "fleet health percent"
Ah, now im learnding!
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
Edit:
In my test with
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?
Code: Select all
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
Question is now, how do i do it without "Number".
Could i just do
Code: Select all
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: Select all
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
Is it maybe because of RootCandidate and LocalCandidate now have a different meaning than before when i had this check in my "Number" block?
Re: Need help with Sitrep to show "fleet health percent"
If fleets with 100% does not trigger the sitrep, may it be that the division is operating over integers?
Try
(No idea about operators preference in FOCS, so I added extra parenthesis).
Try
Code: Select all
((Statistic Sum value = LocalCandidate.Structure condition = ContainedBy RootCandidate) < (0.75 * (Statistic Sum value = LocalCandidate.MaxStructure condition = ContainedBy RootCandidate)))