Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

String mystery

Hi,

 

I have a real mystery I try to fill an html element with a color which doesn't work. I'm converted my current message code to a file transfer. 

///In companion I do:

data =  encode(data); //from cbor.encode
  outbox.enqueue(filenamedata)// here I transfer the color to the simulator
   .then((ft=> {
     console.log(`Transfer of ${ft.name} and ${filename} and ${data} successfully queued.`);
   })
 
///In app I do:
while ((file = await inbox.nextFile())) {
    console.log(file);
    try {
      properties = fs.readFileSync(file,"cbor" ); // properties dos have the color
      
   }
   catch (err) {
     console.log(err.message);           
   }
[...]
 if (file == "myColor.txt"){
     propChoiceColor = properties;  
     
     console.log(propChoiceColor); // for sure it contains a valid css color like gold
     console.log(typeof(propChoiceColor)); //Says string
     myTime.style.fill = propChoiceColor; //DOESN'T work 😞 HTML/CSS is alright it worked before
     myLine.style.fill = propChoiceColor; //DOESN'T work 😞 HTML/CSS is alright it worked before
 [..]
 
Someone got a clue I think it has something to do with the CBOR encoding??????
 
Thnx, Robert
Best Answer
0 Votes
5 REPLIES 5

What does the data your are encoding? just a string value ex. 

"gold"

 

?

Best Answer
0 Votes

yes just a value with a valid css color

Best Answer
0 Votes

My theory is that colour names are converted to numbers at build time. At run time, try sticking a number in there; eg, 16777215.

 

I suspect that no strings will work, including '16777215', '#808080', etc.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@Gondwana I solved the mystery somehow the string contained a start and end quote, charAt (0, properties) resulted in ".

 

And that became because of somehow in the process of getting the color from the colorpicker the " char was escaped, so \"gold\". I still searching how that happend because earlier when using the message connection (instead of filetransfer) it all worked fine.

 

Thnx for thinking along,

 

Robert

Best Answer

I'd inspect what `data` contains before encoding it in the companion. Because maybe it contains the `"` character at that point, and the root cause is in earlier code like the settings.

Best Answer
0 Votes