Discuss Scratch

Rock-Joen
Scratcher
48 posts

Help With An Apps Script Function

This might be off topic for Help With Scripts, but I am really looking for help.
So this is my script,

function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu(“Facts”)
.addItem(“2s”, ‘factsMake(1)’)
.addItem(“3s”, ‘factsMake(3)’)
.addItem(“4s”, ‘factsMake(4)’)
.addItem(“5s”, ‘factsMake(5)’)
.addItem(“6s”, ‘factsMake(6)’)
.addItem(“7s”, ‘factsMake(7)’)
.addItem(“8s”, ‘factsMake(8)’)
.addItem(“9s”, ‘factsMake(9)’)
.addSeparator()
.addItem(“Check Facts”, “checkFacts”)
.addToUi();
}

and i keep getting an error that “factsMake(2-9) is not a function”. I am trying to call a function that does exist though. It needs an input to run properly, but when I give it the input, it says that error.

Last edited by Rock-Joen (Jan. 20, 2025 20:33:34)

redspacecat
Scratcher
500+ posts

Help With An Apps Script Function

What is the definition of “factsMake()”?
Is it in the same file?
Does it work without the input?

Also, maybe change the title to “Help with a Google Apps Script function”, because although similar, this is not javascript

Last edited by redspacecat (Jan. 20, 2025 18:38:04)

mybearworld
Scratcher
1000+ posts

Help With An Apps Script Function

Are you sure you're supposed to provide ‘factsMake(9)’ and so on as strings?
Rock-Joen
Scratcher
48 posts

Help With An Apps Script Function

redspacecat wrote:

What is the definition of “factsMake()”?
Is it in the same file?
Does it work without the input?

Also, maybe change the title to “Help with a Google Apps Script function”, because although similar, this is not javascript
So from what I know, Apps script has it's own language but also uses java script depending on what you choose. In fact, when creating a script it asks for whether you want to use javascript or HTML. Also, it is in the same file to a certain point. But the problem is is that the function requires a number, (hence the (num) at the end of it) and whenever I run it, it says that makeFacts(insert num here) is not a variable. It works though when I remove the (num here) at the end of it, at least, to a certain degree. (It just doesn't give me errors.)
BigNate469
Scratcher
1000+ posts

Help With An Apps Script Function

Rock-Joen wrote:

redspacecat wrote:

snip
So from what I know, Apps script has it's own language but also uses java script depending on what you choose.
Incorrect- Google Script is technically JS but it doesn't follow the language specs on APIs and such. Basically, it has the same syntax, but the way you interact with things is different- kind of like the diffrence between Node.js and a browser's implementation of JS.

That's why V8 can parse it (and does)- it just runs on Google's servers (rather than the client device) and uses APIs available there.

There is an option to go back to an older JavaScript engine, which only supports ES6 and earlier, which might be what you're thinking of.
redspacecat
Scratcher
500+ posts

Help With An Apps Script Function

Rock-Joen wrote:

redspacecat wrote:

What is the definition of “factsMake()”?
Is it in the same file?
Does it work without the input?

Also, maybe change the title to “Help with a Google Apps Script function”, because although similar, this is not javascript
So from what I know, Apps script has it's own language but also uses java script depending on what you choose. In fact, when creating a script it asks for whether you want to use javascript or HTML. Also, it is in the same file to a certain point. But the problem is is that the function requires a number, (hence the (num) at the end of it) and whenever I run it, it says that makeFacts(insert num here) is not a variable. It works though when I remove the (num here) at the end of it, at least, to a certain degree. (It just doesn't give me errors.)
Could I see the definition of makeFacts? (at least the first line)
mybearworld
Scratcher
1000+ posts

Help With An Apps Script Function

mybearworld wrote:

(#3)
Are you sure you're supposed to provide ‘factsMake(9)’ and so on as strings?
i.e. does something like this work?


function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu(“Facts”)
.addItem(“2s”, () => factsMake(1))
.addItem(“3s”, () => factsMake(3))
.addItem(“4s”, () => factsMake(4))
.addItem(“5s”, () => factsMake(5))
.addItem(“6s”, () => factsMake(6))
.addItem(“7s”, () => factsMake(7))
.addItem(“8s”, () => factsMake(8))
.addItem(“9s”, () => factsMake(9))
.addSeparator()
.addItem(“Check Facts”, “checkFacts”)
.addToUi();
}

Last edited by mybearworld (Jan. 21, 2025 19:54:51)

Powered by DjangoBB