How to check which item is in alcove?
How to check which item is in alcove?
How exactly would I got about checking which item(s) is/are in an alcove?
The documentation mentions Alcove:containedItems() but I can't for the life of me figure out how to use it.
The documentation mentions Alcove:containedItems() but I can't for the life of me figure out how to use it.
Re: How to check which item is in alcove?
You need to iterate through the names of the containedItems. It's a little complicated but here's a small script I whipped up to demonstrate how you can do it/what you can do with it:
Code: Select all
function checkAlcoveForItems()
-- change these variables to match your alcove's ID and the item you want to test for
local itemName = "dagger"
local alcoveID = dungeon_alcove_1
-- iterate through all the contained items on alcove, checking for a matching name
for i in alcoveID:containedItems() do
if i.name == itemName then
itemFound()
else
itemNotFound()
end
end
end
-- run this script _once for each item_ with a matching name
function itemFound()
playSound("level_up")
end
-- run this script _once for each item_ without a matching name
function itemNotFound()
spawn("poison_cloud", party.level, party.x, party.y, 0)
end
Steven Seagal of gaming industry
Re: How to check which item is in alcove?
Another example (not tested):
Code: Select all
-- a helper function which returns true if alcove contains the given item
function containsItem(alcove, item)
for it in alcove:containedItems() do
if it.name == item then
return true
end
end
return false
end
-- example usage
if containsItem("alcove1", "dagger") then
print("alcove contains a dagger")
else
print("alcove does not contain a dagger")
end
Re: How to check which item is in alcove?
First of all, well done for this wonderful editor!
I have a somewhat related problem with the daemon head.
Using the editor I can say that each eye socket can activate a door using a gem. But I can't make the door open on the condition that BOTH gems are inserted.
I know nothing about lua but I wanted to give it a go. The problem is that there's no reference to the daemon head in the ressources and I couldn't guess what term to use.
Is it something like eye_socket_left_1:containedItems() or something else.
Edit: Nevermind, just found out that it works like locks with "counter"
I have a somewhat related problem with the daemon head.
Using the editor I can say that each eye socket can activate a door using a gem. But I can't make the door open on the condition that BOTH gems are inserted.
I know nothing about lua but I wanted to give it a go. The problem is that there's no reference to the daemon head in the ressources and I couldn't guess what term to use.
Is it something like eye_socket_left_1:containedItems() or something else.
Edit: Nevermind, just found out that it works like locks with "counter"
Re: How to check which item is in alcove?
I want a door to open when putting the correct item in an alcove, but for the door to shut when taking it out. when I tried this:
I just get a crash-to-editor with "attempt to call method 'containedItems' (a nil value)" next to the second to top line.
If I try this:
It works to open the door, but the door won't close when I take out the blue gem (although it will close if it put in some other wrong item)
Code: Select all
function gemCheckblue(alcoveblue, blue_gem)
for i in alcoveblue:containedItems() do
if i.name == "blue_gem" then
return true
end
end
return false
end
if gemCheckblue("alcoveblue", "blue_gem") then
doorblue:open()
else
doorblue:close()
end
If I try this:
Code: Select all
function gemCheckblue()
for i in alcoveblue:containedItems() do
if i.name == "blue_gem" then
doorblue:open()
else
doorblue:close()
end
end
end
Finished Dungeons - complete mods to play
Re: How to check which item is in alcove?
The first one crashes because in your code the first argument alcoveblue has a string value when you need an object reference. So you are trying to do "alcoveblue":containedItems() which obviously doesn't work.
Re: How to check which item is in alcove?
...[trying to comprehend...]
I'm afraid my attempt to comprehend failed. I'm guessing I need quotes somewhere I don't have them or else I need to remove quotes somewhere I have them?
If I remove the quotes in the "if gemCheckblue(alcoveblue, blue_gem) then" line, it will run, but as soon as I place a blue gem, it crashes with "Attempt to index local 'alcoveblue' (a nil value)"
I'm afraid my attempt to comprehend failed. I'm guessing I need quotes somewhere I don't have them or else I need to remove quotes somewhere I have them?
If I remove the quotes in the "if gemCheckblue(alcoveblue, blue_gem) then" line, it will run, but as soon as I place a blue gem, it crashes with "Attempt to index local 'alcoveblue' (a nil value)"
Finished Dungeons - complete mods to play
Re: How to check which item is in alcove?
using the simpler script:
this works to open the door, but not to close it when removing the gem. I have the alcove lined to the script with "any". If I add a link from the alcove directly to the door with "deactivate-close" it works, but why doesn't the script do it?
Code: Select all
function gemCheckblue()
for i in alcoveblue:containedItems() do
if i.name == "blue_gem" then
doorblue:open()
else
doorblue:close()
end
end
end
Finished Dungeons - complete mods to play
Re: How to check which item is in alcove?
I have two mouth sockets attached to a counter with activation as decrement and deactivation as increment.
Counter intial state at 2.
Hook the counter to the door(s) and voila, requires both sockets to be filled before the door will open.
I believe this is can be adapted to your problem.
Counter intial state at 2.
Hook the counter to the door(s) and voila, requires both sockets to be filled before the door will open.
I believe this is can be adapted to your problem.
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
- Message me to join in!
Re: How to check which item is in alcove?
Yes I'm very familiar with that general solution (a good one usually!). Unfortunately that doesn't quite apply to my problem in this case. In fact, if I set it up with a counter, the deactivate-increment never happens, so putting in the gem the first time decrements and opens the door, but taking out doesn't increment, thus the door stays open, and then putting back in decrements further, closing the door, never to open again
so the problem is, why on earth doesn't the
ever do the something???
so the problem is, why on earth doesn't the
Code: Select all
else
dosomething
Finished Dungeons - complete mods to play