problems with unicode

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
grimaldiface
Posts: 43
Joined: Tue Apr 08, 2008 9:56 pm

problems with unicode

Post by grimaldiface » Tue Jun 24, 2008 3:43 pm

I'm working on a psychology experiment that is basically a flashcard program for Lithuanian-English word pairs. I started by using htmltext to preserve text as it was transferred from field to variable to field, which works fine for presenting the words to the user, however when it comes time to write to file, my text file becomes a mess of html tags. Since a human will eventually have to grade these, it just wont do.

I figure unicode is the way to go, however I've run into a couple problems. When I take the unicodetext out of one field and put it into another, it works fine. But when i transfer the unicode from variable to array, things get sticky. for example, this works:

Code: Select all

put the unicodetext of fld list of cd main into tData
set the unicodeText of fld list2 of cd main to tData
however this does not:

Code: Select all

put the unicodetext of fld list of cd main into tData
repeat with x=1 to 50
     put item 1 of line x of tData into lith[x] 
  end repeat
  repeat with x=1 to 50
    set the unicodetext of fld "cue" of cd main to lith[x]  
    wait 5 seconds
  end repeat
Everything looks Chinese when it goes into fld "word". I assume that it has something to do when putting the chunks of tData into the lith array. Creating the array directly from the field is not an option. Any help would be greatly appreciated.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue Jun 24, 2008 4:45 pm

Hi Grimaldi,

Your itemdelimiter goes together with a NULL char, which is either before or after the itemdelimiter, depending on the endian.

Instead of using items, you can use offset. For example, if your item delimiter is a comma, you might search for the next (comma & NULL) in your text and this determine what is the unicodeText of the next item. Once you have determined the first and last unicode character of the item, you can store it in your array.

A good way to export unicode text is to use the rtfText property. This works as long as you don't use too many different colours and styles. You can export rtfText as binary and open it in a word processor.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

grimaldiface
Posts: 43
Joined: Tue Apr 08, 2008 9:56 pm

Post by grimaldiface » Thu Jun 26, 2008 7:58 pm

Mark,

Thanks so much for the quick reply. I'm not sure if I'm doing it right, but even when using offset instead of items, it still comes out wrong in the end. Here is what I used.

Code: Select all

  put the unicodetext of fld list of cd main into tData
  repeat with x=1 to 10
  put line x of tData into tline 
  put offset(comma & null,tline) into tDelim
  put char 1 to tDelim of tline into lith[x]
  end repeat
  set the unicodetext of fld "word" of cd main to lith[1]
Interestingly, the first item taken from field list works fine, but all the rest are terrible. So lith[1] would work but not lith[2]. By the way, the fld list looks something like this....

bulvÄ—,potato
gÄ—lÄ—,flower
maišas,bag
adata,needle

I'm wondering if the returns at the end of each line have something to do with it, but I haven't been able to figure that out. I've tried using both comma & null and null & comma, subtracting 1 from tDelim, and setting useUnicode to true. Frustrating.

I wasn't sure what you meant by exporting with rtfText, did you mean like writing the rtftext to file? I tried simply using the rtfText to transfer text from field to field and it didn't preserve the characters correctly (removed the dot over the e, like in "bulvÄ—" above)

--grimaldi

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Thu Jun 26, 2008 8:33 pm

Hi Grimaldi,

You have to use offsets for the lines, too.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply