Is there a way target an object using a function parameter?

0 favourites
  • 3 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hi everyone. This is my first post here, and I'm having trouble figuring out how to do something. I only started with Construct 2 about a week ago, and from what I've search of the forums, I can't find an easy solution to my problem.

    So I'm making a JRPG style game, with many unique characters each with their own stats, and other variables. I have all of these characters in a single family called NPCs. I want to create a function that has a parameter which is used to reference a specific character, and get the value of an instance variable from them. Is there a way to do this? My first thought was to simply use the parameter in the expression like so: functionA(0).BulletDistanceTravelled but that didn't work. Is there a reason for this? Can anyone offer me a solution?

    Thank you for any help you offer.

  • When you call the function you can pass the uid of an object as a parameter. Then in the function you can pick the sprite by uid.

    Start of layout

    Pick random sprite instance

    —- function: call “foo” (sprite.uid)

    On function “foo”

    Sprite: pick by uid function.param(0)

    —- do something with sprite

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you. I was banging my head at this for hours. Turns out there was also an issue in my game logic.

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