Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Helghast on December 22, 2012, 05:19:52 PM

Title: UIButtonMessage + Javascript = not receiving call?
Post by: Helghast on December 22, 2012, 05:19:52 PM
Hey Guys,

I'm implementing NGUI into this project (which was done in Javascript), and want to put some custom code to button presses.
If I use UIButtonMessage, and the following javascript pieve:

  1. public function setSpeedSlow(go:GameObject) { Debug.Log("test"); }

the Debug Log never shows up, I have no idea why my script is never executed, as I have checked i setup the right target object and script name, anyone has any clue on this one?

kind regards,
Title: Re: UIButtonMessage + Javascript = not receiving call?
Post by: ArenMook on December 23, 2012, 06:52:51 AM
It should work fine, assuming you set "setSpeedSlow" on your button message. I generally don't recommend using that script though. It's best to use UIEventListener (as it's faster), or better yet -- create your OnClick / OnPress etc handlers right on the button object by adding a custom script.
Title: Re: UIButtonMessage + Javascript = not receiving call?
Post by: Helghast on December 23, 2012, 08:41:00 AM
I tried doing that, but am not even getting the chance of running that...

I have this to setup the delegate listeners (in Javascript):

  1. // Delegate stuff for NGUI
  2. public var buttonSpeedSlow : GameObject;
  3.  
  4. function setSpeedSlow(go : GameObject) { Debug.Log("works!"); }
  5.  
  6. function Start() {
  7.         UIEventListener.Get(buttonSpeedSlow).onClick += setSpeedSlow;
  8. }
  9.  
  10. function OnDestroy() {
  11.         UIEventListener.Get(buttonSpeedSlow).onClick -= setSpeedSlow;
  12. }
  13. // ---

But then I'm faced with the following error:

  1. Assets/Scripts/UI/inputButtonProcess.js(73,54): BCE0051: Operator '+' cannot be used with a left hand side of type 'function(UnityEngine.GameObject): void' and a right hand side of type 'function(UnityEngine.GameObject): void'.
  2.  
(and the same for the - operator)

Any idea?

regards,
Title: Re: UIButtonMessage + Javascript = not receiving call?
Post by: ArenMook on December 23, 2012, 06:29:57 PM
Try equals instead of +=.
Title: Re: UIButtonMessage + Javascript = not receiving call?
Post by: Helghast on December 23, 2012, 06:39:14 PM
out of curiosity and understanding, what makes == so different then +=/-= ?
I'll try when I'm back on my pc and will let you know if it worked!

thanks!
Title: Re: UIButtonMessage + Javascript = not receiving call?
Post by: ArenMook on December 24, 2012, 07:53:57 AM
I meant a single "=", not "==". :P

You would be assigning, not appending.
Title: Re: UIButtonMessage + Javascript = not receiving call?
Post by: Helghast on December 24, 2012, 08:04:19 AM
got it all running now!

Thanks a bunch, really happy with my purchase :D