How do I call an action from a behavior?

0 favourites
  • 7 posts
From the Asset Store
Voice call plugin based on webrtc protocol for construct 3
  • I'm trying to write a behavior that will change the character scale of a sprite font. However, I'm having trouble getting it to work. After digging around in the forum, I came up with this:, 0.5);[/code:p5orxfd2]
    That at least doesn't throw any errors, but it also doesn't actually change the scale.
    Does anyone know what I'm doing wrong?
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • OK, in the docs I found this:


    In behavior instances only: this is the reference to the object instance your behavior should modify.

    Which sounds like it would apply to what I'm trying to do. So I amend my code to:, 0.5);[/code:1u90lmv3]
    But that gives me:
    [quote:1u90lmv3]Uncaught TypeError: Cannot read property 'characterScale' of undefined
    Still searching...
  • TrickyWidget

    It is possible to call an action from a behavior. Even call an action/expression/condition from other plugin/behavior.

  • rex is definitely the authority on plugins but to add to what i think your problem is that you are not passing the correct instance of the spritefont object your trying to change to the function you are calling.

    "this.inst" <- I assume that's the instance of your plugin your passing to the function call? But what it needs to be is the sprite font object instance you want to scale.

    You need to somewhere get the instance of the sprite font object usually by adding a condition to pick it. Once picked you store instance of the sprite font into a variable like "this.spriteFontInstance"

    Your function call would then look like this., 0.5);[/code:3hi931cq]
  • Or run the code step by step by adding

    before the call, to see if the action has been called or not.
  • It is possible to call an action from a behavior. Even call an action/expression/condition from other plugin/behavior.

    Thank you for the response! It was actually that very code that I examined from a previous post that lead me to the code I had.

    It seems my problem was that I was trying to affect the instance in behinstProto.onCreate. I have no idea why that doesn't work, but when I move it down into behinstProto.tick it's now behaving as expected.

    Thanks again!

  • I guess that , the this.inst had not been created at behavior's on create function. I had this problem before, too.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)