The Cartooners Posted September 6, 2008 Share Posted September 6, 2008 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? Quote Link to comment
+Geofellas Posted September 6, 2008 Share Posted September 6, 2008 ... some items may not have a command named 'Drop' ... I think that is where your problem lies. You probably need to figure out how to enumerate just those that do have this command. Quote Link to comment
Ranger Fox Posted September 7, 2008 Share Posted September 7, 2008 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. Quote Link to comment
+Geofellas Posted September 10, 2008 Share Posted September 10, 2008 Shouldn't it be: GetAllOfType('zItem') rather than GetAllOfType('ZItem') ? Quote Link to comment
Ranger Fox Posted September 10, 2008 Share Posted September 10, 2008 Yes, it should. I didn't see that when I copied the function call. I was focusing on adding the nil check and not validating at the rest of the syntax. Good catch. Quote Link to comment
+Geofellas Posted September 10, 2008 Share Posted September 10, 2008 So where did you discover about "GetAllOfType" anyway? I don't see it referenced anywhere else in the forums - there must be all sorts of useful stuff like that around that we only find out about by luck unless someone can point to some documentation that I haven't found yet. Thanks Quote Link to comment
Ranger Fox Posted September 10, 2008 Share Posted September 10, 2008 J2B2 released a Play Anywhere cartridge's code some time around January or February. In it, GetAllOfType was used to get all the zones so it could reposition them to make the cartridge Play Anywhere. That's where I learned it. Quote Link to comment
Recommended Posts
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.