How do I pass variable into instances?

0 favourites
  • 4 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • How can I transfer the values of a variable between one instance and another instance of the same object?

    example:

    Ant (1) finds food in position var foodx and foody that are instance variables.

    Ant (1) collides with Ant (5) and passes the location of the food.

    the ant (5) stops doing what it is doing and goes to the food: foodx and foody

  • How can I transfer the values of a variable between one instance and another instance of the same object?

    example:

    Ant (1) finds food in position var foodx and foody that are instance variables.

    Ant (1) collides with Ant (5) and passes the location of the food.

    the ant (5) stops doing what it is doing and goes to the food: foodx and foody

    well if you want to use the same sprite, you have to have a family, so you can differentiate between instances and a few variables.

    however if u plan on having ants animating and stuff i suggest keep each ant "class" different.

    for a scout have a scout sprite for a gatherer have a gatherer sprite and so on, it will make ur life easier.

    that being said... using the family approach and keeping the 1 sprite for all ants...

    here is a example ants-example.c3p

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • > How can I transfer the values of a variable between one instance and another instance of the same object?

    >

    > example:

    >

    > Ant (1) finds food in position var foodx and foody that are instance variables.

    > Ant (1) collides with Ant (5) and passes the location of the food.

    > the ant (5) stops doing what it is doing and goes to the food: foodx and foody

    well if you want to use the same sprite, you have to have a family, so you can differentiate between instances and a few variables.

    however if u plan on having ants animating and stuff i suggest keep each ant "class" different.

    for a scout have a scout sprite for a gatherer have a gatherer sprite and so on, it will make ur life easier.

    that being said... using the family approach and keeping the 1 sprite for all ants...

    here is a example ants-example.c3p

    Thanks but i found an better solution:

    I use a local variable to save the id of the instance that has "FOOD" and then look inside the collision for the one that does not have it, after verifying that the variable is not -1 or that there is one with "FOOD" and another one "NO FOOD" since under that rule the info will be passed, it does not work for 2 with "FOOD" or 2 "NO FOOD", and then it is only to pass the variable of the instance with "FOOD" according to its IDVAR to which " WITHOUT FOOD ".

    SIMPLE.

    I WAIT FOR YOU, I WAS CRANEING THE SOLUTION. FOR THE USE OF FAMILIES IS THE SAME.

  • EXAMPLE GAME:https://i.imgur.com/bkR86iB.gif

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