Re: (WIP) Curious Conundrum / CFD 2012 submission
Posted: Tue Dec 04, 2012 9:21 pm
Be sure your capitalization is accurate too
Official Legend of Grimrock Forums
http://mail.grimrock.net/forum/
It appears to me that all the capitalization is right, but being a total scripting newb, I can't say that with complete confidence. I copy/pasted the code out of the script entity in my dungeon to my last post with a code box, so if someone sees something, let me know.Komag wrote:Be sure your capitalization is accurate too
Grimwold wrote:Yes that's correct.. it's so you can pass it entities from your script.Redweaver wrote:Yes, the alcoves are numbered 1 - 6, and you got the right gems in the right places from my previous posts. The first part of the code, the bit from the top of your post that you told me to make sure to paste into the same script entity, seems a bit odd. It's refering to entities and items without defining them...is that right?
I'm home for dinner and am just about to go out, so can't look at it right now, but when I get back on in a few hours I will create a test dungeon and set everything up.. then I can send you the working dungeon if necessary.
Since they are functions, as long as both functions are declared before either one is called, it actually doesn't matter which order they are declared in.Redweaver wrote:Hmmmm...since that bit needs to be passed entities from the script, does it maybe need to come at the end?
The message may be an old one... try using the clr button to remove it and then replay the level, if the message re-appears then one of the spawners you have placed has an incorrect target.Redweaver wrote:Also when testing, I get a message at the top of the screen: "Warning! Unknown spawner entity type: nil". That has to be related to the cloned monsters...any ideas? The correct monsters are coming out of the correct spawners correctly, so it's likely some kind of naming issue.
Code: Select all
-- This file has been generated by Dungeon Editor 1.3.1
--- level 1 ---
mapName("Unnamed")
setWallSet("dungeon")
playStream("assets/samples/music/dungeon_ambient.ogg")
mapDesc([[
################################
################################
################################
################################
################################
################################
################################
####################.###########
###################...##########
###################....#########
###################...##########
###################...##########
###################...##########
###################...##########
###################...##########
###################...##########
###################...##########
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
################################
]])
spawn("dungeon_alcove", 19,13,3, "dungeon_alcove_1")
:setActivateAlways(true)
spawn("dungeon_alcove", 19,12,3, "dungeon_alcove_2")
:setActivateAlways(true)
spawn("dungeon_alcove", 19,11,3, "dungeon_alcove_3")
:setActivateAlways(true)
spawn("dungeon_alcove", 19,10,3, "dungeon_alcove_4")
:setActivateAlways(true)
spawn("dungeon_alcove", 19,9,3, "dungeon_alcove_5")
:setActivateAlways(true)
spawn("dungeon_alcove", 19,8,3, "dungeon_alcove_6")
:setActivateAlways(true)
spawn("dungeon_secret_door", 21,9,1, "orbdoor")
spawn("dungeon_door_wooden", 20,8,0, "exitdoor")
spawn("green_gem", 20,13,0, "green_gem_1")
spawn("red_gem", 20,12,2, "red_gem_1")
spawn("blue_gem", 20,13,1, "blue_gem_1")
spawn("starting_location", 20,15,0, "starting_location_1")
spawn("wall_button", 21,8,0, "wall_button_3")
:addConnector("toggle", "alcove_script", "checkAlcoves")
spawn("daemon_head", 21,8,1, "daemon_head_1")
spawn("script_entity", 22,11,0, "alcove_script")
:setSource(" -- 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\
\
function checkAlcoves()\
local green_correct = containsItem(dungeon_alcove_5,\"green_gem\")\
local red_correct = containsItem(dungeon_alcove_4,\"red_gem\")\
local blue_correct = containsItem(dungeon_alcove_1,\"blue_gem\")\
if green_correct and red_correct and blue_correct then\
exitdoor:open()\
return true\
end\
local green2_correct = containsItem(dungeon_alcove_2,\"green_gem\")\
local red2_correct = containsItem(dungeon_alcove_3,\"red_gem\")\
local blue2_correct = containsItem(dungeon_alcove_5,\"blue_gem\")\
if green2_correct and red2_correct and blue2_correct then\
orbdoor:open()\
return true\
end\
local gem_count = 0\
local alcove_list = {\"dungeon_alcove_1\",\"dungeon_alcove_2\",\"dungeon_alcove_3\",\"dungeon_alcove_4\",\"dungeon_alcove_5\",\"dungeon_alcove_6\"}\
for _,i in ipairs(alcove_list) do\
local alcove = findEntity(i)\
for j in alcove:containedItems() do\
if j.name:sub(-3) == \"gem\" then\
gem_count = gem_count + 1\
end\
end\
end\
if gem_count == 3 then\
spawn(\"poison_cloud\", party.level, party.x, party.y, 0)\
end\
end")
Done! Tested! Works perfectly!Grimwold wrote:OK here's a sample dungeon.
To give it a try, create a new dungeon in the editor, then close it and within Windows navigate to the folder:
Documents/Almost Human/Legend of Grimrock/Dungeons/NEW DUNGEON NAME/mod_assets/scripts
(substitute NEW DUNGEON NAME with the name of your new test dungeon)
Here you will find a file called dungeon.lua
Open this file with a text editor (e.g. notepad) and replace everything there with the following code. WARNING - DO NOT DO THIS WITH YOUR MAIN DUNGEON
Save this file and then re-load the new dungeon in the editor... you will be presented with a single large room with 6 alcoves on the left.. 3 gems on the floor, a door a button and a daemon head... the combinations are 1,4,5 and 2,3,5 as per your previous posts...Code: Select all
-- This file has been generated by Dungeon Editor 1.3.1 --- level 1 --- mapName("Unnamed") setWallSet("dungeon") playStream("assets/samples/music/dungeon_ambient.ogg") mapDesc([[ ################################ ################################ ################################ ################################ ################################ ################################ ################################ ####################.########### ###################...########## ###################....######### ###################...########## ###################...########## ###################...########## ###################...########## ###################...########## ###################...########## ###################...########## ################################ ################################ ################################ ################################ ################################ ################################ ################################ ################################ ################################ ################################ ################################ ################################ ################################ ################################ ################################ ]]) spawn("dungeon_alcove", 19,13,3, "dungeon_alcove_1") :setActivateAlways(true) spawn("dungeon_alcove", 19,12,3, "dungeon_alcove_2") :setActivateAlways(true) spawn("dungeon_alcove", 19,11,3, "dungeon_alcove_3") :setActivateAlways(true) spawn("dungeon_alcove", 19,10,3, "dungeon_alcove_4") :setActivateAlways(true) spawn("dungeon_alcove", 19,9,3, "dungeon_alcove_5") :setActivateAlways(true) spawn("dungeon_alcove", 19,8,3, "dungeon_alcove_6") :setActivateAlways(true) spawn("dungeon_secret_door", 21,9,1, "orbdoor") spawn("dungeon_door_wooden", 20,8,0, "exitdoor") spawn("green_gem", 20,13,0, "green_gem_1") spawn("red_gem", 20,12,2, "red_gem_1") spawn("blue_gem", 20,13,1, "blue_gem_1") spawn("starting_location", 20,15,0, "starting_location_1") spawn("wall_button", 21,8,0, "wall_button_3") :addConnector("toggle", "alcove_script", "checkAlcoves") spawn("daemon_head", 21,8,1, "daemon_head_1") spawn("script_entity", 22,11,0, "alcove_script") :setSource(" -- 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\ \ function checkAlcoves()\ local green_correct = containsItem(dungeon_alcove_5,\"green_gem\")\ local red_correct = containsItem(dungeon_alcove_4,\"red_gem\")\ local blue_correct = containsItem(dungeon_alcove_1,\"blue_gem\")\ if green_correct and red_correct and blue_correct then\ exitdoor:open()\ return true\ end\ local green2_correct = containsItem(dungeon_alcove_2,\"green_gem\")\ local red2_correct = containsItem(dungeon_alcove_3,\"red_gem\")\ local blue2_correct = containsItem(dungeon_alcove_5,\"blue_gem\")\ if green2_correct and red2_correct and blue2_correct then\ orbdoor:open()\ return true\ end\ local gem_count = 0\ local alcove_list = {\"dungeon_alcove_1\",\"dungeon_alcove_2\",\"dungeon_alcove_3\",\"dungeon_alcove_4\",\"dungeon_alcove_5\",\"dungeon_alcove_6\"}\ for _,i in ipairs(alcove_list) do\ local alcove = findEntity(i)\ for j in alcove:containedItems() do\ if j.name:sub(-3) == \"gem\" then\ gem_count = gem_count + 1\ end\ end\ end\ if gem_count == 3 then\ spawn(\"poison_cloud\", party.level, party.x, party.y, 0)\ end\ end")
It is working perfectly here.
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 <--- attempt to call method "containedItems" (a nil value)
if i.name == item then
return true
end
end
-- if we get here the item was not found
return false
endRedweaver wrote:I noticed something just now when combing through the code again.
Your wall button is set to hit the "checkAlcoves" script...the "real" part of the script. Mine says it's calling the "containsItem" script...the early part that's throwing the error. It populates itself with that call when I click the "add connector" button. How can I correct that?
Sorry if this is confusing... it's not actually happening early in the script... as the two functions are separate and it doesn't run top to bottom across the two.Redweaver wrote: Done! Tested! Works perfectly!
So I combed through the code here and compared it letter by letter to the code in my main dungeon script entity. They are identical. It fails in my main dungeon. How can that be?
Put the gems in correctly, push the button, and...
Ugh.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 <--- attempt to call method "containedItems" (a nil value) if i.name == item then return true end end -- if we get here the item was not found return false end
As early as that error comes, it seems like it's not even getting into the "real" script.
Nope. I suspect this is an old message... the error messages remain on the console until they are cleared. Did you try clicking the "clr" button in the editor to clear the console? then see if the message re-appears.Redweaver wrote: Also, when testing the dungeon you gave me, I was still getting that "Warning! Unknown spawner entity type: nil" error at the top of the screen.
Did I break my editor somehow?
Awesome. Sorry if I wasn't clear on that part. Actually the problem would not have materialised if you HAD put the functions the other way around, because the connectors automatically pick the first function in the script if you don't change it with the dropdown.Redweaver wrote:Redweaver wrote:I noticed something just now when combing through the code again.
Your wall button is set to hit the "checkAlcoves" script...the "real" part of the script. Mine says it's calling the "containsItem" script...the early part that's throwing the error. It populates itself with that call when I click the "add connector" button. How can I correct that?
That fixed it. I used the dropdown to point it at the correct function. It works now. Thanks, Grim.
Now...what is it that the mouth socket accepts natively?