Page 1 of 1
Spawn/Destroy Items in different alcoves at the same time
Posted: Sat Aug 02, 2014 7:45 pm
by maneus
Can someone please tell me how I can destroy or spawn objects in different alcoves at the same time? Every alcove has the same item inside and I will remove all the items by one script at the same time and later spawn inside every alcove the same item.
I´ve tried to use the following code but without any success:
Code: Select all
for i in entitiesAt(6,6,4) and
entitiesAt(6,6,3) and
entitiesAt(6,5,4) and
entitiesAt(6,5,3) do
if i.name == "dagger" then
i:destroy()
Re: Spawn/Destroy Items in different alcoves at the same tim
Posted: Sat Aug 02, 2014 7:54 pm
by Isaac
Offhand [very offhand], You would probably want to recursively check the alcoves themselves, for the dagger, and destroy them.
Re: Spawn/Destroy Items in different alcoves at the same tim
Posted: Sat Aug 02, 2014 8:11 pm
by maneus
Yes, Isaac. That is true. I´ve tried to use the
Code: Select all
for i in myalcove:containedItems() and
myalcove2:containedItems() do
if i.name == "dagger" then
i:destroy()
but this works only for one alcove and not for more.
And destroy an alcove destroyed only the alcove and not the item inside.
Re: Spawn/Destroy Items in different alcoves at the same tim
Posted: Sat Aug 02, 2014 8:51 pm
by Isaac
maneus wrote:Yes, Isaac. That is true. I´ve tried to use the
Code: Select all
for i in myalcove:containedItems() and
myalcove2:containedItems() do
if i.name == "dagger" then
i:destroy()
but this works only for one alcove and not for more.
And destroy an alcove destroyed only the alcove and not the item inside.
You would write a FOR loop that redefines the target alcove each run through the loop... Something like: alcove = findEntity(alcove_id..x)
*Where "alcove_id" could be 'dungeon_alcove_'. This would make the "alcove" variable point to dungeon_alcove_1, dungeon_alcove_2, dungeon_alcove_3 ...
**Edit: I changed 'name' to 'id' for clarity.
Re: Spawn/Destroy Items in different alcoves at the same tim
Posted: Sat Aug 02, 2014 9:13 pm
by maneus
Thank you Isaac.
So a "x" instead of a number will search for all objects with the same id? Is that right?
Re: Spawn/Destroy Items in different alcoves at the same tim
Posted: Sat Aug 02, 2014 9:25 pm
by minmay
If your alcoves were called "myalcove1", "myalcove2", "myalcove3", and "myalcove4" then you could use code like this:
Code: Select all
for h = 1, 4 do
for i in findEntity("myalcove"..h):containedItems() do
if i.name == "dagger" then i:destroy() end
end
end
The expression
makes a string that is the value of h appended to "myalcove". So if h is 3, then it will result in "myalcove3".
As for your original approach, the "and" keyword in Lua is just a logical operator. Take a look at the
Lua manual. It looks like you tried to use it to combine two iterators - you can't really do that. The "containedItems()" function returns an iterator; "for i in myalcove:containedItems() do [whatever] end" takes that iterator, gets the next item from it, runs [whatever], then repeats until the iterator runs out of items.
The expression "myalcove:containedItems() and myalcove2:containedItems()" has the same result as the expression "myalcove2:containedItems()". The "and" operator just returns its first argument if it is false or nil, and otherwise returns the second, which is what's happening here.
Re: Spawn/Destroy Items in different alcoves at the same tim
Posted: Sat Aug 02, 2014 9:27 pm
by Isaac
maneus wrote:Thank you Isaac.
So a "x" instead of a number will search for all objects with the same id? Is that right?
No...
Code: Select all
for x = 1,16 do
alcove = findEntity("dungeon_alcove_"..x)
end
In this loop, x will mean 1 through 16 as the loop repeats. So the second time the loop runs, "alcove" will point to the entity "dungeon_alcove_2".
Re: Spawn/Destroy Items in different alcoves at the same tim
Posted: Sun Aug 03, 2014 2:39 pm
by maneus
Thank you minmay and Isaac. I get it to work.
