Jump to content

Recommended Posts

Posted

To reproduce press A key.

When i call world:FindEntity("BoxA"):Hide() on object with no script attached it crashes with:

"attempt to index a nil value"

BoxB has some script attached and doesnt have this problem.

if (window:KeyHit(Key.A)) then
	world:FindEntity("BoxA"):Hide()
end

if (window:KeyHit(Key.B)) then
	world:FindEntity("BoxB"):Hide()
end

 

test.map

PS im on 4.5 , didnt test on 4.6 but think is the same problem

 

I made this with Leadwerks/UAK:

Structura Stacky Desktop Edition

Website:

Binary Station

Posted

It might not be obvious which thing is nil, which might help understand which link in the command chain went wrong.

I would temporarily split each bit into a local assignment and see where the problem occurs.

Like this...

 

local currentWorld = world
local boxA = currentWorld:FindEntity("BoxA")
boxA:Hide()

Also be aware that if the item you are trying to find is a prefab it may not find it as it is not an instance and I think I had a situation that it would not find it until I made it an instance.

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...