Navigation

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

    Can anyone give me some tips on how to make and store NPCs and objects?

    Beginners
    5
    12
    607
    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.
    • CasualTie5
      CasualTie5 F last edited by

      I can't give you tips, but I know there are various threads in the forum about arrays of structures;
      maybe you just haven't yet tried out everything that's possible with structures?

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

        I would definitely still use structs in arrays. I couldn’t really think of another way of doing it really...

        Just be careful with a few things, like when copying a struct, always copy each element by itself, and not the whole struct. Also, when passing a struct to a function, the struct is “by reference” until you change anything in it, then it becomes a copy.

        I would write code that worked with any number of items in the arrays; so adding a new enemy would just mean adding to the array, and then the game would just incorporate the new enemy automatically.

        The struct would contain every bit of info for the enemy (or item or whatever), like coordinates, how it is facing, health, etc.

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

          “ Also, when passing a struct to a function, the struct is “by reference” until you change anything in it, then it becomes a copy.”

          That’s a brain twister...

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

            That’s how I understand it at least. It’s quite weird.

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

              Who was it who did ‘linked lists’ by attaching extra properties to sprites? I wonder if you can do that with 3d objects...

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

                @toxibunny I think I tried this already once. I bet its not supported with 3D objects.

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

                  I’m going to have to do some sort of write-up when I figure out a good way to do it. I have my cats and dinos in a list, so clearly it’s possible. I should have a massive clean up of my code - it’s more barnacle than boat at the moment. Maybe after I get the cruft out of the way and reorganise, things will become clearer..

                  spikey 1 Reply Last reply Reply Quote 1
                  • spikey
                    spikey F @PickleCatStars last edited by spikey

                    @toxibunny I thought your asking about adding properties to 3D object handles like @pianofire's example for custom properties with sprites.

                    obj = placeObject( cube, { 0, 0, 0 }, { 2, 2, 2 } )
                    obj.customProperty = 1234
                    

                    What i have in mind is not working.

                    1 Reply Last reply Reply Quote 0
                    • D
                      DaddyJDM last edited by

                      No, the 3d objects can't have properties now.

                      What has worked for me is stuffing the 3d object in a struct with other properties I want to associate with it, like
                      '''
                      S = [.obj=placeObject(...),
                      .hp=100,
                      .pos={0,0,0},
                      //etc.
                      ]
                      '''

                      1 Reply Last reply Reply Quote 3
                      • PickleCatStars
                        PickleCatStars F last edited by

                        Yep, that’s what I do. It’s having those structs in an array, and then trying to change those structs using functions that’s causing problems. At the moment, I’m solving it by having my arrays global, and putting all the code that deals with them in my main loop, inside ’if then endif’s .

                        Which seems like kindof a dumb and untidy way to do it, but that’s the level I’m at at the moment, and apparently this way doesn’t affect performance. Nothing worthy of a full writeup, but I will be talking about it in my WIP thread when I get around to it. My game is going well at the moment :)

                        1 Reply Last reply Reply Quote 2
                        • D
                          DaddyJDM last edited by

                          @toxibunny That's great!
                          I actually also do the global array of structs approach. For my functions that manipulate an individual entity/object, I just pass the array index as an argument. Then I manipulate the strict within the global array itself, without needing to worry about copying structs.
                          That works well in my game, too, without me noticing or measuring any real performance penalty.

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