Livecode and Javascript

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
JereMiami
Posts: 127
Joined: Mon Nov 03, 2014 12:17 am

Livecode and Javascript

Post 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?
SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 328
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Livecode and Javascript

Post by SWEdeAndy »

This simplification works:

Code: Select all

function add(a, b) {
    return a + b;
}

add(5, 10);
The result value is then 15.
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com
Fanny Moen
Posts: 2
Joined: Tue May 06, 2025 5:57 am
Contact:

Re: Livecode and Javascript

Post 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.
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Livecode and Javascript

Post by richmond62 »

What is the relevance of Javascript in a Livecode forum?
SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 328
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Livecode and Javascript

Post 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.
Andreas Bergendal
Independent app and system developer
Free LC dev tools: https://github.com/wheninspace
(WIS_WebDeployHelper, WIS_ScriptDependencies, WIS_BrowserAnimation)
WhenInSpace: https://wheninspace.com
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Livecode and Javascript

Post 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
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Livecode and Javascript

Post 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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Livecode and Javascript

Post 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?
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10501
Joined: Wed May 06, 2009 2:28 pm

Re: Livecode and Javascript

Post by dunbarx »

Richmond.

ChatGPT says:

https://chatgpt.com/c/681ba073-f88c-800 ... b1324cc8ce

I do not know what Scotland says.

Craig
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10415
Joined: Fri Feb 19, 2010 10:17 am

Re: Livecode and Javascript

Post by richmond62 »

Try out the code.

ChatGPT can go and b***** itself as far as I am concerned. 8)
-
Screenshot 2025-05-07 at 21.24.33.png
-
When I need a robot I'll use one I can control:
-
BBot.jpeg
BBot.jpeg (7.74 KiB) Viewed 48247 times
Post Reply