Using the code:
function createNewBody(name,mass)
if not world.body[name]==nil then
print("This body has already been created. Maybe you meant to update it's values?\n")
else
world.body[name]={mass=m,x=0,y=0,xAccel=0,yAccel=0,xR=0,yR=0,properties={gaseous=false,texture=""}}
world.bodies=world.bodies+1
end
end
This code shows no errors, but when I bind createNewBody(moon,1.622) to a key and then use it, it lets me spam the key without showing the error message.
And, yes, I have defined world.bodies and world.body
not world.body[name]==nil is parsed as (not world.body[name])==nil. Since the result of not is a boolean, it is never nil.
Try not(world.body[name]==nil) or world.body[name]~=nil.
Related
I personally don't know how a built in function can be indexed as "nil" butthis error appeared and it haulted my nextbot's movement. heres my code that is causing this
if (!self:GetPlayerVisible() and chasing_timer > chasing_time) then
self.stopchasing = true
self.enraged = false
print("Chase stopped")
print("Increasing escaped chases count, new:", self.escapedchases)
self.escapedchases = self.escapedchases + 1
end
I tried replacing the "!" with "not" but it did nothing.
I don't know what self is but that table does not contain an element GetPlayerVisible. Hece you may not call it. Calling nil values doesn't make sense.
Ask yourself why you think this function exists. Typical reasons are typos, indexing the wrong table or not having implemented a function yet.
To avoid this error you basically have two options. Make sure you call something that exists, or don't call it.
I'm using Sysdig to capture some events and have a small chisel (LUA script) to capture and format the events as necessary. On the on_init() I'm requesting fields like so :
f_field = chisel.request_field("<field>")
My question is how can I check if a field exists before requesting it? I'm going to use a new field only just released on 0.24.1 but ideally I'd like my chisel to continue to work on older versions of sysdig without this field. I've tried wrapping the call to chisel.request_field in a pcall() like so :
ok, f_field = pcall(chisel.request_field("<field>"))
and even implementing my own "get_field" function :
function get_field(field)
ok, f = pcall(chisel.request_field(field))
if ok then return f else return nil end
end
f_field = get_field("<field>")
if f_field ~= nil then
-- do something
end
but the error ("chisel requesting nonexistent field <field>") persists.
I can't see a way to check if a field exists but I can't seem to handle the error either. I really don't want multiple versions of my scripts if possible.
Thanks
Steve H
You're almost there. Your issue is in how you're using pcall. Pcall takes a function value and any arguments you wish to call that function with. In your example you're passing the result of the request_field function call to pcall. Try this instead..
ok, f = pcall(chisel.request_field, "field")
pcall will call the chisel method with your args in a protected mode and catch any subsequent errors.
I have imported to my MediaWiki site the it.Wikipedia Modulo:Bio but I get this error:
Error Lua in Module:Bio line 700: attempt to index field 'wikibase' (a nil value).
In line 700 I have this code:
local entity = mw.wikibase.getEntityObject()
I have multiple wikis that shares the same source code, and the same database, but with its own tables. Then my wikibase is mybase.mywiki.com.
I tried to solve by changing wikibase to mybase:
local entity = mw.mybase.getEntityObject()
But it doesn't work.
The problem is not wikibase: the error simply says that there is no field named wikibase in the mw table, so the problem is that mw doesn't contain what you think it should. You must find the code that puts wikibase field in mw. If it does something like mw.wikibase = something and something is nil, then it is as if that line had not executed (it is not an error to assign nil to a table field, it is like removing the field if it exists already, and doing nothing if it doesn't exist). This is common error when something is an function call, the function may return nil under some circumstances.
I am trying to get a trigger that will show with the sunfire debuff has less time then my nature's grace buff. the lua calls seem to be pulling the correct number, but it is constantly returning true?
function ()
_,_,_,_,_,_,sundur= UnitDebuff("target","Sunfire","player");
_,_,_,_,_,_,NGDur= UnitAura("player","Nature's Grace");
if sundur and NGDur then
if sundur<NGDur+2 then
return true
else
return false
end
end
end
The issue i found was that the ad don was allowing the declared variables to be saved globally which was causing it not to be updated properly even as i changed them. I also had to change one part of code, removing the "" around player only on the uniteDebuff "caster" filter.
local _,_,_,_,_,_,sundur= UnitDebuff("target","Sunfire",player);
I have a method that displays a validation result using the syntax
Box::info(message,title);
However, the first time I run the code it displays the correct title, but the message refreshEx.
Debugging the code the message that is being used is correct, Valid Account Number, but what displays is refreshEx. If I rerun the process the correct message is displayed, this only happens the first time.
Just in case it matters the flow is
Form - DoValidation method creates Class to call...
Class - public AccountValidation method that calls...
- private displayValidation method that contains this code
Thanks...
I have seen this error (unfortunately), in an AX 2009 installation, launched from code behind a button in a form:
if(HIEItemOrderSetup.RMAvailable < HIEItemOrderSetup.RMQuantity)
{
ok = DialogButton::Ok == box::okCancel("#HIE848",DialogButton::Ok,"#HIE849");
}
As far as I can tell it only occurs when you have a breakpoint on your form, when you are updating it. Removing the breakpoint will show the original message or at least this is what I have found.
If the message contains some fields from the database, try to execute a reread() or refresh() or refreshEx() method (depending on the context) to the datasource before showing the value through the info box.
May be the cached data is not refreshed after an update or insert.
EDIT:
If you are specting a return parameter from an Event, don't forget that this is an async process. An example on MSDN:
http://msdn.microsoft.com/en-us/library/gg843664.aspx