(WIP) Curious Conundrum / CFD 2012 submission

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: (WIP) Curious Conundrum / CFD 2012 submission

Post by Komag »

Be sure your capitalization is accurate too
Finished Dungeons - complete mods to play
User avatar
Redweaver
Posts: 68
Joined: Tue Dec 04, 2012 1:13 am
Location: Illinois, USA

Re: (WIP) Curious Conundrum / CFD 2012 submission

Post by Redweaver »

Komag wrote:Be sure your capitalization is accurate too
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.

I can follow the logic of the code, and it seems like it's right...so whatever the problem is, it must be something small, simple and easily overlooked.
My finished mods:
A Curious Conundrum http://grimrock.nexusmods.com/mods/135 also on Steam Workshop

Current WIP:
Lair of Unarak http://grimrock.nexusmods.com/mods/137
User avatar
Redweaver
Posts: 68
Joined: Tue Dec 04, 2012 1:13 am
Location: Illinois, USA

Re: (WIP) Curious Conundrum / CFD 2012 submission

Post by Redweaver »

Grimwold wrote:
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?
Yes that's correct.. it's so you can pass it entities from your script.

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.

Hmmmm...since that bit needs to be passed entities from the script, does it maybe need to come at the end?

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.
My finished mods:
A Curious Conundrum http://grimrock.nexusmods.com/mods/135 also on Steam Workshop

Current WIP:
Lair of Unarak http://grimrock.nexusmods.com/mods/137
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: (WIP) Curious Conundrum / CFD 2012 submission

Post by Grimwold »

Redweaver wrote:Hmmmm...since that bit needs to be passed entities from the script, does it maybe need to come at the end?
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.

So, I just pasted your code into my test dungeon (minus the error message) and it worked completely fine (I had to rename one door from prizedoor to orbdoor)... so it does look like it is something in your dungeon that is causing the problem... please check carefully the IDs of the alcoves.. they should be exactly dungeon_alcove_1 etc.

I will post here a sample dungeon with this script so you can test it.

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.
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.
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: (WIP) Curious Conundrum / CFD 2012 submission

Post by Grimwold »

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

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")
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...

It is working perfectly here.
User avatar
Redweaver
Posts: 68
Joined: Tue Dec 04, 2012 1:13 am
Location: Illinois, USA

Re: (WIP) Curious Conundrum / CFD 2012 submission

Post by Redweaver »

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

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")
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...

It is working perfectly here.
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...

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
Ugh.

As early as that error comes, it seems like it's not even getting into the "real" script.

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?
My finished mods:
A Curious Conundrum http://grimrock.nexusmods.com/mods/135 also on Steam Workshop

Current WIP:
Lair of Unarak http://grimrock.nexusmods.com/mods/137
User avatar
Redweaver
Posts: 68
Joined: Tue Dec 04, 2012 1:13 am
Location: Illinois, USA

Re: (WIP) Curious Conundrum / CFD 2012 submission

Post by Redweaver »

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?
My finished mods:
A Curious Conundrum http://grimrock.nexusmods.com/mods/135 also on Steam Workshop

Current WIP:
Lair of Unarak http://grimrock.nexusmods.com/mods/137
User avatar
Redweaver
Posts: 68
Joined: Tue Dec 04, 2012 1:13 am
Location: Illinois, USA

Re: (WIP) Curious Conundrum / CFD 2012 submission

Post by Redweaver »

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?
My finished mods:
A Curious Conundrum http://grimrock.nexusmods.com/mods/135 also on Steam Workshop

Current WIP:
Lair of Unarak http://grimrock.nexusmods.com/mods/137
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: (WIP) Curious Conundrum / CFD 2012 submission

Post by Grimwold »

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...

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
Ugh.

As early as that error comes, it seems like it's not even getting into the "real" script.
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.

When the button is pressed it goes straight to the point where we declare function checkAlcoves() and starts there.... it goes through that until it reaches containsItem(dungeon_alcove_5,"green_gem"), then it jumps to the other function, which is called containsItem() and it processes all of that function with the values dungeon_alcove_5 and "green_gem", then drops back to the bottom function, where it calls containsItem() again, but this time with values dungeon_alcove_4 and "red_gem". It keeps doing this swapping back and forth every time the command containsItem() is written in the main function... so as it is, we can't actually tell at what point the error is cropping up...

I will see if I can modify the script a little to build in some error checking.. that way we can see what is missing from your dungeon.
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?
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.
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: (WIP) Curious Conundrum / CFD 2012 submission

Post by Grimwold »

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?
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.


Oh and the basic mouth socket seems to only accept a green gem (by trial and error)
Post Reply