this works:
Code: Select all
function gemCheckblue()
if alcoveblue:getItemCount() ~= 0 then
for i in alcoveblue:containedItems() do
if i.name == "blue_gem" then
doorblue:open()
end
end
else
doorblue:close()
end
end
Code: Select all
function gemCheckblue()
if alcoveblue:getItemCount() ~= 0 then
for i in alcoveblue:containedItems() do
if i.name == "blue_gem" then
doorblue:open()
end
end
else
doorblue:close()
end
end
I'm having problems with this script... I want to use an empty flask instead of a blue gem, so I changed the i.name field to "flask" and made sure my alcove and door were named correctly as per the script. and if I have something else on the alcove with the flask (e.g. a blue gem), I can take the flask off and the door stays open. I ticked "activate always" on the alcove and used an "any" connection to the script.Emciel wrote:the problem is when checking containedItems, the function basically fails if there's nothing there.
this works:
Code: Select all
function gemCheckblue() if alcoveblue:getItemCount() ~= 0 then for i in alcoveblue:containedItems() do if i.name == "blue_gem" then doorblue:open() end end else doorblue:close() end end
Code: Select all
function gemCheckblue()
if alcoveblue:getItemCount() == 0
then
doorblue:close()
else
for i in alcoveblue:containedItems() do
if i.name == "flask"
then
doorblue:open()
break
else
doorblue:close()
end
end
end
end
I would replace the break with a return and place the doorblue:close() after the for-loop. Then the door wouldn't get x "closes" before it get's an "open", depending on how many items are in the alcove.Grimwold wrote:OK, this script works for my flask... if the flask is on the alcove, the door is open and if it is off, the door is closed... even when there are multiple items on the alcove, and when there are no items at all. The "break" is used to stop checking items once the flask is found.. otherwise the door would sometimes close with multiple items on the alcove including the flask.
Code: Select all
function gemCheckblue() if alcoveblue:getItemCount() == 0 then doorblue:close() else for i in alcoveblue:containedItems() do if i.name == "flask" then doorblue:open() break else doorblue:close() end end end end
Code: Select all
function gemCheckblue()
if alcoveblue:getItemCount() == 0
then
doorblue:close()
else
for i in alcoveblue:containedItems() do
if i.name == "flask"
then
doorblue:open()
return
end
end
doorblue:close()
end
end