How to sum my instance variable ?

0 favourites
  • 5 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello ! I have one sprite with multiple animation, and every animation is a different object.

    Depending on the animation, my sprite don't have the same instance variable named Score (it can go from 1 to 5).

    I want to sum up all the instance variable of the sprite I can see on screen. Is that possible ?

    For now I have an global variable named "Animation 1", "Animation 2", "Animation 3" etc...

    with "Animation n" set to "Sprite.pickedcount*n"

    And a global variable named "Total" set to "Animation 1 + animation 2 etc..."

    But it seems very tideous and spaghetti. Is there an easier way ? Thank you for your help !

  • for each sprite, add to global variable 'sprite.var', with a trigger once so it doesn't keep adding.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • "I want to sum up all the instance variable of the sprite I can see on screen" i screwed up, I meant : I want to sum up all the instance variable of the sprite overlaping another sprite.

    Let's call the first sprite with the different animation Ball and the other sprite Ground

    When Ball is playing animation 1 = instance variable = 1

    When Ball is playing animation 2 = instance variable = 2

    Every tick, I want to know the sum of the instance variable of the Ball overlaping Ground, but I can move the Ball and not overlap them with Ground as I wish.

    So like, if there is 2 Balls playing animation 1 and 2 playing animation 2, and the four are on the Ground, the score is 6 but then I get one animation 1 out of the Ground the score gets to 5

    So it has to be constantly counting. (plus you can add or destroy balls whenever you want)

    I hope that's more clear, thank you for answering !

  • I might do it with another instance variable on the ball so you know when it is or isn't overlapping the ground by offset. Then you can say if a ball overlaps the ground and variable isn't set, set it and add ball.amount to global. Then in the opposite way if a ball is not overlapping the ground but the variable is set, that means it was overlapping but is now moving away, you subtract ball.amount from global.

  • Omg that works ! Thank you so much !!

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