How do I transfer values for variables across objects?

0 favourites
  • 11 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I have an object for the player's currently held weapon and for a weapon on the ground. When the player swaps weapons all of the stats in the currently held weapon get transferred into a temporary variable (e.g: Set tempAccuracy to weapon.accuracy). All of the temporary variables are local static variables. After this the currently held weapon gets the stats from the weapon on ground and weapon on the ground gets the original stats from the held weapon.

    Here is a picture of this part of the event sheet (zoomed out as far as I could while making it legible):

    However, when the weapons are swapped the stats do not carry over correctly:

    Before the swap

    After the swap

    Does anyone know how I can make this work? (and possibly more efficiently than an event that is dozens of actions long)

  • You are not picking the currently held weapon in the condition, you need to do this to set those values to the temporary variable. Then when you use weapon.id etc it will relate to the currently held weapon. Also make sure it's a trigger once event on a key press or similar and not running constantly.

  • You are not picking the currently held weapon in the condition, you need to do this to set those values to the temporary variable. Then when you use weapon.id etc it will relate to the currently held weapon. Also make sure it's a trigger once event on a key press or similar and not running constantly.

    There's only one weapon object in the game at any time and it already only occurs upon swapping weapons so I don't think it is to do with not picking the right weapon.

  • The bit about it triggering once is also important or you're going to see constantly swapping variables. What does the start of the event look like ?

  • The bit about it triggering once is also important or you're going to see constantly swapping variables. What does the start of the event look like ?

    This is the start of the function.

  • There is only one weapondrop instance in the game? Are you sure? Looks like weapon is being assigned default values from a weapondrop instance instead of one you have selected and then the others update as expected, weapon stats to variable and then variable to weapondrop.

  • There is only one weapondrop instance in the game? Are you sure? Looks like weapon is being assigned default values from a weapondrop instance instead of one you have selected and then the others update as expected, weapon stats to variable and then variable to weapondrop.

    There are multiple weaponDrop instances but there is only one weapon instance. Would I have to specify what weaponDrop instance I am referring to in order to stop it from updating to the default values?

  • Yep in the condition you need to pick the instances. Weapon held but if there is only one weapon then fair enough and also the weapondrop object. So I guess you would use player is overlapping weapondrop or something similar.

  • Yep in the condition you need to pick the instances. Weapon held but if there is only one weapon then fair enough and also the weapondrop object. So I guess you would use player is overlapping weapondrop or something similar.

    EDIT: I added a parameter to the function where it would take the UID of the weaponDrop the player swaps with and used 'Pick by UID' in the swap and now it works properly! Thanks a lot!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yep sounds good :)

  • It might be easier to put an equipped = false on all equipment. Then as you wear them you set it to true and swap them out set back to false.

    This way you can always go back and find all equipped gear by searching that 1 instance variable on all items.

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