我尝试创建的程序有一个小问题。它应该计算出将能力带到一定水平需要多少exp。我还没有得到那么多,因为我在CalculateCost函数结束时返回时遇到了问题。我试图将一个字符串数组传递给名为CalculateCost的函数,但是,这不起作用,所以我尝试将所有值连接到单个字符串中。这也没有奏效。我知道我试图返回的变量不是null,因为我非常频繁地使用ui.alert()来检查变量的值。任何帮助将不胜感激。 以下是有问题的Google表格。 https://docs.google.com/spreadsheets/d/1Xo_uppFDI_C65EVi-TZ1iHTseK-Fg1izyCRkeTKaV9k/edit?usp=sharing 有问题的脚本被称为能力价格计算器。即使变量包含数据,Google脚本函数也会返回null
1
A
回答
1
看来问题是功能CalculateCost没有返回什么...
function CalculateCost(abilityValues,index,level) {
var ui = SpreadsheetApp.getUi();
var ss = SpreadsheetApp.getActive();
var sheet = ss.getActiveSheet();
ui.alert("CalculateCost");
FindRequirements(abilityValues,index,sheet,level);
// current function returns nothing!
}
/* You may have thought, "oh but CalculateCost() already does the return,
so there's no need". However, when we call a function that contains
a return, it's as though we just paste the value that it returns.
Plus, there was no command (alert, prompt, etc) at the end of your
non-return-function, which made no sense. It made no sense to Google
at least, so it was... undefined. */
所以我改成了
function CalculateCost(abilityValues,index,level) {
var ui = SpreadsheetApp.getUi();
var ss = SpreadsheetApp.getActive();
var sheet = ss.getActiveSheet();
ui.alert("CalculateCost");
var reqs = FindRequirements(abilityValues,index,sheet,level); // notice the reqs var
return reqs; // this line was missing
}
此外,我在排除代码故障时遇到了一些问题:我的主要问题是,当我们点击菜单中的CalculateCost时,通常会调用CalculateCost()函数,但实际上我们调用了InputValues()函数。当自定义函数没有绑定到相同的菜单项时,很容易迷路,所以稍后你可能会改变它。
请问,如果我的回答帮助了你的代码,你能否让我知道?
相关问题
- 1. 即使有数据库中的数据,SqlCommand也会返回null
- 2. 即使数据库中有数据,ExecuteScalar()也会返回NULL
- 3. MySQL - 即使它包含整数,也返回NULL
- 4. apache avro api的getLogicalType()函数即使存在也会返回null
- 5. 即使文件存在,php dir函数也会返回null
- 6. document.getelementbyId()即使脚本位于文件末尾也会返回null
- 7. 即使数据肯定返回,将ajax提取函数赋值给变量也会返回undefined?
- 8. 即使行数为300,ADF - ViewObject getRowAtRangeIndex也会返回null
- 9. 即使响应中包含<body>标记,HTMLUnit HtmlPage.getBody()也会返回null
- 10. MVC 4即使数据库中存在该值,也返回null
- 11. 即使rect包含点,CGRectContainsPoint()也不会返回TRUE?
- 12. getExternalFilesDir(null)即使具有READ_EXTERNAL_STORAGE权限也会返回null
- 13. Google App脚本Regex exec()仅在一个函数中返回null
- 14. 即使数据通过,函数返回null?
- 15. 即使有异常处理,Python函数也会返回NameError
- 16. 即使外函数返回,闭包如何访问外函数的变量?
- 17. 即使仍有数据,DataInputStream.readInt()也会返回EOFException
- 18. rails model.blank?即使我清除了数据库也会返回false
- 19. SQL即使没有数据也会返回行
- 20. exif_read_data()即使元数据存在于jpeg中也会返回false
- 21. 即使未返回“故障”,数据库也不会写入
- 22. R脚本函数不返回数据
- 23. 即使表数据退出,Hibernate会返回null
- 24. 变量不会从AJAX函数返回
- 25. 即使元素存在,Javascript-getElementById()也会返回null
- 26. getSupportFragmentManager()。即使片段存在,findFragmentById()也会返回null
- 27. 即使select()成功,流明调用DB :: connection()也会返回null
- 28. Android/Java CheckBox即使在初始化时也会返回null
- 29. 即使在托管bean线程中FacesContext.getCurrentInstance()也会返回null
- 30. 即使元素存在,getElementById()也会返回null
所以我忘了第二次返回变量?这让我感觉真的很愚蠢。感谢您指出这一点,它确实有帮助。 –
嘿,这表明你正在努力研究这个代码,我知道这感觉。保持它,它会完全按照你的要求进行;) –
如果解决了这个问题,我建议你将我的答案标记为“已接受”。周末愉快! –