Error code: attempt to call a nil value [LUA] - lua

after pressing the "button2" works correctly but after a while lua turns off
error: [Lua] Error in “LUA”: attempt to call a nil value
local webHookURL = Menu.TextBox("Webhook", "Webhook URL", 148, "", "Enter your webhook URL")
local message = ("Hello!")
local function hook(msg)
Http.PostAsync(string.format("%s",webHookURL:GetString()),
string.format("content=%s",msg))
Cheat.AddNotify("neverlose.cc", "Shared! Well done!")
end
button2:RegisterCallback(function()
hook(message)
end)

The error message doesn't indicate at which line the calling is happening?
A trivial workaround is to test it before:
if type(var_that_will_be_called) == "function" then
var_that_will_be_called ()
end
But that doesn't really solve the problem, just avoid the error...

Related

Can anyone tell me that the error "calling xxxx on bad self" shows

I use lua in Unity. When I call the function **TryDisableHeadWear **, there are some error I can't understand.
calling 'GetSurfaceName' on bad self (string expected, got nil)
function def:TryDisableHeadWear()
if not self:CheckSurfaceName(self._hat_go) then
self._hat_go:SetActive(false)
end
end
function def:CheckSurfaceName(obj)
local surface_name = self:GetSurfaceName(obj)
return head_wear_surface[surface_name] ~= nil
end
local reg = "(%w+)"
function def:GetSurfaceName(obj)
if not obj then return end
local root_obj = self:GetSurfaceObj(obj)
local surface_obj_name = root_obj and root_obj.name
return surface_obj_name and string.match(surface_obj_name, reg)
end
function def:GetSurfaceObj(obj)
if string.find(obj.name, "Surface") then
return obj
else
local parent = obj.transform.parent
if not parent then return end
return self:GetSurfaceObj(parent.gameObject)
end
end
Can anyone tell me what the error means?
I try to call the function in normal environment. I get no error and everything goes well. But where are some error report in firebase that means the code above has bugs

Attempt to index a boolean value error when calling this function

I get the attempt to index a boolean value error when calling this function:
M.on_attach = function(client, bufnr)
if client.name == "tsserver" then
client.resolved_capabilities.document_formatting = false
end
lsp_keymaps(bufnr)
lsp_highlight_document(client)
end
Can anyone help me?
Edit:
I get the error on the second line here:
local opts = {
on_attach = require("s3m.lsp.handlers").on_attach,
capabilities = require("s3m.lsp.handlers").capabilities,
}
require("s3m.lsp.handlers") returns true which is a boolean value. with require("s3m.lsp.handlers").on_attach you index that nil value which is an invalid operation in Lua.
For this to make sense your required script must return a value. In your case M
require returns true if the script is loaded successfully but does not return a non-nil value. Please read the manual to avoid such errors.

I have a gLua error: bad argument #1 to 'lower' (string expected, got nil)

I want to create a command that would change your model when typing "!swap" and make it so it would return to your previous model when you type it again and repeat.
I have tried ending the function and continuing on but that hasn't worked. I need someone to explain the error as I have never seen it before and google/gmod wiki doesn't show it either.
hook.Add( 'PlayerSay', 'PlayerSayExample', function (ply, text, team)
end )
if ( string.sub( string.lower( text ), 1, 5 ) == "!swap" ) then
local model = ply:GetModel()
function GM:PlayerSetModel( ply ) end
else
end
if model == ("models/Kleiner.mdl") then
ply:SetModel("models/Eli.mdl")
else
ply:SetModel("models/Kleiner.mdl")
end
===================================
[ERROR] lua/swap2.lua:3: bad argument #1 to 'lower' (string expected, got nil)
1. lower - [C]:-1
2. unknown - lua/swap2.lua:3
===================================
above (between the breaks) is the error I am getting. It occurs on the "string.lower" bit on line 3 but I don't know what is actually wrong with the code, as I haven't seen the error before.
hook.Add( 'PlayerSay', 'PlayerSayExample', function (ply, text, team)
end )
Means that your hook is empty.
If you do not define text before or after the hook, text is nil and will always throw this error. Here is your fix:
hook.Add( 'PlayerSay', 'PlayerSayExample', function (ply, text, team)
if ( string.sub( string.lower( text ), 1, 5 ) == "!swap" ) then
local model = ply:GetModel()
function GM:PlayerSetModel( ply ) end
else
end
if model == ("models/Kleiner.mdl") then
ply:SetModel("models/Eli.mdl")
else
ply:SetModel("models/Kleiner.mdl")
end
end )

Lua : return table trough function is nil

I get the error: source_file.lua:5: attempt to call a nil value (global 'getCard')
i try to catch the right table in questCards which Index=name is the same as the given string from objName
questCards={{['name']='test1',['creatureName']='test3'},{['name']='test2',['creatureName']='test4'}}
obj='test1'
card=getCard(obj)
card['creatureName']=nil --Only for test purpose
if card['creatureName']==nil then
--do Somthing
end
function getCard(objName)
for k,v in pairs(questCards) do
if v['name']==objName then
return v
end
end
end
The error message is telling you that getCard is not defined at the point where it is called.
You need to define getCard before calling it.

HTTP GET in LUA/NodeMCU

I'm trying to send a HTTP GET each time I press a button :
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PWD")
function loop()
if wifi.sta.status() == 5 then
-- Stop the loop
tmr.stop(0)
else
print("Connecting...")
end
end
tmr.alarm(0, 100, 1, function() loop() end)
print(wifi.sta.getip())
outpin_led = 1
inpin_button = 3
gpio.mode(outpin_led,gpio.OUTPUT)
gpio.mode(inpin_button,gpio.INPUT)
light_on = false
function light()
if not light_on then
-- turn the light on
gpio.write(outpin_led,gpio.HIGH)
light_on = true
http.get("https://google.com", function(clt, data)
print(data)
end)
else
-- turn the light off
gpio.write(outpin_led,gpio.LOW)
light_on = false
end
end
gpio.trig(inpin_button,"down",light)
The line containing http.get is throwing this error message :
> PANIC: unprotected error in call to Lua API (stdin:6: attempt to index global 'http' (a nil value))
I made sure my NodeMCU build contained the http module by compiling it through http://nodemcu-build.com/
Any idea ?
Thanks.
As Marcel Stör pointed out, it was indeed an issue during the flashing of the firmware.
Thanks a lot for your reply and for your work on http://nodemcu-build.com/.

Resources