how do I get a var from an array and use it to get an object using UID?

0 favourites
  • 9 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I decided that I would see if I'm doing something wrong or I'm just crazy because it seems like this would work to me

    but appearantly it doesn't work. I thought maybe because it was returning a string or an int it didn't work to select the weapon but it seems turning it into an int or a string it's broken either way which is kinda bugging me. all I want to do is grab the random object UID that's selected and find that object so I can use it or move it. is there something I'm doing wrong or is this just a thing where I'm not allowed to do something like this just because?

  • Yeah, weaponUIDI is a string, you need an integer to pick by UID.

    Why are you doing this with scripting anyway? It's so much easier with events - "System pick random instance"

  • well I know I made it a string intentionally. turning it into an integer using parseint() didn't work as well. leaving it alone also doesn't work. I would do pick random instance but I'm trying to use an array to pick the instance using the UID I put inside the array

  • I'm trying to use an array to pick the instance using the UID I put inside the array

    Ok, it's still easy to do with events.

    Sprite pick instance with UID = Array.at(random(Array.width))

  • I don't see how I would do that. if I go to system or the family that the sprites are a part of I don't find anything where I can pick an instance by a UID. also I wanna do it by script because I'm gonna make a function that will make more bullets based on the data inside the array and such when the player shoots

  • You need to check out a few examples and tutorials. In C3 you can create big and complex games 100% with events. Scripting is rarely needed.

    There are 3 different ways you can pick up an instance by UID:

    Sprite/Family: Pick by unique ID

    System: Pick by evaluate

    System: Pick by comparison

    .

    Can you explain the task? You need to spawn a specific type of bullet based on .. what?

  • I want the damage of the bullet, how many bullets there are and everything inside of the array. then I wanna use the UID from the array to grab the object to move it and such

  • I wanna use the UID from the array to grab the object to move it and such

    You really should avoid storing UIDs in the array. UIDs are assigned dynamically and can change if you destroy/create objects in runtime or even in the editor.

    .

    I assume you want to spawn different bullets for different weapons, with different properties. Is this right?

    There are many ways to do this. The easiest would be to use templates: create a template for each bullet type, configure all properties directly on the bullet sprite (speed, animation, damage value etc.) Then spawn the bullet sprite by template name. You won't need any arrays or scripts.

    Here is a demo

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • finally went back, I looked at the demo and this is absolutely amazing, I honestly didn't even think of doing it this way and I tried it out and yeah it does (so far) exactly what I want it to do. tysm man

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