Not being able to cancel a "click" is very annoying

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
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Not being able to cancel a "click" is very annoying

Post by MrChoke »

I am faced with the same problem I had when trying to get chests to unlock with keys and not lock picks. The major problem is how the Clickable component works. If an object has one and its enabled, there is a built-in behavior that executes after the onClick() function fires AND YOU CANNOT STOP IT. Well, we did make it cancel itself for the chest to get key unlocks to work. We faked-it-out basically by removing the held object so that when the built-in code executed it didn't do anything because the object was gone. I was amazed it worked to be honest.

So my current situation has no work around that I can find. I have a pull chain defined for a door (castle_door_button). I can add my own onClick() hook for the button but there is nothing I can do to stop it from calling open() on the door. Even in the door's onOpen() I cannot seem to stop that event either. Sure I can disable the clickable component but I want conditional logic so that I can decide whether I want the click to go through or not.

In any event-driven language like Java for example, you can cancel an event to stop it from bubbling. Now I know this is a game not a full-blown language but still, this functionality is sorely lacking.
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: Not being able to cancel a "click" is very annoying

Post by GoldenShadowGS »

Why don't you make a pullchain that is separate from the door?

Try this:

Code: Select all

defineObject{
	name = "castle_customdoor_button",
	baseObject = "wall_button",
	components = {
		{
			class = "Model",
			model = "assets/models/env/castle_wall_button.fbx",
			offset = vec(1.5, 1.5, -0.23),
		},
		--{
		--	class = "Animation",
		--	animations = {
		--		press = "assets/animations/env/beach_rock_wall_button_01_press.fbx",
		--	},
		--},
		{
			class = "Particle",
			particleSystem = "castle_button",
			offset = vec(1.5, 1.5, -0.23),
		},
		{
			class = "Light",
			offset = vec(1.5, 1.5, -0.23),
			range = 4,
			color = vec(0.5, 1.0, 2.5),
			brightness = 4,
			fillLight = true,
		},
		{
			class = "Clickable",
			offset = vec(1.5, 1.5, -0.23),
			size = vec(0.25, 0.25, 0.25),
			--debugDraw = true,
		},
		{
			class = "Button",
			sound = "castle_button",
		},
	},
	replacesWall = false,
}
Last edited by GoldenShadowGS on Wed Dec 24, 2014 7:17 pm, edited 1 time in total.
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: Not being able to cancel a "click" is very annoying

Post by Batty »

It's not the Clickable class, the

Code: Select all

{
   class = "PullChain"
},
is allowing the click to go through so do not do

Code: Select all

baseObject = "door_pullchain",
in your definition because you're inheriting it. Make something like this and you can control the click:

Code: Select all

defineObject{
   name = "new_pullchain",
	components = {
	   {
			class = "Model",
			model = "assets/models/env/door_pullchain.fbx"
		},
		{
			class = "Animation",
			animations = {
				press = "assets/animations/env/door_pullchain.fbx"
			}
		},
		{
			class = "Clickable",
			offset = vec(1.3, 1.3,-0.4),
			size = vec(0.3, 0.6, 0.3),
			onClick = function(self)
				if (your test) then 
				   self.go.animation:play("press")
               (do other things also)
				   return true
            else				
			      return false
				end
			end
			--debugDraw = true,			
		}
	},
	placement = "wall",
	editorIcon = 12
}
Last edited by Batty on Thu Dec 25, 2014 2:52 am, edited 1 time in total.
GoldenShadowGS
Posts: 168
Joined: Thu Oct 30, 2014 1:56 am

Re: Not being able to cancel a "click" is very annoying

Post by GoldenShadowGS »

I had the same idea, I copied the castle wall button definition and put the castle door pull chain buttons offsets onto it.
MrChoke
Posts: 324
Joined: Sat Oct 25, 2014 7:20 pm

Re: Not being able to cancel a "click" is very annoying

Post by MrChoke »

Thanks Batty. Yes, I came back to the thread to update as SOLVED with the same answer. I found that I can enable or disable the pullchain component on the button and it works without having to remove the pullchain off the door (a solution that also worked but stunk).

My complaint does still remain in that we cannot cancel the click. But much like the keyLock chest, we can get the hard-coded event handler to not do anything if we find the right thing to modify. I fear one of these times we won't find something. But who knows.
Post Reply