Navigation

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

    Append to Arrays

    Help
    6
    12
    504
    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.
    • J
      Jack_Blue last edited by

      Hi!

      Is there any way to append items to an array while the game is running (i.e. with a command, rather than typing a new item into it yourself)?

      An example of what I mean, where 'append' means 'add onto the end of the array' (this is just a guess at how it could be done):

       nums = []
       boop = 0
      
       loop
      
            if boop < 6 then
                 nums append boop
            else
                 boop = 0
            endif
      
            boop += 1
      
       repeat
      vinicity R 2 Replies Last reply Reply Quote 0
      • vinicity
        vinicity F @Jack_Blue last edited by

        @Jack_Blue

        Instead of “nums append boop”, try

        nums[len(nums)] = boop 
        
        1 Reply Last reply Reply Quote 1
        • R
          Richard F @Jack_Blue last edited by

          @Jack_Blue
          Something like:
          nums[len(nums)] = boop

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

            Great minds, etc.

            1 Reply Last reply Reply Quote 1
            • J
              Jack_Blue last edited by

              Thanks, both!

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

                Just a few notes:

                As far as I know you can add a value to an existing array only if you add it in the next available index. So if you have an array of length 3, you can only add with a[3] = newVal. Doing a[10] = newVal would not work.

                It is also not possible to expand an array by inserting a value at a specific index in the array. You would have to write a looping function for this yourself If you need it.

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

                  I think it does work to extend the array however the unassigned values are void which is one way to get the "Unrecognised type: 4" error message. So if you do a[10] = newVal when the array length was 3, a[3] to a[9] will exist but have undefined values.

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

                    Ah, OK. I only know that its been giving me grief in the past, so I have made a habit of only extending it one index at the time.

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

                      @vinicity Probably safest!

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

                        Looks like it’s time to write an append function then!

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

                          Just to be clear, btw, I’m not going to do it.

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

                            @toxibunny yeah please i also really need one

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