objects as functions parameter

0 favourites
  • 8 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • Hello,

    is any way to use objects or families within function parameters?

    the idea is to create a function that sets up the angle of motion and speed attack with different families objects as enemies (aliens, planes, dragons, etc...).

    I know i can create the object inside the function body, but that limits the function to the specific object or family i created within. Of course, one way is to create the objects outside the function and use the function to only set up the attack movement values.

    Just wondering :)

  • I'm not sure exactly what you mean, but I'm quite sue it can be done ;)

    Normally you would do something like:

    On enemy destroyed: call function "enemyDestroyed" with the first parameter as the enemy.UID.

    Then in the function, pick enemy by UID and you can do whatever you like from there. Hope it helps! Feel free to ask if you have trouble.

  • Hello Tobey,

    Thanks for such a quick answer :). I was thinking more on being able to use the create object event with a function parameter. Something like this:

    Let's say we have 2 families of sprite objects. FlyDragons and GroundDragons, and we want to use a function to create every 3 seconds an enemy of any of those families in the screen.

    Every 3 seconds: call function "newEnemy"(family, screen.X, screen.Y)

    :)Perhaps (just come to my mind) the approach is using a random variable value for the first parameter and in the body of the function create the object depending on that value.

  • The question is really unclear.

    If you want the function to work on a specific instance it should be picked.

    If the object is created within the function it can be referenced by using subevents.

    If after the creation you want to do things to each object in the family, you can add a for each.

    Point is, you want to sent the family or object as a parameter. To do this you'd have to know which object or family to use as parameter, right? So actually you have to do the picking before being able to set as parameter. Which is outside of the function, which makes your question questionable.

    You could just choose to send a global variable as a parameter and within the function have a subevent that says if global variable is ... perform these actions. these actions could be family or object specific, ofcourse.

  • Just saw your reply. I would probably go for the easy approach.

    You could use choose(1,2)

    and create family 1 if choose is 1

    and create family 2 if choose is 2

  • Thanks LittleStain. Definetively going with the variable method :)

  • You could discard the global variable actually:

    call function"enemycreate"(choose(1,2),screen.x,screen.y)

    on function"enemycreate"

    -compare two values : param(0)=1 - family1 actions

    -compare two values : param(0)=2 - family2 actions

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks again. Now i need more enemies! :)

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