Custom (hotspot) properties not shown in translations

Started by , Fri 12/02/2016 11:37:22

Previous topic - Next topic

m0ds

Hello, a quick one here, for hotspots we have used custom properties. (by selecting a hotspot, then going down to the properties > properties > properties menu.

However none of the custom properties (customoption1 ie "press button" customoption2 ie "pull lever") text reaches the translation (TRS) files.

I did solve this once but can't remember how, and have no idea where to start right now... any help or clues are appreciated :) There is a possibility this is linked in to a custom module that we're using by duals, but if something clicks in someone's mind about the above please do say, if I do find out first I'll update this with my solution. thanks!

Crimson Wizard

This is probably one of the places we found in AGS which does not connect to translation system (another was Global variables, I think).

From the top of my head, I see this solution: create a dummy function that assigns strings to variable:
Code: ags

function translation_hack()
{
    String s;
    s = "press button";
    s = "pull lever";
}

You do not have to call this function from anywhere, you just need to have it in your script.

When getting custom property value, use GetTranslation() function to translate it:
Code: ags

String real_string = GetTranslation(my_hotspot.GetTextProperty("property_name"));

m0ds

Hi CW, thanks for the suggestion! The problem is the game has hundreds of these custom options, does your method suggest I have to go thru and find every one and list it? That could take me a week or two... Or is there a way I can pull what exists into a list/listbox or something and then create strings from that? If that makes sense...

As mentioned, once, somehow, I did manage to or someone managed to get them all into the trs file, but I'm having little luck re-creating that (even starting new projects and trying), so have noo idea how it was possible originally, but don't recall anyone (inc. me) having to manually list every custom option text. Something dumped them all into the trs, can't remember what though..

Snarky

If you can't work out any other way, you could write a module script that loops through each room and each hotspot[] array and prints all the property values to a text file. That way it won't take you a week to find them all, at least!

m0ds

Thanks. Sounds like a legit route to take for now... but that's beyond me though, can you give me a starter code for something like that please? (laugh)

Crimson Wizard

#5
Code: ags

File *f = File.Open("room_%d_hotspots.txt", player.Room);
int i = 0;
while (i < AGS_MAX_HOTSPOTS)
{
   Hotspot *h = hotspot[i];
   String s = h.GetTextProperty("my_property");
   if (!String.IsNullOrEmpty(s))
       f.WriteRawLine(s);
   i++;
}
f.Close();

m0ds

Thanks... well i'm curious to see if this works, but any instruction please? Where to put it/call it? what is "my_property" ?

I also get "Type mismatch: cannot convert 'Hotspoty*' to 'Hotspot*'" putting it anywhere, currently.

Snarky

"Hotspoty" is a typo. "my_property" is the name of your custom property. (If you have multiple, you'd want to read each one and write it to the file.)

You can put the code in an on_event() function in the global script (see manual for predefined global script functions), to run when the event is eEventEnterRoomBeforeFadein:

Code: ags
function on_event(EventType event, int data)
{
  if(event == eEventEnterRoomBeforeFadein)
  {
    // CW's code
  }
}


Now whenever you visit a room, all its hotspots' properties are written to the file. Looping through the rooms automatically is a little tricky, so it's probably easier to just to that manually, maybe using the debug feature to jump to each room.

m0ds

Thanks. About that hotspoty thing, I think its actually referring to something else in the script, or at least, is having difficulty with this maybe (from a module .ash)?

Code: ags

struct Hotspoty {
bool EnabledOption[10];
};
Hotspoty hotspots[3000];


because there is no "hotspoty" in CW's code.


Khris

And the first line should be:

Code: ags
File *f = File.Open(String.Format("room_%d_hotspots.txt", player.Room), eFileWrite);

m0ds

Thanks. That does something... but sadly it's not the solution to my problem. And with a game with 150 rooms it takes the piss a bit...

I guess it was perhaps one of the other companies, akella or zodiac who figured out a way to get custom properties to go into translation file.

For the record, Game.DoOnlyOnce("this description text") also goes into translation, which is hella-annoying :P Dunno if that's been mentioned before, so just wanted to put it out there. I realize not many people do translations, and probably even fewer with custom properties (if any). But thanks for trying to help me on that, I'll keep investigating.

Gurok

Mods, for Game.DoOnlyOnce, wrap your description text in a call to this function:

Code: ags
String Property(String value)
{
	return(value);
}


i.e. Game.DoOnlyOnce(Property("this description text"));

The presence of the word Property is enough to turn off the translation parser.
[img]http://7d4iqnx.gif;rWRLUuw.gi

Snarky

Quote from: Mods on Sat 13/02/2016 14:08:31
Thanks. That does something... but sadly it's not the solution to my problem. And with a game with 150 rooms it takes the piss a bit...

How is it not the solution? You should end up with a set of text files with all the property values (though you might just want to write it all to one file instead of 150 of them), and then you can paste the strings into the translation_hack() function CW suggested to have them included in the translation.

To loop through all the rooms automatically, you could try something like this. It's a little convoluted because you have to make sure you don't try to go to a room that doesn't exist (which will crash), and there's no way from within AGS to know whether it does in advance. If you've just created the rooms sequentially and never deleted any it's quite simple, but in general the best approach is probably to write a little function that tells you whether a room is valid:

Code: ags
#define MAX_ROOM 150 // or whatever the highest room number is

bool isValidRoom(int i)
{
  // Check whether the given room is valid. Depends on how you have your rooms set up.
  // For example:
  if(i>=1 && i <= 45) return true;
  if(i>=50 && i <=102) return true;
  if(i>=300 && i <=345) return true;
  return false;
}

int nextValidRoom()
{
  int i = player.Room+1;
  while(!isValidRoom(i))
  {
    i++;
    if(i>MAX_ROOM) return -1;
  }
  return i;
}

function on_event(EventType event, int data)
{
  if(event == eEventEnterRoomBeforeFadein)
  {
    // CW's code
    int nextRoom = nextValidRoom();
    if(nextRoom>0) player.ChangeRoom(nextRoom);
  }
}

SMF spam blocked by CleanTalk