Daemon eye socket problem.

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
zeltak
Posts: 119
Joined: Fri May 04, 2012 2:33 am

Daemon eye socket problem.

Post by zeltak » Sat Sep 15, 2012 2:39 am

I thought I understood the following script, but it seems I didn't and now I need some explaining and help.

Code: Select all

cloneObject{
          name = "red_eye_right",
          baseObject = "eye_socket_right",

          onInsertItem = function(red_gem)
          return true
	  end,
    }
So I thought that with this the right eye socket (the new eye_socket_right) would accept red gems. Well, it does, but in addition 'eye_socket_right' accepts all other gems. So what did I understood wrong here? What I'm trying to do is, if player puts red gem into a socket it would blast the player and green gem would open a door. I thought that I could just use connectors to do those things with the new named sockets.

User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Daemon eye socket problem.

Post by petri » Sat Sep 15, 2012 7:14 am

The function should return false when the socket wants to reject an item. Now it returns true for any item.

Aazlan
Posts: 13
Joined: Thu Sep 13, 2012 6:59 pm

Re: Daemon eye socket problem.

Post by Aazlan » Sat Sep 15, 2012 1:35 pm

petri wrote:The function should return false when the socket wants to reject an item. Now it returns true for any item.
Ok, so how do we adjust the arguments so that it will accept a specific gem (return true) and reject the others (return false) with the onInsertItem function?
I can't get that to happen as either a hook or an in game script entity.

As far as excepting multiple types of gems and doing different things, try this zeltak:
objects.lua hook

Code: Select all

cloneObject{
		name = "multi_eye_right",
		baseObject = "eye_socket_right",
		onInsertItem = function()
		 print("Gem inserted right.")
		 return true
		end,

}

cloneObject{
		name = "multi_eye_left",
		baseObject = "eye_socket_left",
		onInsertItem = function()
		 print("Gem inserted left.")
		 return true
		end,

}
In game script entity:

Code: Select all

function checkEyes()

for i in multi_eye_left_1:containedItems() do
	if i.name == "green_gem" then
	 print("L Green Gem")
	 leftGreenGem = "true"
	 leftRedGem = "false"
	 leftBlueGem = "false"
	 greenGems()
	end
end

for i in multi_eye_right_1:containedItems() do
	if i.name == "green_gem" then
	 print("R Green Gem")
	 rightGreenGem = "true"
	 rightRedGem = "false"
	 rightBlueGem = "false"
	 greenGems()
	end
end

for i in multi_eye_left_1:containedItems() do
	if i.name == "red_gem" then
	 print("L Red Gem")
	 leftGreenGem = "false"
	 leftRedGem = "true"
	 leftBlueGem = "false"
	 redGems()
	end
end

for i in multi_eye_right_1:containedItems() do
	if i.name == "red_gem" then
	 print("R Red Gem")
	 rightGreenGem = "false"
	 rightRedGem = "true"
	 rightBlueGem = "false"
	 redGems()
	end
end

for i in multi_eye_left_1:containedItems() do
	if i.name == "blue_gem" then
	 print("L Blue Gem")
	 leftGreenGem = "false"
	 leftRedGem = "false"
	 leftBlueGem = "true"
	 blueGems()
	end
end

for i in multi_eye_right_1:containedItems() do
	if i.name == "blue_gem" then
	 print("R Blue Gem")
	 rightGreenGem = "false"
	 rightRedGem = "false"
	 rightBlueGem = "true"
	 blueGems()
	end
end

end

function greenGems()
	if rightGreenGem == "true" and leftGreenGem == "true" then
	 playSound("level_up")
	 myDoor:open()
	else
	 myDoor:close()	
	end
end

function redGems()
	if rightRedGem == "true" or leftRedGem == "true" then
	 spawn("fireburst", party.level, party.x, party.y, 0)
	end
end

function blueGems()
	if rightBlueGem == "true" or leftBlueGem == "true" then
	 spawn("frostburst", party.level, party.x, party.y, 0)
	end
end
	
The only issue with this, is that you can take the green gem out and stick it in the other socket to get the door to open, in this particular example. What I really need is some code that locks the gems in place once they are the correct ones, and some code that keeps you from being able to stick multiple gems in the sockets. I've tried various things with "socket":onInsertItem and party:onPickUpItem but I'm stumped again. Think you guys should really consider adding multi-gem and other than blue gem selection abilities to the eye and mouth sockets, please!

edit: sorry, noticed my code still had a bunch of extraneous code where I was trying to figure out other stuff

User avatar
zeltak
Posts: 119
Joined: Fri May 04, 2012 2:33 am

Re: Daemon eye socket problem.

Post by zeltak » Sun Sep 16, 2012 4:34 am

Thank you! This works very well as a placeholder until we figure out a better way to handle the sockets and gems.

velojun
Posts: 19
Joined: Sat Sep 15, 2012 9:02 am

Re: Daemon eye socket problem.

Post by velojun » Sun Sep 16, 2012 12:58 pm

petri wrote:The function should return false when the socket wants to reject an item. Now it returns true for any item.
how then to program the objects file???? :?:

what i've got so far is something like this:


cloneObject{
name = "red_mouth_socket",
baseObject = "mouth_socket",

onInsertItem = function (red_mouth_socket, red_gem)
hudPrint("Red Gem inserted mouth.")
return true
end,

}

cloneObject{
name = "blue_mouth_socket",
baseObject = "mouth_socket",

onInsertItem = function (blue_mouth_socket, blue_gem)
hudPrint("Blue Gem inserted mouth.")
return true
end,


unfortunately when i use the blue_mouth_socket in the same place as the red_mouth_socket, placing a red gem returns the hudPrint: " Blue Gem Inserted"

velojun
Posts: 19
Joined: Sat Sep 15, 2012 9:02 am

Re: Daemon eye socket problem.

Post by velojun » Sun Sep 16, 2012 1:05 pm

---i tried adding this to the red_mouth__socket:
onInsertItem = function (red_mouth_socket, green_gem)
hudPrint("Green Gem inserted mouth.")
return false
end,
onInsertItem = function (red_mouth_socket, blue_gem)
hudPrint("Blue Gem inserted mouth.")
return false
end,

----and this to the blue_mouth_socket:
onInsertItem = function (blue_mouth_socket, green_gem)
hudPrint("Green Gem inserted mouth.")
return false
end,
onInsertItem = function (blue_mouth_socket, red_gem)
hudPrint("Blue Gem inserted mouth.")
return false
end,


and it does reject the gems, but then i cant even insert a red gem(using both the blue_mouth _socket AND red_mouth_socket)

User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Daemon eye socket problem.

Post by petri » Sun Sep 16, 2012 4:17 pm

Eye and mouth sockets function just like alcoves (in fact they're alcoves with no 3d model and custom anchor position for the inserted item). Like alcoves, onInsertItem receives the inserted item as a parameter. The idea is to check that parameter and either return true or false depending whether you want to accept or reject the item. Also you probably don't want to allow multiple gems to be inserted into the socket so onInsertItem should return false if there is an item already inserted.

For example, the following function returns true only if the item to be inserted is a blue_gem and the socket is empty:

Code: Select all

	onInsertItem = function(self, item)
		return item.name == "blue_gem" and self:getItemCount() == 0
	end

Aazlan
Posts: 13
Joined: Thu Sep 13, 2012 6:59 pm

Re: Daemon eye socket problem.

Post by Aazlan » Sun Sep 16, 2012 5:24 pm

Gah! Figures, I was close at one point, I tried using the return command to get the string from the arguments, but I must have been screwing up the syntax somewhere. LUA seems to have a lot of similarities to Pascal and C, but it's different enough that it's been throwing me for loops. Thank you Petri!

velojun
Posts: 19
Joined: Sat Sep 15, 2012 9:02 am

Re: Daemon eye socket problem.

Post by velojun » Mon Sep 17, 2012 6:42 am

thanks petri! :D i now have Multi colour daemonheadsockets!!!!!!

Post Reply