How to make so that each copy of the object is independent of each other?

0 favourites
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • I can not solve the puzzle. Who faced this condition.

    There is an "object 1" it has the behavior of "field of view", when the "object 2" enters the field of view of object 1, then object 1 produces a text message. So far so good.

    The problem arises at that moment that there can be many copies of objects 1.

    As it should be: when object 2 gets into the field of view of object 1, then only the given object 1’s text should come out and not all its copies.

    The number of objects 1 is not known in advance and can be any number.

    Now I have 2 situations: Either only one first object 1 produces text when object 2 falls within the visibility range of any copy of object 1, or all objects 1 produce text at a time if object 2 approaches any object 1.

    How to make so that each copy of the object is independent of each other?

  • Hiya, I don't really understand the logic there as it is just a small section but be careful using functions after picking instance because when you run the function it does not relate to this instance and can pick a different one. You can pass through the UID of the object 1 through the function, and then on function call you can say for object 1 where UID = param 0.

  • i don't know if this is having any sense to you but what i see in the image is this

    you call function with name"t2" but you have creation of sprites on function with name"t1" ... maybe is something we are missing?

    What "t2" is supposed to do? and why is "t1" function there? how is "t1" called? and again, as i mentioned to another function related question, having a wait 4 seconds in the trigger once function call doesn't work like that, you have to replace the wait 4 seconds with a timer being it a global number or the timer plugin.

    atleast that is how i solved that wait "n" seconds issue... mainly cause functions calls and anything else happen on a tick bassis, adding a seconds based delay inside a trigger once tick condition makes the function not trigger properly....

    creature_spawn here is the wait "n" seconds workaround inside a function call.

    hope it helps.

  • i don't know if this is having any sense to you but what i see in the image is this

    you call function with name"t2" but you have creation of sprites on function with name"t1" ... maybe is something we are missing?

    What "t2" is supposed to do? and why is "t1" function there? how is "t1" called? and again, as i mentioned to another function related question, having a wait 4 seconds in the trigger once function call doesn't work like that, you have to replace the wait 4 seconds with a timer being it a global number or the timer plugin.

    atleast that is how i solved that wait "n" seconds issue... mainly cause functions calls and anything else happen on a tick bassis, adding a seconds based delay inside a trigger once tick condition makes the function not trigger properly....

    creature_spawn here is the wait "n" seconds workaround inside a function call.

    hope it helps.

    Many thanks for the example.

    There are no problems with functions, since I built them in to simplify the work.

    The point is not in functions, but in the fact that when a copy of an object is created, it applies all the parameters to itself. And I do not understand how to make a copy work separately.

    We have:

    Player

    Object 1

    Object 1 (copy)

    Imagine that we first have a Player then after 10 meters Object 1 and after 20 meters Object 1 (copy)

    When the Player approaches Object 1, then (for example) object 1 must create a new object (for example, object 2) on itself.

    And here dances begin with a tambourine, since the object object 2 is created immediately and on object 1 and on object 1 (copy).

    I put the function to randomly select a copy of the object, but this led to the fact that as soon as the Player touches object 1, then object 2 can be created arbitrarily.

    And it is necessary that object 2 is created each time on the copy of object 1 to which the Player interacts.

    ---

    I will try to more fully explain the problem.

    Imagine that the player has 5 sheets of white paper. (all these papers are copies), further, when interacting with one of the 5 sheets of paper, that is, with one of the copies, this copy creates the text on itself. That is, only that copy of the paper with which the player interacts creates text on itself. If the player in turn will interact with all 5 sheets of paper, then each of them in turn will create a different text.

  • Hiya, I don't really understand the logic there as it is just a small section but be careful using functions after picking instance because when you run the function it does not relate to this instance and can pick a different one. You can pass through the UID of the object 1 through the function, and then on function call you can say for object 1 where UID = param 0.

    Yes, that's right, as long as this is my only solution so that not all copies of object 1 create a new object on themselves.

    Also, I can not use UID since I do not know how many copies to create, they can be any number

  • Imagine that we first have a Player then after 10 meters Object 1 and after 20 meters Object 1 (copy)

    When the Player approaches Object 1, then (for example) object 1 must create a new object (for example, object 2) on itself.

    And here dances begin with a tambourine, since the object object 2 is created immediately and on object 1 and on object 1 (copy).

    i see you have a collision/overlap issue, so what happens is when the player hits object1, object 1 clones himself as a new instance in the same position, position at which the player is already overlaping the object therefore triggering the collision again, and spawns again another object and so on.

    try push the player outside the object1 when collision happens even if it's 0.01 pixels outside to it so is not noticed to the player, that should fix your issue.

    also make sure you destroy object1 that initializes the new cloned object in the same event action that makes the new object. on the same tick.

    here is some pseudo-code

    player.oncollision with object1

    object1 spawn object1 on self.

    player.setX to self.x-0.01

    now the above is applying for a sidescrooler type of movement assuming the player moves left and right only. and assuming the player stops the movement at the very first contact with the object1.

    otherwise you could add a timer on the object created to enable collision so it's not happening that fast.

    think of it like this

    if object1 hits player.

    object1 destroy

    object1 spawn object1 on self

    set object1 collisions disabled.

    set timer to activate to 2 seconds

    if timer countdown is ready

    object1 set collision enabled.

    that should give you the basic idea on how things could work with a delay, so you have time to read the text.

    or you could save the position and area of object1 on initial collision then save the position and for the new object say if player is in same area as before don't do nothing.

    once the player is outside the area activate object and then the loop of collision can happen again.

    hope it makes sense.

    if you could share a c3p file would help us understand better your setup.

  • > Imagine that we first have a Player then after 10 meters Object 1 and after 20 meters Object 1 (copy)

    >

    > When the Player approaches Object 1, then (for example) object 1 must create a new object (for example, object 2) on itself.

    >

    > And here dances begin with a tambourine, since the object object 2 is created immediately and on object 1 and on object 1 (copy).

    i see you have a collision/overlap issue, so what happens is when the player hits object1, object 1 clones himself as a new instance in the same position, position at which the player is already overlaping the object therefore triggering the collision again, and spawns again another object and so on.

    try push the player outside the object1 when collision happens even if it's 0.01 pixels outside to it so is not noticed to the player, that should fix your issue.

    also make sure you destroy object1 that initializes the new cloned object in the same event action that makes the new object. on the same tick.

    No no. I can hardly see the problem, sorry for my English))) Here is a picture

  • in that case you need to destroy object when collision is happening, or disable collisions once the player collides with it, without any wait 4 seconds or anything in between.

    please see my above reply i edited and added a few example pseudo-codes.

  • >

    in that case you need to destroy object when collision is happening, or disable collisions once the player collides with it.

    please see my above reply i edited and added a few example pseudo-codes.

    Yes, but I cannot destroy it, that is, I need this object to be, for example, as "NPS" only in my case, these are 5 identical "NPS" and not different.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • >

    in that case you need to destroy object when collision is happening, or disable collisions once the player collides with it.

    please see my above reply i edited and added a few example pseudo-codes.

    Thank you, now I will try your example)

  • if you have a stationary npc, that needs to be in screen u can also make a boolean and say

    player on collision with object1

    if object1 boolean is false

    do action

    set boolean to true.

    that would make the object1 stop looping the creation.

    the boolean can be either a instance boolean, or a number that u set to 0 or 1 or a text variable

  • if you have a stationary npc, that needs to be in screen u can also make a boolean and say

    player on collision with object1

    if object1 boolean is false

    do action

    set boolean to true.

    that would make the object1 stop looping the creation.

    the boolean can be either a instance boolean, or a number that u set to 0 or 1 or a text variable

    I have 5 copies of the object on the screen at once, they interact with the player using the "field of view" behavior and as soon as any nearest copy notices the player, that is, the player enters the interaction zone, all 5 copies immediately begin performing the action.

  • Here's my example of the objects acting independently with LOS, check it out see if it helps. dropbox.com/sh/be0cumtbjy9bx9h/AAB2HSgzGL9ciuxfYj3PWpNxa

  • Here's my example of the objects acting independently with LOS, check it out see if it helps. dropbox.com/sh/be0cumtbjy9bx9h/AAB2HSgzGL9ciuxfYj3PWpNxa

    Yes! Thank you so much! You saved me! I spent 2 days on this simple code)))) This is exactly what is needed)

    ---

    But I have some kind of mistake when I built it at my place. It works always only in the first copy.

  • Your functions look a little redundant as the only difference is the creation of a different text object. You can just use one function like in my example and send another parameter through it with the text to set in a single text object. Your functions are also sub events of a global variable condition, not sure what this is for but checking a global variable at the time of line of sight so 2 things must be true can be risky.

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