Page 6 of 8
Re: How to check which item is in alcove?
Posted: Fri Oct 12, 2012 9:57 am
by Betalove
Now I have a seperate script for each altar. Each altar has a connector pointed to areitemsthere function. I have also tried pointing each altar to the altarhasitem function with the door not opening after all items are in place. I have tried adding connectors to both functions for each altar with the same result. The door does not open. ACK! maybe there is an easier way... I have checked all of the names and ID's. The door ID is amordoor. Altars are altar_1 - altar_4. Scripts are ID'd amoralcove_1 - armoralcove_4.
function altarHasItem(altar_1,chitin_boots_1)
for i in altar_1:containedItems() do
if i.name == "chitin_boots" then
return true
end
end
return false
end
function areitemsthere()
if altarHasItem(altar_1, "chitin_boots") and altarHasItem(altar_2, "chitin_greaves") and altarHasItem (altar_3, "chitin_mail") and altarHasItem(altar_4, "chitin_mask") then
armordoor:open()
else
armordoor:close()
end
end
Re: How to check which item is in alcove?
Posted: Fri Oct 12, 2012 10:10 am
by Filipsan
Please, use Code formatting, thanks
Again - link every altar with Lua entity (function CheckAltars)
Lua should have this code (not tested, i'm not sure about the multiple-row if syntax...)
Code: Select all
function altarHasItem(altar,item_name)
print("checking for "..item_name)
for i in altar:containedItems() do
if i.name == item_name then
print(item_name.."is there")
return true
end
end
print(item_name.."is not there")
return false
end
function CheckAltars()
if altarHasItem(altar_1, "chitin_boots")
and altarHasItem(altar_2, "chitin_greaves")
and altarHasItem(altar_3, "chitin_mail")
and altarHasItem(altar_4, "chitin_mask") then
armordoor:open()
else
armordoor:close()
end
end
Re: How to check which item is in alcove?
Posted: Sat Oct 13, 2012 3:04 am
by Betalove
I have it responding correctly with the first item placed. Then it checks the second item before it is place and returns a false. Each item placed after that is returning a false for the first item. Maybe a counter? Not sure how to set one up though. Also I have 4 scripts. One for each altar. Should this all be in one script entity?
Code: Select all
function altarHasItem(altar_1,item_name)
print("checking for "..item_name)
for i in altar_1:containedItems() do
if i.name == "chitin_boots" then
print(item_name.." is there")
return true
end
end
print(item_name.." is not there")
return false
end
function checkAltars()
if altarHasItem(altar_1, "chitin_boots")
and altarHasItem(altar_2, "chitin_greaves")
and altarHasItem (altar_3, "chitin_mail")
and altarHasItem(altar_4, "chitin_mask") then
armordoor:open()
else
armordoor:close()
end
end
Re: How to check which item is in alcove?
Posted: Sat Oct 13, 2012 9:56 am
by Filipsan
Betalove wrote:... Also I have 4 scripts. One for each altar. Should this all be in one script entity?
Yes, all in one entity
Re: How to check which item is in alcove?
Posted: Sat Oct 13, 2012 10:38 am
by Betalove
It's comming along now. However, all I have to do is place mask on altar_4 and the door opens. Also the answers are still comming back false.
Code: Select all
function altarHasItem(altar,item_name)
print("checking for "..item_name)
for i in altar_1:containedItems() do
if i.name == "chitin_boots" then
print(item_name.." is there")
return true
end
end
print(item_name.." is not there")
return false
end
function altarHasItem(altar,item_name)
print("checking for "..item_name)
for j in altar_2:containedItems() do
if j.name == "chitin_greaves" then
print(item_name.." is there")
return true
end
end
print(item_name.." is not there")
return false
end
function altarHasItem(altar,item_name)
print("checking for "..item_name)
for k in altar_3:containedItems() do
if k.name == "chitin_mail" then
print(item_name.." is there")
return true
end
end
print(item_name.." is not there")
return false
end
function altarHasItem(altar,item_name)
print("checking for "..item_name)
for l in altar_4:containedItems() do
if l.name == "chitin_mask" then
print(item_name.." is there")
return true
end
end
print(item_name.." is not there")
return false
end
function checkAltars()
if altarHasItem(altar_1, "chitin_boots")
and altarHasItem(altar_2, "chitin_greaves")
and altarHasItem (altar_3, "chitin_mail")
and altarHasItem(altar_4, "chitin_mask") then
armordoor:open()
else
armordoor:close()
end
end
Re: How to check which item is in alcove?
Posted: Sat Oct 13, 2012 11:25 am
by Komag
you can only have one function per function name.
Let me get back to you more on this in just a minute...
Re: How to check which item is in alcove?
Posted: Sat Oct 13, 2012 11:44 am
by Komag
I think it's better to split the functions into just two parts as some of the previous examples show. Here is something that works well for me:
Code: Select all
-- This function returns true if the entity contains a given item.
-- It works for any entity that implements the containedItems() method.
function alcoveContents(entity, item)
for i in entity:containedItems() do
if i.id == item then
return true
end
end
-- if we get here the item was not found
return false
end
-- function actually used to check all the alcoves
function alcoveCheck()
if alcoveContents(coolAlcove1, "coolScroll1") and
alcoveContents(coolAlcove2, "coolScroll2") and
alcoveContents(coolAlcove3, "coolScroll3") and
alcoveContents(coolAlcove4, "coolScroll4")
then
coolDoor:open()
else
coolDoor:close()
end
end
The whole thing is MUCH cleaner and shorter than your current approach. In this example I have i.id instead of i.name so I could find out specific items instead of just types of items, but you would probably use i.name for your case.
Re: How to check which item is in alcove?
Posted: Sat Oct 13, 2012 1:03 pm
by Betalove
I would still need to use the function alcoveContents four differnt times. One for each item right? v I think part of the trouble I am having is knowing where to put the name of the item or the word "item and the name of the alcove or the word entity.
Re: How to check which item is in alcove?
Posted: Sat Oct 13, 2012 1:53 pm
by Komag
yes, it's right there four times in the second function:
Code: Select all
-- This function returns true if the entity contains a given item.
-- It works for any entity that implements the containedItems() method.
function alcoveContents(entity, item) -- CUSTOMIZE: PICK A NAME FOR THIS FUNCTION, I PICKED "alcoveContents". LEAVE ENTITY, ITEM AS THEY ARE
for i in entity:containedItems() do
if i.id == item then -- CUSTOMIZE: YOU MAY WANT TO USE i.name INSTEAD OF i.id
return true
end
end
-- if we get here the item was not found
return false
end
-- function actually used to check all the alcoves
function alcoveCheck() -- CUSTOMIZE: PICK A NAME FOR THIS FUNCTION, I PICKED "alcoveCheck"
if alcoveContents(coolAlcove1, "coolScroll1") and -- CUSTOMIZE: USE THE NAME OF THE ABOVE FUNCTION IN PLACE OF "alcoveContents", USE THE ID OF YOUR FIRST ALCOVE IN PLACE OF "coolAlcove1", USE THE ID OR NAME OF THE ITEM YOU WANT THIS ALCOVE TO CHECK FOR IN PLACE OF "coolScroll1"
alcoveContents(coolAlcove2, "coolScroll2") and -- CUSTOMIZE: USE THE NAME OF THE ABOVE FUNCTION IN PLACE OF "alcoveContents", USE THE ID OF YOUR SECOND ALCOVE IN PLACE OF "coolAlcove2", USE THE ID OR NAME OF THE ITEM YOU WANT THIS ALCOVE TO CHECK FOR IN PLACE OF "coolScroll2"
alcoveContents(coolAlcove3, "coolScroll3") and -- CUSTOMIZE: USE THE NAME OF THE ABOVE FUNCTION IN PLACE OF "alcoveContents", USE THE ID OF YOUR THIRD ALCOVE IN PLACE OF "coolAlcove3", USE THE ID OR NAME OF THE ITEM YOU WANT THIS ALCOVE TO CHECK FOR IN PLACE OF "coolScroll3"
alcoveContents(coolAlcove4, "coolScroll4") -- CUSTOMIZE: USE THE NAME OF THE ABOVE FUNCTION IN PLACE OF "alcoveContents", USE THE ID OF YOUR FOURTH ALCOVE IN PLACE OF "coolAlcove4", USE THE ID OR NAME OF THE ITEM YOU WANT THIS ALCOVE TO CHECK FOR IN PLACE OF "coolScroll4"
then
coolDoor:open() -- CUSTOMIZE: PUT YOUR DOOR ID HERE
else
coolDoor:close() -- CUSTOMIZE: PUT YOUR DOOR ID HERE
end
end
Re: How to check which item is in alcove?
Posted: Sun Oct 14, 2012 10:40 am
by Betalove
I finally got it. Thank you Filipsan and Komag. Sorry it took so long. I really appreciate your help.