problem variable

0 favourites
  • 7 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • hi,

    how to add a variable of several same instance .. all store in a global variable.

    Thx

    Ex: A IId: 0 Variable "truc" : 3

    A IId: 1 Variable "truc" : 4

    A IId: 2 Variable "truc" : 14

    Ect ...

  • That's what instance variables are for.

  • I have trouble explaining myself ...

    I have an object: A, with variable of instance "truc" which changes according to certain condition ...

    I have several object A and I wish to add them in a global variable.

    But the problem I have for now is that either it runs in a loop or does not add up ..

  • You need to add up values from all instances?

    Set GlobalVar to 0
    System For each SpriteA -> Add (SpriteA.truk) to GlobalVar
    
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You need to add up values from all instances?

    > Set GlobalVar to 0
    System For each SpriteA -> Add (SpriteA.truk) to GlobalVar
    

    Hi

    i try but is more complicate

    Hi,

    I already try but it's not enough ..

    I will detail my problem lol ..

    basically the global variable "wood product" is a resource counter that depends on several building "Woodstock" which they have a variable instance "wood" so

    The variable changes with specific conditions (selects the number of objects on another object "Zone" to count the whole ")

  • For each "Woodstock" -->add wood to wood prouct

    Problem is looping so I try it

    For each "Woodstock"

    trigger once -->add wood to wood prouct

    Only count it once

    after I try to take directly The instance that allows to count the variable "Wood" that is to say "trunk"

    et j'ai essayer ceci

    but even his kidding,

  • You are doing the loop on every tick, this is wrong. Also, "Trigger once" doesn't work like this, it's also wrong.

    If you just want to count the number of instances, use Count and PickedCount expressions. For example:

    Product compare instance variable type="wool"
     -> Text set text "Total products: " & Product.Count & " wool: " & Product.PickedCount
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)