How to check which item is in alcove?
Re: How to check which item is in alcove?
Great. Thanks everyone. This final iteration seems to work well and is presumably more efficient. This should probably go in the scripting thread if it's not already.
Puzzle Frameworks - http://www.grimrock.net/forum/viewtopic.php?f=14&t=4564
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
Magic Pack - https://www.nexusmods.com/grimrock/mods/70
Area of Effect Spell System - http://www.grimrock.net/forum/viewtopic ... 150#p44382
- Montis
- Posts: 340
- Joined: Sun Apr 15, 2012 1:25 am
- Location: Grimrock II 2nd playthrough (hard/oldschool)
Re: How to check which item is in alcove?
As the previous posters said: break does break out of your innermost loop, return breaks out of the complete function and let's the function return values if need be.
Re: How to check which item is in alcove?
yes, I've already added it to the script repository (under 1.1.7)
Finished Dungeons - complete mods to play
Re: How to check which item is in alcove?
I would write it like this (less redundancy and cleaner control flow):
This could also be generalized to:
Code: Select all
function gemCheckblue()
local itemFound = false
for i in alcoveblue:containedItems() do
if i.name == "blue_gem" then
itemFound = true
end
end
if itemFound then
doorblue:open()
else
doorblue:close()
end
end
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 containsItem(entity, item)
for i in entity:containedItems() do
if i.name == item then
return true
end
end
-- if we get here the item was not found
return false
end
-- example usage
if containsItem(alcoveblue, "blue_gem") then
doorblue:open()
else
doorblue:close()
end
Re: How to check which item is in alcove?
ah, so that's how to apply that version, thanks!
(would be nice to do it in-editor, such as "require specific object? [] " checkbox, with entry for typing in the object)
(would be nice to do it in-editor, such as "require specific object? [] " checkbox, with entry for typing in the object)
Finished Dungeons - complete mods to play
Re: How to check which item is in alcove?
That would not be very generic. Should it require a specific id, or specific name? Or maybe require a weapon (an item with attack power)? How about requiring more than one item? Should the alcove be deactivated when another item is placed in it when the correct item is already in it? These kind of conditions are better expressed in code.Komag wrote:(would be nice to do it in-editor, such as "require specific object? [] " checkbox, with entry for typing in the object)
Re: How to check which item is in alcove?
hmm, I see, with all those possible scenarios and wants, I guess code is really the best way to go in this case
Finished Dungeons - complete mods to play
Re: How to check which item is in alcove?
I'm trying to recreate the weapon check alcove from the original game level 2, but I haven't seen any hints about how to check whether an item placed in an alcove is weapon, other than making a complete list of all the weapons and having it check for any of them specifically. There's got to be a better way! Ideas?
Finished Dungeons - complete mods to play
Re: How to check which item is in alcove?
I really like the script, but I would like to get a little trickier, and check to make sure all of several items are in the alcove before anything happens. Because my understanding of the for loop is that it runs all through the code beneath it before it changes the object that i points to, I'll have to run the brute force method of for loops inside of my for loops. Is anything more elegant possible? I'll be sure to show off my brute strength for loops once I've written those, at least!
edit:
As far as figuring out whether something is a weapon or not, maybe look around http://www.grimrock.net/modding/asset-d ... reference/. I suspect you could check for the boolean values rangedweapon, meleeweapon, or thrownweapon, or maybe even just accuracy or attackpower.
edit:
As far as figuring out whether something is a weapon or not, maybe look around http://www.grimrock.net/modding/asset-d ... reference/. I suspect you could check for the boolean values rangedweapon, meleeweapon, or thrownweapon, or maybe even just accuracy or attackpower.
Re: How to check which item is in alcove?
I did notice those but I'm not sure how to apply it to the script
Finished Dungeons - complete mods to play