Getting species name from planet
Moderators: Oberlus, Committer
Getting species name from planet
Hi, i tried to print out the species on a planet via the sitrep.
I got me the species from a building using Source.Planet.Species but that killed the effect when using as data for the "species" tag. Using "rawtext" I do not get the Species name, but the id (e.g. 23).
For the species tag I need the species name like e.g. "SP_TRITH".
Shouldnt this return the species instead of the id? Is this a bug?
Can I look up the name from the id in scripting?
I got me the species from a building using Source.Planet.Species but that killed the effect when using as data for the "species" tag. Using "rawtext" I do not get the Species name, but the id (e.g. 23).
For the species tag I need the species name like e.g. "SP_TRITH".
Shouldnt this return the species instead of the id? Is this a bug?
Can I look up the name from the id in scripting?
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.
Look, ma... four combat bouts!
Look, ma... four combat bouts!
Re: Getting species name from planet
I am terrible at remembering how to get sitreps right, I virtually always need help fixing them, but the colony building has try tag= "species" data = Source.Planet.Species
Beyond that, there are people quite good at bughunting my messes, if you post the entire effectsgroup you're trying to setup someone can sometimes spot a problem, it can be caused by the scope or activation script being off.
Code: Select all
tag = "species" data = "SP_CRAY"
Beyond that, there are people quite good at bughunting my messes, if you post the entire effectsgroup you're trying to setup someone can sometimes spot a problem, it can be caused by the scope or activation script being off.
Mat Bowles
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13587
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Getting species name from planet
This please. I can't tell from the somewhat vague description what could be happening.MatGB wrote:...if you post the entire effectsgroup you're trying to setup someone can sometimes spot a problem...
Re: Getting species name from planet
Sorry , here you go. If i use species (as below) no message is written out. If I use rawtext instead I get the message "ERROR: Additional effect by species 24"Geoff the Medio wrote:This please. I can't tell from the somewhat vague description what could be happening.MatGB wrote:...if you post the entire effectsgroup you're trying to setup someone can sometimes spot a problem...
Code: Select all
EffectsGroup
scope = And [
Object id = Source.PlanetID
Planet
OwnedBy empire = Source.Owner
Species
]
activation = Source
priority = [[EARLY_PRIORITY]]
effects = [
SetEmpireMeter empire = Source.Owner meter = "METER_IMPERIAL_PP_STORAGE_YIELD" value = Value + 0.2
GenerateSitRepMessage
message = "Additional effect by species %rawtext%"
label = "EFFECT_BLACKHOLE_LABEL"
icon = "icons/building/blackhole.png"
parameters = [
tag = "rawtext" data = Source.Planet.Species // gibt nummer der species
]
empire = Source.Owner
]
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.
Look, ma... four combat bouts!
Look, ma... four combat bouts!
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13587
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Getting species name from planet
There's an option setting to hide sitreps with errors. You should probably turn that off (so they are displayed). That should make the case with the tag = "species" show up. Make sure both the string and the tag are species, not just one...
"Additional effect by species %species%"
tag = "species" data = Source.Planet.Species
The message parameter is looking for a stringtable key, not the actual text to display, which is where the "ERROR" is coming from (the stringtable looking failing), since you've just written out the message instead of putting it in the stringtable as expected. To avoid that, I think you can put
NoStringtableLookup
after the label = line, although I'm not sure if that has any other consequence.
Looks like it's interpreting Source.Planet.Species as an expression that returns an integer, so it's calculating and returning the number 24, then converting that to a string since it's expecting a string reference in the parameter list.
This (interpreting as an integer) makes sense given the order it tries to interpret expressions here:
https://github.com/freeorion/freeorion/ ... 1.cpp#L116
Probably (in C++) either the int expression needs to be renamed to SpeciesID or the species name should be gotten with SpeciesName to avoid the ambiguity.
You can also try forcing it to interpret Source.Planet.Species as a string by writing something like
data = "" + Source.Planet.Species
Not sure if that'll work, but it might.
"Additional effect by species %species%"
tag = "species" data = Source.Planet.Species
The message parameter is looking for a stringtable key, not the actual text to display, which is where the "ERROR" is coming from (the stringtable looking failing), since you've just written out the message instead of putting it in the stringtable as expected. To avoid that, I think you can put
NoStringtableLookup
after the label = line, although I'm not sure if that has any other consequence.
Looks like it's interpreting Source.Planet.Species as an expression that returns an integer, so it's calculating and returning the number 24, then converting that to a string since it's expecting a string reference in the parameter list.
This (interpreting as an integer) makes sense given the order it tries to interpret expressions here:
https://github.com/freeorion/freeorion/ ... 1.cpp#L116
Probably (in C++) either the int expression needs to be renamed to SpeciesID or the species name should be gotten with SpeciesName to avoid the ambiguity.
You can also try forcing it to interpret Source.Planet.Species as a string by writing something like
data = "" + Source.Planet.Species
Not sure if that'll work, but it might.
Re: Getting species name from planet
Not in this case at least:Geoff the Medio wrote: You can also try forcing it to interpret Source.Planet.Species as a string by writing something like
data = "" + Source.Planet.Species
Not sure if that'll work, but it might.
Code: Select all
default\scripting/buildings\INTERSPECIES_ACADEMY.focs.txt:39:51: Parse error. E
xpected real number expression here:
GenerateSitRepMessage
message = "Additional effect by species %rawtext%"
label = "EFFECT_BLACKHOLE_LABEL"
icon = "icons/building/blackhole.png"
parameters = [
tag = "rawtext" data = ("" + Source.Planet.Species)
^
]
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.
Look, ma... four combat bouts!
Look, ma... four combat bouts!
Re: Getting species name from planet
Ah thats what "Situation reports with errors" is forGeoff the Medio wrote:There's an option setting to hide sitreps with errors. You should probably turn that off (so they are displayed). That should make the case with the tag = "species" show up. Make sure both the string and the tag are species, not just one...
Code: Select all
ERROR: Additional effect by species ERROR
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.
Look, ma... four combat bouts!
Look, ma... four combat bouts!
Re: Getting species name from planet
The ERROR: at the front shows it's an error in the stringtable lookup, you need to put something into the stringtable or tell it to not look things up, the former is easier for most purposes (and we won't accept any PRs that don't use the stringtables).
Open en.txt, find the stringtable keys section and add something like EFFECT_MY_PLANET_SPECIES_THING and put that in place of the text in your script, puttting your text beneath it in the stringtable, that will resolve at least part of the error regardless.
Open en.txt, find the stringtable keys section and add something like EFFECT_MY_PLANET_SPECIES_THING and put that in place of the text in your script, puttting your text beneath it in the stringtable, that will resolve at least part of the error regardless.
Mat Bowles
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.
- Geoff the Medio
- Programming, Design, Admin
- Posts: 13587
- Joined: Wed Oct 08, 2003 1:33 am
- Location: Munich
Re: Getting species name from planet
I can't find any place that .Species is used that actually expects an ID number instead of the name. I also can't find in the history when it was added for any context. But I'll just change it to .SpeciesID for the ID number so that .Species should always return the name string.
Edit: Try again after: https://github.com/freeorion/freeorion/ ... ce53a9cd5e
Edit: Try again after: https://github.com/freeorion/freeorion/ ... ce53a9cd5e
-
- Programmer
- Posts: 389
- Joined: Sun Feb 14, 2016 12:08 am
Re: Getting species name from planet
Either
or
Seems to work great.
Code: Select all
tag = "species" data = Source.Planet.Species
Code: Select all
tag = "text" data = Source.Planet.Species
Any content posted should be considered licensed GNU GPL 2.0 and/or CC-BY-SA 3.0 as appropriate.
Re: Getting species name from planet
Verified, worksGeoff the Medio wrote:I can't find any place that .Species is used that actually expects an ID number instead of the name. I also can't find in the history when it was added for any context. But I'll just change it to .SpeciesID for the ID number so that .Species should always return the name string.
Edit: Try again after: https://github.com/freeorion/freeorion/ ... ce53a9cd5e
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.
Look, ma... four combat bouts!
Look, ma... four combat bouts!