0 Favourites

How do I pick objects by instant variable for set behavior

  • Hi. I have objects with different instant variable values for different features. But when I need set a behavior for a object with a instant variable, the behavior set actions for all instances!

    How can I tweak or do a better thing than it?

    Thanks in advance

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Well, you should be able to pick objects by variable value with no problem, something like,

    Object Variable = 0 --> do X

    Object Variable = 1 --> do Y

    Only objects whose variable equals 0 will do X and those with 1 will do Y, so I'm not sure I understand the problem correctly?

  • Well, you should be able to pick objects by variable value with no problem, something like,

    Object Variable = 0 --> do X

    Object Variable = 1 --> do Y

    Only objects whose variable equals 0 will do X and those with 1 will do Y, so I'm not sure I understand the problem correctly?

    I use text in variables instead of numbers.

    This is my sheet:

    The drag and drop behavior isn't working for all instances. I don't know what is the conflict.

  • I tried recreating something similar but it seems to be working correctly. What does the event which sets the Type variable look like? Most likely something in that condition is setting Type for all instances instead of just one.

  • Good idea, but I've tried in a separate-new project, with two instances with different variables, but the behaviors continue working for all instances.

  • Ashley, I think here its a problem with behaviors.

  • Hmm, strange. Can you upload the .capx for one of these projects so I can have a look?

  • Of the main project I can't, but I will send of the separated project.

  • You need a "For each" loop in your conditions, otherwise if just one object meets the conditions, it will apply to all object instances (because you haven't told it to check each one individually).

    [For each sprite.object]

    [sprite.variable=XYZ]

    --- Do stuff

    [ELSE]

    --- Do nothing

    ~Sol

  • SoldjahBoy

    You need a "For each" loop in your conditions, otherwise if just one object meets the conditions, it will apply to all object instances (because you haven't told it to check each one individually).

    [For each sprite.object]

    [sprite.variable=XYZ]

    --- Do stuff

    [ELSE]

    --- Do nothing

    ~Sol

    It isn't working. I tried using car behavior instead of dragndrop, and continues conflicting.

  • When I tried to recreate this I didn't need a For Each loop, each instance would enable/disable its behavior based on its individual variable. Most likely some other event is interfering and setting all of the objects variable to the same thing.

    In my experiment all I did was have 3 different objects, A, X, Y, where A had drag and drop behavior and X and Y had sine behavior to make them move.

    If A collides with X -> Set variable to "no"

    If A collides with Y -> Set variable to "yes"

    If variable = "no" -> Disabled drag and drop

    If variable = "yes" -> Enable drag and drop

    This worked as expected with multiple instances of A, so the issue seems to be someplace else.

  • When I tried to recreate this I didn't need a For Each loop, each instance would enable/disable its behavior based on its individual variable. Most likely some other event is interfering and setting all of the objects variable to the same thing.

    In my experiment all I did was have 3 different objects, A, X, Y, where A had drag and drop behavior and X and Y had sine behavior to make them move.

    If A collides with X -> Set variable to "no"

    If A collides with Y -> Set variable to "yes"

    If variable = "no" -> Disabled drag and drop

    If variable = "yes" -> Enable drag and drop

    This worked as expected with multiple instances of A, so the issue seems to be someplace else.

    Please attach the .capx file.

  • I didn't save it since I was just doodling lol

    Should be really simple to recreate since it was literally those four conditions and three objects. I can try to redo it tomorrow.

  • Here it isn't work, please send a .capx.

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
0 Favourites
[BEHAVIOR] Chipmunk Physics
673 82,535
nelostic's avatar
nelostic
Unread hot topic
0 Favourites
[Behavior] LiteTween
672 169,941
manujorgo's avatar
manujorgo
Unread hot topic
564 105,252
rexrainbow's avatar
rexrainbow