How do I create object from UID?

0 favourites
  • 3 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • I have been experimenting with various possibilities for keeping track of objects that a user collects throughout the game. In response to my original question, Plinky suggested two approaches: global variables for relatively simple scenarios and arrays for more complicated collection scenarios.

    I understand how to solve this with global variables, but I'm struggling with implementation using arrays. As you can see from the attached file, I am using two arrays. arrayInventory is a sort of 'map' of the inventory slots on the final page. It includes a slot number and the x/y coordinates where sprites should be placed when displayed in the inventory. Meanwhile, arrayCollection is an empty array that I am using to store the UID of collected sprites.

    Everything goes swimmingly until I reach the final stage of my game. Using the debugger, I can see that my collection array has been populated with the correct UID, but I cannot figure out how to spawn an object based on this UID information. Is there anything I can do with the UID at this stage?

    I realize that it might be illogical to spawn an object with UID since it references a *unique* identifying number for the sprite. But it seems that I should be able to reposition the sprite with the UID if it hasn't actually been destroyed.

    (As a side note, I can imagine another approach that keeps track of things by using sprites that have multiple frames and named animations, but I want to figure out the UID thing first.)

    I hope I'm posting this before everyone goes to bed across the pond. :) The file is posted at:

    transmedia.trinity.edu/~adelwich/temp/array-inventory-by-uid.c3p

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • A UID doesn't work. As soon as you leave the layout, the objects are destroyed, so the UID has no meaning. The simplest solution really is separate frames of an animation. Then you just store the frame number, and at the end, create the object and set the frame.

  • Thanks, blackHornet. Back to the (virtual) drawing board! :)

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