Global strings for generic messages and translation file

Started by Gal Shemesh, Thu 20/07/2023 21:20:28

Previous topic - Next topic

Gal Shemesh

Hi everyone,

Is there way that global strings of generic messages, such as "That doesn't work" which is commonly used in else statements when using items on random things, could be included in the translation file?

I made some global strings in a game I'm working on so I'll only have to write them once, and then I call for them from any scenario that I like, preventing any duplications of the same line in the translation file. Though, I found that they don't get included when the translation file is generated...

If not, where would you put your generic messages in a way that they will be included in the translation file?

I've read here and found that I can just create a new script in the Scripts tree and that as long as the script will be above the other scripts, that I could call for things in it from the entire project. However, when I try to declare a string variable name and set it to store the actua text string that I wish to show to the screen, I get the error that type 'string' is no longer supported; use String instead. But when I try String with capital 'S', I get the error "cannot assign initial value to global pointer", so I'm not sure what I'm doing wrong.

Would appreciate some help.

Thanks
Gal Shemesh,
goldeng

Khris

You can redirect interactions to unhandled_event to do this.
Open the global script's header and add
Code: ags
import function unhandled_event(int what, int type);

Now you can do
Code: ags
  else unhandled_event(2, 3); // 2 = on object, 3 = use inventory

This way the global unhandled_event functions gets called even if an event handler exists, and in there you can now have the player say appropriate messages, which thus end up in the translation file.

In general you shouldn't use global messages any longer, they've been obsolete for years.

Crimson Wizard

#2
I think this is a question about global String variables, not built-in "global messages" feature.

@Gal Shemesh, AGS cannot assign values to String variables at their declaration, same as any pointer variable.
You should do the assignment in game_start.
Room-local messages may be initialized in room's Load event.

About translation file, AGS does not add String variable values exactly, because they are only known at runtime.
Instead it adds every string literal from script (the sequence between " ... ") to the translation file, as well as values of textual properties and custom properties.

Khris

@Crimson Wizard Right, I didn't realize this is about String variables created inside the Global Variables pane.

Anyway, calling a function is still better than using just a player.Say command because if you ever want to change the behavior in the future, you can do it in a single place instead of having to edit potentially dozens or even hundreds of interaction functions.

Gal Shemesh

#4
Thanks guys! As I progress in learning AGS (and writing some sort of a reference 'book' to myself that as of this moment has reached the 330 pages!), I always encounter with new problems and new creative solutions to solving them - I'm not a programmer so I don't immediately get many of the technical things, but I'm trying my best with the manual and the forum here, and only when I really don't find what I'm looking for I make a new thread and ask. I much appreciate your assistance! Thanks again. :)

@Khris, this is exactly what I'm after - to make my script right so I won't have to come back and change plenty of lines of code if I want to make a global change to something; I'm still trying to understand the suggested method that you mentioned, as I'm having some difficulties to understand this unhandled_event thing. But in general, I understand your point of using a function and then call for it, rather than writing the actual code many times in many places, and then having to tune it everywhere if you want to change something - I'm learning a lot from the Narrate function that you assisted me with. :)
Gal Shemesh,
goldeng

Khris

330 pages! Wow :-D

unhandled_event is a built in function. If it exists, AGS calls it whenever an event runs that doesn't have a handler function associated with it. It's closely related to the multi-cursor Sierra GUI and according event functions, so if your game uses the BASS or Tumbleweed template for instance, you're not going to really use it anyway.
Or rather, you should probably implement your own way of handling unhandled events.

Moving stuff into custom functions is a good idea in general, not only makes it your scripts more readable and organized but you can easily change global aspects, indeed.

Gal Shemesh

Quote from: Khris on Fri 21/07/2023 07:14:45330 pages! Wow :-D

unhandled_event is a built in function. If it exists, AGS calls it whenever an event runs that doesn't have a handler function associated with it. It's closely related to the multi-cursor Sierra GUI and according event functions, so if your game uses the BASS or Tumbleweed template for instance, you're not going to really use it anyway.
Or rather, you should probably implement your own way of handling unhandled events.

Moving stuff into custom functions is a good idea in general, not only makes it your scripts more readable and organized but you can easily change global aspects, indeed.

Thanks so much for the detailed explanation, @Khris! Much appreciated. :)

As for my reference book - yeah, I called it AGS from scratch (the name may change) and it became long and detailed with information; I started from a complete empty project, as I wanted to learn my way with the engine from a complete scratch, and up to re-creating the base Sierra-style template game that comes with it. Then I began improving it and cover many aspects, such as making a plot, adding speech, building some puzzles, and also side features like the translation of a game to another language. By how it turned out, I really look forward to making a video tutorial course series on YouTube. Will update on the forum if and when it will be done. :)
Gal Shemesh,
goldeng

SMF spam blocked by CleanTalk