Mummy puzzle problem

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
The cube
Posts: 94
Joined: Tue Apr 23, 2013 6:09 pm
Location: Barren Desert

Mummy puzzle problem

Post by The cube »

I accidently posted to legend of grimrock 1 side of the forum :roll:

the puzzle:

You stand beetween two rows of mummies in forcefields. The other one has buttons underneath, the other one doesn't. You must get the mummies in the row with buttons to be in the same order as the mummies in the row with buttons. This is done by pressing two different buttonns, which changes the position of the two respective mummies.

Code: Select all

function switchPlaces(button)

   if selected1 == 0 then
      selected1 = button.go.x
      print("first one selected!")
      print(selected1)
   else
      selected2 = button.go.x
      print("second one selected!")
      print(selected2)
   end
   
   if selected1 ~= selected2 and selected2 ~= 0 then   
      print("Progressing!")
      for e in party.map:entitiesAt(selected1,7) do
         for i in party.map:entitiesAt(selected2,7) do
            if checkIfIsMummy(i) and checkIfIsMummy(e) then
		i:setPosition(party.map, selected1, e.y, 2, 0)
		e:setPosition(party.map, selected2, e.y, 2, 0)
            end
         end
      end      
   elseif selected1 == selected2 then
      selected2=0
      print("corrected you fool!")
   end
end
But there is an error! it is: "could not look up class name".

The function works well all the way until it prints out "progressing".

Also, you may notice i am destoying and then spawning entities. If there is a way to move entities around i'd gladly use it!

Here's the rest of the code:

Code: Select all

selected1=0
selected2=0

function checksides()
   
   local matches = 0
   
   for x = 14,17 do
      for e in party.map:entitiesAt(x,7) do   
         for i in party.map:entitiesAt(x,13) do   
            if checkIfIsMummy(i) and checkIfIsMummy(e) then
               print(e.name)
               print(i.name)
               print("")
                 if e.name == i.name then
                  matches = matches + 1   
               end
            end
            end
        end
   end
   
   if matches == 4 then
      puzzledoor_1.controller:open()
   end
end
   
function checkIfIsMummy(entity)
   local mummyList = {"mummy","mummy1","mummy2","mummy3"}
   for _, value in pairs(mummyList) do
       if value == entity.name then
          return true
       end
     end
     return false
end
Last edited by The cube on Sun Apr 19, 2015 8:12 pm, edited 1 time in total.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: Mummy puzzle problem

Post by minmay »

entities can be moved with GameObject:setPosition()
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
The cube
Posts: 94
Joined: Tue Apr 23, 2013 6:09 pm
Location: Barren Desert

Re: Mummy puzzle problem

Post by The cube »

Oh yeah. that is much better.

The problem seems to be at these lines:

Code: Select all

     for e in party.map:entitiesAt(selected1,7) do
         for i in party.map:entitiesAt(selected2,7) do
            if checkIfIsMummy(i) and checkIfIsMummy(e) then
Post Reply