How do I pass a variable value?

0 favourites
  • 12 posts
From the Asset Store
Color Variable
$4.50 USD
10% off
Easily store, modify, read and manipulate colors with Color Variables!
  • Hi Everyone,

    Need some help please.

    I have 2 (OBJ_one and OBJ_two) objects that each have a variable (my_variable). When the objects collide, I would like to have the variable value in OBJ_one be passed to OBJ_two and then OBJ_two be destroyed.

    What is happening is when they collide is OBJ_two is destroyed, but the variable value is not passed.

    I have the event set at 'on collision', which is working fine. And the action set to ObJ_one add OBJ_two.my_variable to my_variable. But it doesn't seem to be passing the variable value.

    Any and all help is appreciated.

  • Why do you pass a variable to an object that be destroyed?

    It will gone with your object.

    Store it in another variable instead.

  • The passing of the value likely happens on the next tick of execution. The tick where the instance is destroyed anyway.

    Further explain what exactly you are trying to achieve, the problem to which passing a value to a destroyed object is the solution you decided to implement.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry, I wrote this just before I went to bed so it probably reads like a dr Seuss book.

    My game has a cannon-like object that will shoot 1 canister with say 5 items in it. When the canister hits a target, I want to destroy the canister but transfer the count of 5 items to the target it hit. But the number of items can vary for each canister. So I can’t just say when they collide just add 5. It has to add the variable amount in the canister.

    Hope that makes more sense.

  • Well then post your .c3p file for us to be able to investigate what might be going wrong.

  • In your add to variable action use canister."var_items" (replace with your variable name) as the amount. This will take the value from the variable of the canister that has collided with the target and add it to the target's variable.

  • Here is a link to my game file.

    Based on the example above, I've got that piece of code correct. So I'm stumped.

    drive.google.com/file/d/1bgMxUrq7jMeJIuyARx9AZeRU1XuhMFt8/view

  • Your file shows it working correctly. The variable from the gloop object is being passed to the gloop turner object and then reset to 0.

    Is that not what you wanted to achieve?

  • Not exactly.

    After doing some more testing, it is passing he variable to another object of the same type. Not the one that it is colliding with.

    Any idea why that would be?

  • It is clearly passing the variable to the object that it is colliding with.

  • I disagree.

    If you press 1 while in the game you can put down another turner and the original turner will be firing even though it isn't getting hit.

    I recall having this same issue with previous attempts to use construct, it doesn't easily differentiate objects from each other like visual engines do.

  • Your events are telling it to do that.

    You are saying:

    For Every Turner every two seconds, spawn gloop object.

    Every X seconds is a global condition and not individual to each object instance, and "For Each" is specifying that you want those actions to be applied to every instance.

    In your events there is no dependency on the turner being hit for it to continue firing.

    It's difficult to understand what you are trying to do because you haven't explained it clearly. Your initial question was about the passing of a variable on collision. This is working.

    If you want to understand how to do something else create a new topic or explain it clearly.

    construct.net/en/make-games/manuals/construct-3/project-primitives/events/how-events-work

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