How do I set a unique ID that is consistent in future game plays?

0 favourites
  • 4 posts
From the Asset Store
This Student Workbook uses both Construct 3 & 2 encoding. It supplies client-side & php "back-end" encoding.
  • I want my game to have a number of 'treasures' on each level. When the player finds them they get to keep them, even if they die before finishing the level. However, once a treasure is found, it should no longer appear on the level in future level replays.

    My plan is to give each treasure object an instance variable called treasureID with a value unique to that treasure, and have a CSV string key in my saveGameDictionary called "treasuresFound". When a treasure is found, I'll add its treasureID to treasuresFound. On start of layout, I'll delete any treasure objects whose treasureID is in treasuresFound.

    One sticking point is creating the treasureID value. I don't want to manually create them in the Layout editor when placing the treasure objects, because this will be very tedious and time consuming as I will have hundreds of treasures. It will also be prone to error - how will I be sure I didn't accidentally use the same treasureID twice across different layouts? So instead, I want a way to automatically set treasureID values that will be consistent with future plays of the game/levels.

    Any idea on how to do that? I don't think using the treasure UID is an option, since I believe that can change from one game play to the next.

    Thanks

  • I don't think using the treasure UID is an option, since I believe that can change from one game play to the next.

    If you are creating treasures dynamically during gameplay, then UIDs will be inconsistent. But if you create and keep all treasures in the editor - the UIDs won't change.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Why don't just enumerate them across layout using Index ID (IID)? You can set instance variable to store the enumeration.

    An example:

    + System: Trigger once

    + System: For each box order by box.IID ascending

    -> box: Set box_id to LoopIndex

  • Create a variable called IDGenerator. Whenever uou have an event that assigns a value to an instances treasureID variable use the IDGenerator value and then add 1 to IDGenerator. Store the IDGenerator value in local storage or use whatever method suits your game and then load that value back in at the start of each game session.

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