Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
hyperPad

hyperPad Forum

  1. Home
  2. Help and Support
  3. Is there a way to get the length of an array?

Is there a way to get the length of an array?

Scheduled Pinned Locked Moved Help and Support
11 Posts 2 Posters 930 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Deeeds
    wrote on last edited by
    #1

    Imagine I don't know how many items are in an array, or anything else about its content... is there a way to find the length of the array?

    Jack de WildeJ 1 Reply Last reply
    0
    • D Deeeds

      Imagine I don't know how many items are in an array, or anything else about its content... is there a way to find the length of the array?

      Jack de WildeJ Offline
      Jack de WildeJ Offline
      Jack de Wilde
      wrote on last edited by
      #2

      @Deeeds get array length is under logic rather than custom, confused me at first too.

      D 1 Reply Last reply
      0
      • Jack de WildeJ Jack de Wilde

        @Deeeds get array length is under logic rather than custom, confused me at first too.

        D Offline
        D Offline
        Deeeds
        wrote on last edited by
        #3

        @Jack8680 Brilliant. First part solved.

        I'm wanting to spawn a bunch of objects and then place them according to the positional information held in two arrays:

        ArrayX, ArrayY

        How do I do something like this in this syntactical FARKING nightmare?

        Can I have a reference to each one afterwards? Or them have a unique ID that I can somehow know when something hits them?

        D 1 Reply Last reply
        0
        • D Deeeds

          @Jack8680 Brilliant. First part solved.

          I'm wanting to spawn a bunch of objects and then place them according to the positional information held in two arrays:

          ArrayX, ArrayY

          How do I do something like this in this syntactical FARKING nightmare?

          Can I have a reference to each one afterwards? Or them have a unique ID that I can somehow know when something hits them?

          D Offline
          D Offline
          Deeeds
          wrote on last edited by
          #4

          @Jack8680 The first problem: How do I spawn an object and then have a reference to it so I can change its position?

          It seems spawned objects head into the nether.

          Jack de WildeJ 1 Reply Last reply
          0
          • D Deeeds

            @Jack8680 The first problem: How do I spawn an object and then have a reference to it so I can change its position?

            It seems spawned objects head into the nether.

            Jack de WildeJ Offline
            Jack de WildeJ Offline
            Jack de Wilde
            wrote on last edited by
            #5

            @Deeeds to spawn them at a position, use 'spawn on area' with the area being the the x and y position for the lower and upper bounds.

            To give them an ID, I'd have a main non-spawned object with an idCounter attribute set to 0, then every time an object spawns it gets this value, sets this to its ID, then increments the idCounter variable by 1. They will run in the order they spawn, so you could refer to for example the 8th spawned object by broadcasting a message involving the ID 7, which is the same as the index of the array. and then having the spawned object receive a message based on its ID and run whatever you want it to do.

            D 1 Reply Last reply
            0
            • Jack de WildeJ Jack de Wilde

              @Deeeds to spawn them at a position, use 'spawn on area' with the area being the the x and y position for the lower and upper bounds.

              To give them an ID, I'd have a main non-spawned object with an idCounter attribute set to 0, then every time an object spawns it gets this value, sets this to its ID, then increments the idCounter variable by 1. They will run in the order they spawn, so you could refer to for example the 8th spawned object by broadcasting a message involving the ID 7, which is the same as the index of the array. and then having the spawned object receive a message based on its ID and run whatever you want it to do.

              D Offline
              D Offline
              Deeeds
              wrote on last edited by
              #6

              @Jack8680 I need the objects to know who they are. To say "hey, I'm soo and soo... and this just happened to me..."

              Jack de WildeJ 1 Reply Last reply
              0
              • D Deeeds

                @Jack8680 I need the objects to know who they are. To say "hey, I'm soo and soo... and this just happened to me..."

                Jack de WildeJ Offline
                Jack de WildeJ Offline
                Jack de Wilde
                wrote on last edited by
                #7

                @Deeeds do you want a main object to send a message to a spawned object or you want the spawned objects to send a message to a main object? If it's the latter, it's pretty hard because receive message is limited to once per tick.

                D 1 Reply Last reply
                0
                • Jack de WildeJ Jack de Wilde

                  @Deeeds do you want a main object to send a message to a spawned object or you want the spawned objects to send a message to a main object? If it's the latter, it's pretty hard because receive message is limited to once per tick.

                  D Offline
                  D Offline
                  Deeeds
                  wrote on last edited by
                  #8

                  @Jack8680 When something collides with the spawned objects, I want them to let a central (bonus calculator) know about it, and I want the spawned object to say "It was me!" with an ID that's unique and can be referenced.

                  Jack de WildeJ 1 Reply Last reply
                  0
                  • D Deeeds

                    @Jack8680 When something collides with the spawned objects, I want them to let a central (bonus calculator) know about it, and I want the spawned object to say "It was me!" with an ID that's unique and can be referenced.

                    Jack de WildeJ Offline
                    Jack de WildeJ Offline
                    Jack de Wilde
                    wrote on last edited by
                    #9

                    @Deeeds have a main object with an attribute like 'idCount', and when objects spawn they use the current state of the main idCount attribute as their own ID and increments the idCount. This way each object's ID is the order in which it spawned.

                    Also in the spawned object put a collided behaviour to detect the collision. Then broadcast with a key of "bonus" and use the ID of the object as the value.

                    In your bonus calculator receive with key "bonus" and the value is the ID it can now use.

                    D 1 Reply Last reply
                    0
                    • Jack de WildeJ Jack de Wilde

                      @Deeeds have a main object with an attribute like 'idCount', and when objects spawn they use the current state of the main idCount attribute as their own ID and increments the idCount. This way each object's ID is the order in which it spawned.

                      Also in the spawned object put a collided behaviour to detect the collision. Then broadcast with a key of "bonus" and use the ID of the object as the value.

                      In your bonus calculator receive with key "bonus" and the value is the ID it can now use.

                      D Offline
                      D Offline
                      Deeeds
                      wrote on last edited by
                      #10

                      @Jack8680 I followed this through, as much as I could, and was thinking this way too....

                      but how do I use that ID in the object as a value? It's referencing the original prototype's ID, not "self's" ID.

                      Jack de WildeJ 1 Reply Last reply
                      0
                      • D Deeeds

                        @Jack8680 I followed this through, as much as I could, and was thinking this way too....

                        but how do I use that ID in the object as a value? It's referencing the original prototype's ID, not "self's" ID.

                        Jack de WildeJ Offline
                        Jack de WildeJ Offline
                        Jack de Wilde
                        wrote on last edited by
                        #11

                        @Deeeds
                        idCount = 0
                        First object spawns
                        First object sets its ID to idCount (ID=0)
                        First object increments idCount to 1
                        Second object spawns
                        Second object sets its ID to idCount (ID=1)
                        Second object increments idCount to 2
                        Etc.

                        1 Reply Last reply
                        0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Search