The LG(...) Function - Grisgram/gml-raptor GitHub Wiki

This core function is the heart of LG. It will resolve all of your strings and has many powerful features.

To resolve a string, call LG with a path to the string to retrieve.
The path can be in one of those formats:

  • LG("key1", "subkey", "keybelow");
  • LG("key1/subkey/keybelow");
  • You may even mix the formats: LG("key", "subkey/keybelow"); will work just fine!

String references - Strings within Strings

LG supports string references. Use [?key] to reference a string from within another string.
Reference resolve even works recursively! So the referenced string may contain another reference, and so on...
References are resolved only once and the result is cached, so you don't have to worry about performance too much when you create lots of references.
Only the first resolve consumes the CPU time. Subsequent ones will resolve through a cache hit.

Here is an example for string references:

    "author" : "Mike"
    "credit" : "Written by [?author]." -> Will resolve to "Written by Mike."

Access Local and Global Variables

LG can even access local and global variables from your running game through the [:: (global) and [: (local) commands.

Here are some examples
Score: [::_score] will access the variable global._score and put its value into the string at this position

Imagine an inventory of a vendor in your RPG and you want to print the cost of an item:
[:cost] will look for a local variable in the current scope named cost and print its value into the string at this position

Those variable are resolved live, so if their value changes, the string automatically changes too.

Random Picks

LG supports "random picks" if some character should say "one out of x" possible statements, like greetings, curses or cheers when something happens in game.

To have LG pick one string randomly, you must either create a sub-object in json or create a group of strings that all share the same prefix.
Then put an asterisk * as a wildcard marker at the end of your query string when you call LG.

Here is an example of random picks:

"greetings": {
	"greet_1" : "Hi.",
	"greet_2" : "Hello.",
	"greet_3" : "Welcome.",
}

You can pick one of those greetings randomly by querying LG with:

  • LG("greetings/*");
  • or
  • LG("greetings/greet*");

The return value of the LG function is always a string.
Either it is the resolved string or "??? [key] ???" if no string was found for the supplied parameters.

⚠️ **GitHub.com Fallback** ⚠️