0 Favourites

How do I Grab the sum of instance varibles from two instance

  • Lets say you have a player object, and you use the UID to separate them within scripts. I am trying to create a co-op system where they have their own score but have x score to each which multiplies each stage. I want to grab the sum of each instances score. How would I do that.


    Instance one score = 25

    instance two score = 50

    so I want to do a test of

    if player.UID(1).score + player.UID(2).score > goal

    Goal being a global variable, set prior. But I don't know how too do that, as it doesn't accept that in expression fields.

    The reason for this being there is a co-op & vs mode I am trying to make, & trying to create shared scripts for different game modes.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • You can just make a variable called "Combined_ score".

    Set Combined_score = 0
    For each Player
           Combined_score = Combined_score + Player.score
    If Combined_score > Goal
  • global var scored

    function scorecounter


    pick instance by unique ID = function.param(0)


    set scored to instance.score


    pick instance by unique ID = function.param(1)


    add instance.score to scored





    scored > 50


    go nutts

  • The idea is there, just wrong implantation. With that for a test value in that case you would want to use a local var not global as it pertains only to that script. Trying to optimize my scripts as much as I possibly can, working on a massive game.

    A expression refference method would be more beneficial & what I'm trying to ask for as it would mean any independent but mathmatically connected value between two instances of the same object type would need a new value created just for the connection, just to be constantly called, never mind if I want to constantly call the function.

    If it is impossible with c2 then, yeah I will have to do it basically the same.

  • hmm

    if a score takes place, have it update a separate var, in a unique instance or global.

    For instance a sprite named player1 with a instance var called score. Or a global var dedicated to the player 1's score.

    Same goes for player 2 and others

    Then, use


    system, compare 2 values

    (player1.score + player2.score+player3.score)



    do something

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic Locked topic
198 18,650
Tom's avatar
Tom Construct Team Founder
Unread hot topic
99 10,124
karshinkoff's avatar
Unread hot topic
98 7,590
norum82's avatar