Can I run a Javascript or Python file from a Defold script?

I’ve been looking online for a Lua library to run Python files, and similarly for Javascript, but I’ve had no luck. I did find Lunatic-Python, but it seems to not like Defold’s dependency system, and has not been updated in the last 2 years, so it probably wouldn’t work anyway.

What I’m trying to do is use Google Sheets API from a Defold project. I figure a Javascript file would likely already be compatible because Defold seems to go hand-in-hand with Javascript and JSON files already.

I would prefer running a Python file, as I’m only just getting familiar with JS, but either way works. I want to be able to get one of these two options working for a Jam that is starting in a few days.

If someone could point me to an example, or library to use, I’d be very appreciative.

Oh, so running Python from Lua? To interact with a Google Sheet? Sounds crazy! :slight_smile:

What exactly do you need to do with the Google Sheet? And on which platforms?

Yeah, it’s a bit of a stretch, but I wanted to see if I could get it to work because I was familiar with it.

I just need it as a simple scoring system. I would send the score to the Python or JS file, and then either could access the API and input the new info. I could then retrieve the info freely at any time to write the highscores on screen without having to mess with any type of server system.

This would be on PC, so Windows, and preferably also Mac and Linux.

Well, you are messing with a server, albeit a Google Docs one… :slight_smile:

You could use os.execute() and bundle a python script with your app.

os.execute("python myscript.py 12345")

But that would expect the user to have Python installed.

True. :stuck_out_tongue:

Sadly, that wouldn’t work. It has to be a stand-alone solution.

The options I’ve found so far:

  • Run a Python or JavaScript file with new score info (Not possible without os.execute?)
  • Compile a JavaScript or Python file in Lua (Imports break?)

I’ve found a few library’s for JavaScript to Lua compilers, but I don’t believe those would work either. In order for the API to work, it requires a Google authentication dependency, which I don’t believe I can get in Lua. If I were to compile the Javascript file to Lua, I’m pretty sure the dependency would no longer work.

Honestly this seems to be way too unsupported to be worth it.

I may have a solution. I can make the Python file standalone and have the OS execute it from the directory, instead of using the Python interpreter (which most people probably wouldn’t have).

1 Like

Yes, that would work. For things such as highscores the PlayFab SDK would be an option though. Quite easy to use.

Thanks. I took a look at that beforehand, but I couldn’t understand much of what was going on in the examples, so I started looking for different options.