Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Unicode read from notecards

RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
03-10-2007 14:44
I have a notecard with, for example, this line:

arrivés à l'entrée

The special characters look fine when opening it in SL editor.

I read it with this script:

CODE

key g_QueryID;
key g_Agent;

default
{
state_entry()
{
llSay(0, "Ready");
}

touch_start(integer total_number)
{
g_QueryID = llGetNotecardLine("messages.Fr", 0);
g_Agent = llDetectedKey(0);
}

dataserver(key query_id, string data)
{
llOwnerSay("Len: " + (string)llStringLength(data));
llSay(0, "Say: " + llEscapeURL(data));
llOwnerSay("OwnerSay: " + data);
llInstantMessage(g_Agent, "IM: " + data);
}
}


Here is what it prints out when I click on the object:

CODE

[14:37] Object: Len: 15
[14:37] Object: Say: arrivs%20%20l%27entre
[14:37] Object: OwnerSay: arrivs l'entre
[14:37] Object: IM: arrivs l'entre


I tried printing it several ways, to insure I'm seeing what I think I'm seeing.

Not only are the special characters gone, but the length of what was read doesn't even include them (otherwise Len would be 18).

Does reading notecards and dataserver events not support special characters and unicode?

Rj
Peekay Semyorka
Registered User
Join date: 18 Nov 2006
Posts: 337
03-12-2007 09:39
The dataserver supports Unicode fine, unfortunately LSL can't directly handle it. In order to display Unicode characters, you need to represent them in escaped UTF-8 format, then convert with llUnescapeURL before display.

E.g., the following code correctly prints "arrivés à l'entrée".
CODE

string str = "arriv%C3%A9s%20%C3%A0%20l'entr%C3%A9e";
llOwnerSay(llUnescapeURL(str));


Makes it difficult to create notecards meant for both human and LSL consumption, however.

-peekay
Peekay Semyorka
Registered User
Join date: 18 Nov 2006
Posts: 337
03-12-2007 09:43
The dataserver supports Unicode fine, unfortunately LSL can't directly handle it. In order to display Unicode characters, you need to represent them in escaped UTF-8 format, then convert with llUnescapeURL before display.

E.g., the following code correctly prints "arrivés à l'entrée".
CODE

string str = "arriv%C3%A9s%20%C3%A0%20l'entr%C3%A9e";
llOwnerSay(llUnescapeURL(str));


Makes it difficult to create notecards meant for both human and LSL consumption, however.

-peekay
RJ Source
Green Sky Labs
Join date: 10 Jan 2007
Posts: 272
03-13-2007 13:50
From: Peekay Semyorka
The dataserver supports Unicode fine, unfortunately LSL can't directly handle it. In order to display Unicode characters, you need to represent them in escaped UTF-8 format, then convert with llUnescapeURL before display.

E.g., the following code correctly prints "arrivés à l'entrée".
CODE

string str = "arriv%C3%A9s%20%C3%A0%20l'entr%C3%A9e";
llOwnerSay(llUnescapeURL(str));


Makes it difficult to create notecards meant for both human and LSL consumption, however.

-peekay


Thanks peekay - I was almost there... I finally resolved myself to the unescape direction, but was trying to get the right escape codes. It's working great now.

Rj