set/getWebViewString not working?

I am trying to convert text to ascii codes. Code works outside. But in AI it gives preset WebViewString code

JS Code:

function getCharCodes(s) {
    let charCodeArr = [];
    
    for (let i = 0; i < s.length; i++) {
        let code = s.charCodeAt(i);
        charCodeArr.push(code);
    }
    
    return charCodeArr;
}

let webString = window.AppInventor.getWebViewString();

// Ensure charCodes is an array by wrapping it in square brackets
let charCodes = [getCharCodes(webString)];

let charCodesString = charCodes.toString();

window.AppInventor.setWebViewstring(charCodesString);

AI code:

A picture of a truncated text block (...) is pretty useless for debugging.

Canned Reply: ABG- Export & Upload .aia)
Export your .aia file and upload it here.

export_and_upload_aia

.

data_over_sound.aia (2.2 KB)

try with:

let charCodesString = JSON.stringify(charCodes);

and don't wrap getCharCodes(webString) in square brackets

		function getCharCodes(s) {     
			let charCodeArr = [];         
			for (let i = 0; i < s.length; i++) {
			let code = s.charCodeAt(i);
			charCodeArr.push(code);
			}
			return charCodeArr; 
		}
		let webString = window.AppInventor.getWebViewString();
		let charCodes = getCharCodes(webString); 
		let charCodesString = JSON.stringify(charCodes);
		window.AppInventor.setWebViewString(charCodesString);

works for me

image

blocks

I took a shot at adding the WebViewer event to show the changed WebViewString when it was ready, but it was not enough.

There's something in your Javascript, beyond my Javascript skills:

function getCharCodes(s) {     
let charCodeArr = [];         
 for (let i = 0; i < s.length; i++) {
	 let code = s.charCodeAt(i);
	 charCodeArr.push(code);     }
	 return charCodeArr; } 
 let webString = window.AppInventor.getWebViewString(); 
 // Ensure charCodes is an array by wrapping it in square brackets;
let charCodes = [getCharCodes(webString)]; 
 let charCodesString = charCodes.toString();  
 window.AppInventor.setWebViewstring(charCodesString);

setWebViewString

Unfortunately, neither fix changed anything on screen after the button push.
data_over_sound1.aia (2.4 KB)

function getCharCodes(s) {     
let charCodeArr = [];         
 for (let i = 0; i < s.length; i++) {
	 let code = s.charCodeAt(i);
	 charCodeArr.push(code);     }
	 return charCodeArr; } 
 let webString = window.AppInventor.getWebViewString(); 
 // Ensure charCodes is an array by wrapping it in square brackets;
let charCodes = [getCharCodes(webString)]; 
 let charCodesString = JSON.stringify(charCodes);
 window.AppInventor.setWebViewString(charCodesString);

It's working after removing the comment line :

function getCharCodes(s) {     
let charCodeArr = [];         
 for (let i = 0; i < s.length; i++) {
	 let code = s.charCodeAt(i);
	 charCodeArr.push(code);     }
	 return charCodeArr; } 
 let webString = window.AppInventor.getWebViewString(); 

let charCodes = [getCharCodes(webString)]; 
 let charCodesString = JSON.stringify(charCodes);
 window.AppInventor.setWebViewString(charCodesString);
1 Like

Tried everything in companion and apk but didn't work neither. Maybe I can try for loop and variables in AI and just ascii converter for js.

Did you read this?

did you read this:

Yes. Can you provide .aia maybe?

Didn't work

you post 3 posts but nothing helps us to help you.
maybe you upload your aia here.

data_over_sound1.aia (2.2 KB) @Kevinkun

I changed nothing, but it's working.

Not in iOS companion app. Plus Bluestacks

You did not mention this in previous posts.

@Kevinkun here

worked in bluestacks this time