Author Topic: lua function unitName broken ?  (Read 1194 times)

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
lua function unitName broken ?
« on: 7 August 2014, 17:41:42 »
I am not sure if this is a bugreport or just something to discuss.

Currently the lua function "unitName" returns the currents units "displayname" which si for example translated too. Is this really meant like this or did this return the naem of the unit type in the past ?
I personally cannot really imagine why there should be a function unitName but no function returning the unitType .
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: lua function unitName broken ?
« Reply #1 on: 7 August 2014, 21:42:15 »
Yes, that seems to be broken. It was changed by softcoder in 0ead6a36. As an aside, git blame makes it easy to figure out where a specific line of code changed.

Here's the relevant function:
Code: [Select]
const string World::getUnitName(int unitId) {
Unit* unit= findUnitById(unitId);
if(unit == NULL) {
throw megaglest_runtime_error("Can not find Faction unit to get position unitId = " + intToStr(unitId),true);
}
return unit->getFullName(game->showTranslatedTechTree());
}

This is what it used to be:
Code: [Select]
const string World::getUnitName(int unitId) {
Unit* unit= findUnitById(unitId);
if(unit == NULL) {
throw megaglest_runtime_error("Can not find Faction unit to get position unitId = " + intToStr(unitId),true);
}
return unit->getFullName();
}

As an aside, I haven't checked if the function is used elsewhere.

This is probably unintentional, since it prevents easy checking for what unit an ID corresponds to (eg, what type was the last unit that died?). Not to mention most of the changes in the revision in question are using the non-translated versions. However, I do think we need some way to get the translated value for output (since scenarios can be translated).
« Last Edit: 7 August 2014, 21:48:20 by Omega »
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

Baŝto

  • Summoner
  • **
  • Posts: 59
    • View Profile
    • find me on diaspora
Re: lua function unitName broken ?
« Reply #2 on: 8 August 2014, 08:08:13 »
I think a techTreeTranslate(string) and scenarioTranslate(string[,string…]) would be in general handy.
I remember having trouble with outputting strings, some functions translated every string, others were not able to replace %s. I guess just outputting the plain string and using the functions mentioned above would be the easiest solution.

titi_son

  • Draco Rider
  • *****
  • Posts: 283
  • titi_son
    • View Profile
Re: lua function unitName broken ?
« Reply #3 on: 8 August 2014, 14:07:49 »
i think this function is alright, but we need another one ( maybe called unitType() ) because you may want to have a the translated unitname. This may be useful for tutorials. So you can tell the exactly unit name to tell the player which unit to select. This will work also if he plays without translated techtree.
My first Tilseset: SPRING :) (included in Megaglest )

Secret Hint: To play online join the IRC #megaglest-lobby on freenode which is the lobby chat ingame. So you can chat with or wait for people in the lobby without running megaglest all the time.

GunChleoc

  • Horseman
  • ****
  • Posts: 202
    • View Profile
    • Fòram na Gàidhlig
Re: lua function unitName broken ?
« Reply #4 on: 9 August 2014, 16:09:40 »
We definitely need 2 functions here - one to return an internal name fr coding reference, and one to return the (translated) name that the player will see on screen.

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: lua function unitName broken ?
« Reply #5 on: 9 August 2014, 21:24:30 »
As an aside, if we are using two functions (or have some optional boolean parameter that specifies whether to translate), then I think the current unitName should *probably* be the untranslated value, simply to fix any scenarios that might have been broken and gone unnoticed. Although I'm not sure if there are any such scenarios. If there is, though, it'd probably using the old behaviour could fix broken scenarios, while the worst case for it would be printing out a non-translated name when a translated name is expected.
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

titi

  • MegaGlest Team
  • Airship
  • ********
  • Posts: 4,240
    • View Profile
    • http://www.titusgames.de
Re: lua function unitName broken ?
« Reply #6 on: 9 August 2014, 21:45:01 »
its not only about translation. Its also about a changed unit name when a unit name when the unit gets more advanced ( many kills ).

I fixed this now and added a new function "getUnitDisplayName()"
The old one "getUnitName" only returns the plain unit type name which fits to all the other name related lua functions.

https://github.com/MegaGlest/megaglest-source/commit/cf5da4d2b360ea49d96f67a00cb1d9abdcb2f90f
Try Megaglest! Improved Engine / New factions / New tilesets / New maps / New scenarios

 

anything