Jump to content

Function Call


The Cartooners

Recommended Posts

I have created the following function:

 

function EnableDrop()

local txt = ""

--Identify all Items within Cartridge

local allItems = cartUphillChallenge:GetAllOfType('ZItem')

txt = txt .. "Items: " .. table.getn(allItems)

for _,item in ipairs(allItems) do

item.Commands["Drop"].Enabled = true

end

end

 

When I place the method call "EnableDrop" within the zone:OnEnter() event I receive the following error:

 

enc:960 Attempt to index field 'Drop' (a nil value)

 

I realise that there may not be any items within the zone and that some items may not have a command named 'Drop' Could that be the problem and if so how do I overcome this problem?

 

Any idease please?

Link to comment

Before I try making a test cartridge, have you tried the following?

function EnableDrop()
  local txt = ""
  --Identify all Items within Cartridge
  local allItems = cartUphillChallenge:GetAllOfType('ZItem')
  txt = txt .. "Items: " .. table.getn(allItems)
  for _,item in ipairs(allItems) do
  if item.Commands["Drop"] ~= nil then
	 item.Commands["Drop"].Enabled = true
  end
  end
end

 

In other words, have you tried testing for a nil value when you reference the command? I'm not sure if that's possible in lua, but try it. The logic seems good. If you have problems with that, I'll test some things and post something that works.

Link to comment

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.

Loading...
×
×
  • Create New...