Jump to content
  • 0

another pair of eyes to see what i'm missing re: gg.prompt


Tonos

Question

The most recent thread I found mildly relevant had no activity for over a year and though I am a fan of necromancy I know it's frowned upon by most widdards. I think I'm having problems with syntax but I cannot find my screwup. gg.prompt returning nil despite having value

 

my debugging code:

local num = gg.prompt(
	    {'BigNumber; Td = 42, qd = 45, Qd = 48, sd=51, Sd=54, Od=57, Nd = 60, V = 63, uV = 66, DV = 69, TV =72'},
	    {[1]='3.861e69'},
	    {'text'}
)
alert(num[1])

my error:

Script ended:
Script error: luaj.o: /storage/emulated/0/Notes/bocks.lua:6
`alert(num[1])`
attempt to call a nil value (global 'alert')
level = 1, const = 7, proto = 0, upval = 1, vars = 5, code = 15
CALL v1..v2
 ; PC 13 CODE 0100405D OP 29 A 1 B 2 C 1 Bx 1025 sBx -130046
stack traceback:
	/storage/emulated/0/Notes/bocks.lua:6 in main chunk
	[Java]: in ?
	at luaj.LuaValue.a(src:2835)
	at luaj.LuaValue.Z(src:1966)
	at luaj.LuaValue.a(src:1419)
	at luaj.LuaClosure.a(src:534)
	at luaj.LuaClosure.l(src:160)
	at android.ext.Script.d(src:6056)
	at android.ext.Script$ScriptThread.run(src:5785)

Guidance to what I'm missing I feel like it's going to be impressively trivial

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

You are misinterpreting the error. "Attempt to call a nil value" in this case means that global variable "alert" has nil value. There isn't such default function in Lua. For logging something you can use "print" function or "gg.alert" function from GG API, if you intend to display an alert dialog.

Update: original topic has been edited with different question, so the above doesn't apply anymore. Don't do this in future, please.

Error from the current question is simply because of attempt to use a function before defining it. Move function definition before it's usage.

Link to comment
Share on other sites

Thanks for the catch that got it to do the alert but I'm still getting effectively the same error...

code:

local num = gg.prompt(
	    {'BigNumber; Td = 42, qd = 45, Qd = 48, sd=51, Sd=54, Od=57, Nd = 60, V = 63, uV = 66, DV = 69, TV =72'},
	    {[1]='3.861e69'},
	    {'text'}
)
--gg.alert(num[1])
--gg.alert(num[2])
--gg.alert(num[3])            
---[[
local me = gotta_keep_em_separated(num[1],"e")
local low = me[1] - 0.001
local high = me[1] + 0.001
local i = 0
gg.clearResults()
gg.searchNumber(low..'e'..me[2], gg.TYPE_DOUBLE, false, gg.SIGN_GREATER_OR_EQUAL)
repeat
    gg.refineNumber(high..'e'..me[2], gg.TYPE_DOUBLE, false, gg.SIGN_LESS_OR_EQUAL)
    gg.refineNumber(low..'e'..me[2], gg.TYPE_DOUBLE, false, gg.SIGN_GREATER_OR_EQUAL)
    i = i +1
until(i>15)
gg.getResults(gg.getResultsCount())    
gg.editAll(me[1].."e"..me[2]+9, gg.TYPE_DOUBLE)

function gotta_keep_em_separated(em,separated)
    if separated==nil then
        separated = "%s"
    end
    local t={}
    for str in string.gmatch(em, "([^"..separated.."]+)") do
        table.insert(t,str)
    end
    return t
end
--]]    

error:

Script ended:
Script error: luaj.o: /storage/emulated/0/Notes/bocks.lua:10
`local me = gotta_keep_em_separated(num[1],"e")`
attempt to call a nil value (global 'gotta_keep_em_separated')
level = 1, const = 22, proto = 1, upval = 1, vars = 10, code = 81
CALL v1..v3 v1..v1
 ; PC 14 CODE 0180805D OP 29 A 1 B 3 C 2 Bx 1538 sBx -129533
stack traceback:
	/storage/emulated/0/Notes/bocks.lua:10 in main chunk
	[Java]: in ?
	at luaj.LuaValue.a(src:2835)
	at luaj.LuaValue.Z(src:1966)
	at luaj.LuaValue.a(src:1453)
	at luaj.LuaClosure.a(src:539)
	at luaj.LuaClosure.l(src:160)
	at android.ext.Script.d(src:6056)
	at android.ext.Script$ScriptThread.run(src:5785)

 

Link to comment
Share on other sites

22 minutes ago, CmP said:

You are misinterpreting the error. "Attempt to call a nil value" in this case means that global variable "alert" has nil value. There isn't such default function in Lua. For logging something you can use "print" function or "gg.alert" function from GG API, if you intend to display an alert dialog.

Update: original topic has been edited with different question, so the above doesn't apply anymore. Don't do this in future, please.

Error from the current question is simply because of attempt to use a function before defining it. Move function definition before it's usage.

24 minutes ago, CmP said:

You are misinterpreting the error. "Attempt to call a nil value" in this case means that global variable "alert" has nil value. There isn't such default function in Lua. For logging something you can use "print" function or "gg.alert" function from GG API, if you intend to display an alert dialog.

Update: original topic has been edited with different question, so the above doesn't apply anymore. Don't do this in future, please.

Error from the current question is simply because of attempt to use a function before defining it. Move function definition before it's usage.

I attempted to fix it before anyone commented but you were too swift so I reverted it back to the original. I'll not make the edits after the post. So your response would still be relevant and yet I failed again. Thanks for the assist. I assumed I could define functions anywhere and have it operate.

Link to comment
Share on other sites

48 minutes ago, Tonos said:

I attempted to fix it before anyone commented but you were too swift so I reverted it back to the original.

The only downside of that is that my post has become outdated once again, i.e. would need another update. But I will just leave it as is, since current post clarifies the situation with it.

Thank you for understanding and fix attempt. Hopefully, this has shown the importance of being careful with editing posts and especially topic starting ones.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.