Simple on-click/touch function not working!

I’m experimenting with Functions, and decided to create one that combines a common condition for interacting with game elements to test:

  • if cursor/touch is on object
  • Left mouse button was released

into one “When object is touched/clicked” condition.

I followed the Wiki tutorial, and all the config/parameters are correct (screenshots below), but it doesn’t work… The last screenshot has the new function condition selected, with the equivalent conditions above it to illustrate (they are removed during test of course).
The equivalent conditions work fine, but the packaged/function version doesn’t.

Am I missing something?

Functions - Config

Functions - Parameters

Event
gd-function-events

I see atleast three errors.

  • You give wrong name of parameter to the condition for cursor. (Why AnyObject? This come from where?)
  • Your function return nothing, then when you use it this do nothing. (Add an action in the function for return true)
  • On your eventsheet i see the custom function, and two other conditions, the two conditions are useless because your custom fonction should be do same thing as the two other conditions.

Thanks Bouh!

You give wrong name of parameter to the condition for cursor. (Why AnyObject? This come from where?)

You can choose Any Object in the function builder (screenshot below), so that you don’t have to restrict yourself to specific object types like Sprite, Text, Panel etc. The player interacts with sprites, text objects and panel sprites, so I put them all in one.

Your function return nothing, then when you use it this do nothing. (Add an action in the function for return true)

So does the function need both a condition and an action in order to work? That wasn’t clear in the Wiki - one example shows just an action on its own, so I assumed you could do the same with a condition (screenshot below)

Object name

  • Any Object is the type of your object used in the function.
  • Parameter #1 2 3 … is the hook/name to use in your function. It’s like an alias to give to your conditions/actions in the function for use the object pass from your eventsheet.

Function return

If you set an function for trigger some condition you need return if the conditions are complete.
If your conditions are success you return true.
If nothing is returned, false is return by default, thats mean your custom condition in eventsheet return false, so the custom condition is false and the action next to it are never tigger.
More info about function return you should read.

There is a warning bubble about it. Maybe we can precise that works differently betweens actions and conditions yeah.

Well, this is embarrassing…

I read all of the documentation you referenced, and somehow missed the “For a condition, you need to set when the condition returns true or false. For this, you can set the condition to true or false using the “Set condition return value” action.”

Totally missed it!

Just set that up as you described, and it works perfectly. Thanks for your help!

3 Likes