Is there a way to use accents in strings in LUA?

2

I'm looking for a way to use accents in strings in the LUA language. I already tried to do this

texto='Pão,está,cabeçalho,'

But in the engine I'm using (the ROBLOX studio), the game only writes to the part that has an accent or other special character, and when I go to check the value of Text (the variable that makes writing in the value of your screen), in the places of letters that have an accent has some signs similar to this: <?>

Does anyone know how to do this?

    
asked by anonymous 26.01.2017 / 01:04

2 answers

1

This depends on how the string is interpreted by the renderer. For example, perhaps the renderer treats each byte of the string as a character code, or in other cases it can base the reading of character codes between bytes in an encoding.

Basically a value of type string in Lua has a sequence of bytes, this would be a sequence of character codes, and the language does nothing and does not relate to those codes. >

Depending on where your code is pasted to run, some characters may be encoded automatically. For example, because accented characters have a code greater than 127, UTF-8, a general character encoding, adds 1 or more bytes to represent it.

If you want to control the above action on a string character without having to modify the encoding of your code it is possible to generate it by the Lua using your code.

If the version is 5.3:

local texto = '\xXX';

Or smaller:

local texto = string.char(byte);

where the XX / byte component is the character code, between 0 and 255 . In the first example the code is in 2-digit hexadecimal format.

To get the code of a specific character in bytes you need to know whether or not it has encoding, and which one. Usually your code would be the first byte, but with encodings it can be represented differently, but obviously using any size of bytes. Warning that certain encodings allow codes greater than 255.

With the above explanations about the coding of the Lua code to be executed, its character specified in the code itself can be encoded next to the other bytes of the same code. If it was with UTF-8 it is better to use a library to manipulate it. Unfortunately it is difficult to link things on the phone, so I will give an example according to the utf8 library of version 5.3:

local offsetI = utf8.offset(
    caractere, 1
);

local code = utf8.codepoint(caractere, offsetI);

This is an approximation. You can now test the text renderer by specifying each character using bytes. If that does not work either, it may be that it uses another encoding or has no way of rendering those characters yet.

    
26.01.2017 / 11:45
-2

- link Like this?

Texto = "Pão,está,cabeçalho,"
script.Parent.Text = Texto

If this is what you wanted ...

    
15.04.2017 / 06:24