console.log(runtime.objects.EmailBodyInput.Text); // Log the whole object to see what it contains var emailBody = runtime.objects.EmailBodyInput.Text; if (emailBody) { emailBody = emailBody.replace(/\r\n/g, '\n'); // Normalize line endings runtime.globalvars.emailBody = encodeURIComponent(emailBody); consol.log(emailBody); } else { console.error("EmailBodyInput.Text is undefined."); }
And I get EmailBodyInput.Text undefined. Know full well it contains text. Trying to clean up some line endings that aren't working as intended when I ajax them to my server.
Thanks.
You are getting the object type, and that doesn’t have a text property. You need to get the instance from the type to be able to access text I imagine. Refer to the docs, tutorials or examples on how to correctly access an instance.
See the Learn JavaScript in Construct course or the quick-start guide which covers the basics of accessing objects from JavaScript. I'd also recommend using TypeScript which will catch coding mistakes like this for you so probably save a lot of trouble.
var emailObject = runtime.objects.EmailBodyInput.getFirstPickedInstance();
var emailBody = emailObject.Text()
you need to get an instance first.
var emailObject = runtime.objects.EmailBodyInput.getFirstPickedInstance(); var emailBody = emailObject.Text() you need to get an instance first.
Develop games in your browser. Powerful, performant & highly capable.
Thanks Ashley. I try really hard to avoid using direct JS as I'm not that good at it. I have so many languages and API's in my head now for this and that IDE that I end up trying to jam Pascal into PHP code.