Page 1 of 1
Livecode and Javascript
Posted: Fri Mar 14, 2025 11:30 pm
by JereMiami
If I "do [below code] with "'javascript'":
Code: Select all
function add(a, b) {
return a + b;
}
const res = add(5, 10);
console.log(res);
How do I get 15 in "the result"?
What am I missing?
Re: Livecode and Javascript
Posted: Sat Mar 15, 2025 12:44 pm
by SWEdeAndy
This simplification works:
Code: Select all
function add(a, b) {
return a + b;
}
add(5, 10);
The result value is then 15.
Re: Livecode and Javascript
Posted: Wed May 07, 2025 5:51 am
by Fanny Moen
The JavaScript code is correct and calculates 15. You may not get 15 as "result" because your environment is not set up to capture .log output or the value of the res variable directly. You may need to explicitly return res; so that it is the result.
Re: Livecode and Javascript
Posted: Wed May 07, 2025 7:15 am
by richmond62
What is the relevance of Javascript in a Livecode forum?
Re: Livecode and Javascript
Posted: Wed May 07, 2025 8:00 am
by SWEdeAndy
richmond62 wrote: ↑Wed May 07, 2025 7:15 am
What is the relevance of Javascript in a Livecode forum?
It is of great relevance if you want to extend LiveCode's capabilities to things that is normally out of its scope.
Since a long time, you've been able to run javascript in LiveCode by simply calling it through
Code: Select all
do [javascript code] with "javascript"
or by interacting with javascript running in a browser widget (or with javascript running on a web page hosting a LC web deployment).
So, while pure javascript coding issues may be better answered in other forums, the area where LiveCode and javascript intersect and communicate is very relevant to discuss here.
Re: Livecode and Javascript
Posted: Wed May 07, 2025 2:49 pm
by dunbarx
Richmond.
SWEdeAndy is spot on. HC invented the ability to run code as any OSA compliant language. Such a feature, originally focused mainly on AppleScript, but suitable in many other ways, was a powerful tool.
Craig
Re: Livecode and Javascript
Posted: Wed May 07, 2025 3:03 pm
by FourthWorld
richmond62 wrote: ↑Wed May 07, 2025 7:15 am
What is the relevance of Javascript in a Livecode forum?
Just as HyperCard was arguably the most powerful, scriptable, rich media engine included in every GUI device of its day, the browser engine is the most powerful, scriptable, rich media engine included in every GUI device today.
A growing number of LiveCode features, like the chart widget, make use of embedding the browser engine within the LC environment. And of course web deployment is fully dependent on JavaScript, since it's the only scripting language supported in browsers.
Blending the two opens many possibilities. I wouldn't mind seeing a more complete LC implementation of what Craig described: just as HyperCard allowed us to choose whether a script is written in HyperTalk or AppleScript, it would be nice to be able to choose between scripting in LiveCode or JavaScript. And given JavaScript's popularity, it might be a nice introduction to the benefits of xTalk workflows for those who enjoy that language.
Re: Livecode and Javascript
Posted: Wed May 07, 2025 6:38 pm
by richmond62
Erm:
Code: Select all
do [javascript code] as "javascript"
Mind you, fairly limited.
AND ... are there other programming languages one can leverage in the same way?
Re: Livecode and Javascript
Posted: Wed May 07, 2025 7:04 pm
by dunbarx
Richmond.
ChatGPT says:
https://chatgpt.com/c/681ba073-f88c-800 ... b1324cc8ce
I do not know what Scotland says.
Craig
Re: Livecode and Javascript
Posted: Wed May 07, 2025 7:22 pm
by richmond62
Try out the code.
ChatGPT can go and b***** itself as far as I am concerned.

-
-
When I need a robot I'll use one I can control:
-

- BBot.jpeg (7.74 KiB) Viewed 2061 times