Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    Can A Sprite be an Array?

    Beginners
    3
    6
    385
    Loading More Posts
    • 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.
    • M
      Mechanical last edited by

      Weird question but I try to explain myself.

      I want to code a garden simulation with space for up to 50 entities.

      I made a Sprite animation of a dandelion in different states of growth.

      So far so good I got into some trouble with handling Sprite handles.

      I made an Array called Entities[50] wich contains an entity struct with Intel like status, species, and coords.

      And I made an Array called Sprites[50] that's associated with the entity slots.

      For I = 1 to 50 loop
      Sprites[I] = Createsprite()

      Repeat

      When I try to setspriteimage(Sprites[Freeslot] ) In an algorithm that looks for a free slot and saves the index number of the first free slot it finds in a global variable called Freeslot.

      The Interpreter says that Sprites[Freeslot] is not a Sprite. And here I am confused. Because there should be a whole Array of Sprites.

      1 Reply Last reply Reply Quote 0
      • pianofire
        pianofire Fuze Team last edited by

        You certainly can store a sprite handle in an array so that should work. Are you sure that FreeSlot is set to a value in the range 1 to 50?

        1 Reply Last reply Reply Quote 2
        • M
          Mechanical last edited by

          The search algorithm works as follows:

          For I = 1 to 50 loop

          If Entities[I]. Status = 0 then saveslot() break endif

          Repeat

          Like this the index number of the free slot should be stored in the Freeslot variable.

          Saveslot() does just that. But maybe I should do a Freeslot == I instead.

          That aside I don't get why I can't refer to that Array as a Sprite handle

          1 Reply Last reply Reply Quote 0
          • spikey
            spikey F last edited by

            Did you store something in Entities[0]? Because the array index starts at 0.
            And the for loop parameters will be 0 to 50. And it will return you values with the indexes 0 to 49.

            M 1 Reply Last reply Reply Quote 2
            • M
              Mechanical @spikey last edited by

              @spikey that could actually be it. Thanks for the reminder I will try that out later and tell you the results.

              1 Reply Last reply Reply Quote 1
              • M
                Mechanical last edited by

                It seems that this was indeed the problem.
                Array indexes start at 0. If I skip the 0 slot I can't Acess it as a Sprite.

                I fixed the numbers and it worked as intended.

                1 Reply Last reply Reply Quote 6
                • First post
                  Last post