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 » Fri Mar 14, 2025 11:30 pm

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: 324
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Livecode and Javascript

Post by SWEdeAndy » Sat Mar 15, 2025 12:44 pm

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 » Wed May 07, 2025 5:51 am

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: 10076
Joined: Fri Feb 19, 2010 10:17 am

Re: Livecode and Javascript

Post by richmond62 » Wed May 07, 2025 7:15 am

What is the relevance of Javascript in a Livecode forum?

SWEdeAndy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 324
Joined: Sat Aug 16, 2008 9:48 am
Contact:

Re: Livecode and Javascript

Post by SWEdeAndy » Wed May 07, 2025 8:00 am

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: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Livecode and Javascript

Post by dunbarx » Wed May 07, 2025 2:49 pm

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: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Livecode and Javascript

Post by FourthWorld » Wed May 07, 2025 3:03 pm

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: 10076
Joined: Fri Feb 19, 2010 10:17 am

Re: Livecode and Javascript

Post by richmond62 » Wed May 07, 2025 6:38 pm

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: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: Livecode and Javascript

Post by dunbarx » Wed May 07, 2025 7:04 pm

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: 10076
Joined: Fri Feb 19, 2010 10:17 am

Re: Livecode and Javascript

Post by richmond62 » Wed May 07, 2025 7:22 pm

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 2032 times

Post Reply