0 Replies - 267 Views - Last Post: 03 January 2008 - 07:28 PM

#1 RodgerB   User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • Posts: 2,284
  • Joined: 21-September 07

[LUA]Lua: Initialize an array

Posted 03 January 2008 - 07:28 PM

Description: 1) Copy and paste the snippet into the lua file you are using. 2) Read the comments.Easy way to initialize a Lua array. Expands the array to fit the element count, and sets their value to zero, like most languages do.
-- Create an instance of a variable for initialization.
anArray = initializeArray ( 256 )

-- The function we will be using to initialize the array.
function initializeArray ( elementCount )
    -- Create a temporary array that we will be returning.
    local tempArray = {}

    -- Loop through the count of elements needed
    -- and give the element a value of zero.
    for i=1, elementCount do
        tempArray[i] = 0
    end

    -- Return the temporary array.
    return tempArray
end


Is This A Good Question/Topic? 0
  • +

Page 1 of 1