Getting species name from planet

Creation, discussion, and balancing of game content such as techs, buildings, ship parts.

Moderator: Committer

Post Reply
Message
Author
Ophiuchus
Vacuum Dragon
Posts: 507
Joined: Tue Sep 30, 2014 10:01 am

Getting species name from planet

#1 Post by Ophiuchus » Wed Jan 25, 2017 9:55 am

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?
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: Getting species name from planet

#2 Post by MatGB » Wed Jan 25, 2017 10:53 am

I am terrible at remembering how to get sitreps right, I virtually always need help fixing them, but the colony building has

Code: Select all

                        tag = "species" data = "SP_CRAY"
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.
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

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

Re: Getting species name from planet

#3 Post by Geoff the Medio » Wed Jan 25, 2017 12:47 pm

MatGB wrote:...if you post the entire effectsgroup you're trying to setup someone can sometimes spot a problem...
This please. I can't tell from the somewhat vague description what could be happening.

Ophiuchus
Vacuum Dragon
Posts: 507
Joined: Tue Sep 30, 2014 10:01 am

Re: Getting species name from planet

#4 Post by Ophiuchus » Wed Jan 25, 2017 12:58 pm

Geoff the Medio wrote:
MatGB wrote:...if you post the entire effectsgroup you're trying to setup someone can sometimes spot a problem...
This please. I can't tell from the somewhat vague description what could be happening.
Sorry :oops: , 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"

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.

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

Re: Getting species name from planet

#5 Post by Geoff the Medio » Wed Jan 25, 2017 2:29 pm

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.

Ophiuchus
Vacuum Dragon
Posts: 507
Joined: Tue Sep 30, 2014 10:01 am

Re: Getting species name from planet

#6 Post by Ophiuchus » Wed Jan 25, 2017 5:35 pm

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.
Not in this case at least:

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.

Ophiuchus
Vacuum Dragon
Posts: 507
Joined: Tue Sep 30, 2014 10:01 am

Re: Getting species name from planet

#7 Post by Ophiuchus » Wed Jan 25, 2017 5:45 pm

Geoff 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...
Ah thats what "Situation reports with errors" is for :)

Code: Select all

ERROR: Additional effect by species ERROR
Guess that would help a little bit with debugging.
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: Getting species name from planet

#8 Post by MatGB » Wed Jan 25, 2017 6:06 pm

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.
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

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

Re: Getting species name from planet

#9 Post by Geoff the Medio » Wed Jan 25, 2017 6:38 pm

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

dbenage-cx
Programmer
Posts: 389
Joined: Sun Feb 14, 2016 12:08 am

Re: Getting species name from planet

#10 Post by dbenage-cx » Wed Jan 25, 2017 7:34 pm

Either

Code: Select all

tag = "species" data = Source.Planet.Species
or

Code: Select all

tag = "text" data = Source.Planet.Species
Seems to work great.
Any content posted should be considered licensed GNU GPL 2.0 and/or CC-BY-SA 3.0 as appropriate.

Ophiuchus
Vacuum Dragon
Posts: 507
Joined: Tue Sep 30, 2014 10:01 am

Re: Getting species name from planet

#11 Post by Ophiuchus » Thu Jan 26, 2017 7:48 pm

Geoff 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
Verified, works :)
Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

Post Reply