Need help with tables and objects. [Solved]

Hello, I’m a new, totally inexperienced programmer, came across Codea a few months ago. But for the lack of tutorials, I couldn’t learn much yet. Of course I found @Ignatz books, they are really helpful. But I still have some problems. Like this…

I just made a project, where I need to get the list of assets in my “Documents” assets pack. I have a parameter that would get the asset pack name, add the current indexed asset name and pass the two values to a variable. The variable would then pass the total name (ex-“Asset pack:Asset key”) as a key to the sprite command in draw. The sprite command would then draw the image at the centre of the screen. This is the code

-- Tables

-- Use this function to perform your initial setup
function setup()
    Assetchange=assetList("Documents",SPRITES)
        for i,v in pairs(Assetchange) do
        print(i,v)
            parameter.integer("Assets",1,#Assetchange,1)
        Image="Documents:"..v      
   end
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here

sprite(Image,WIDTH/2,HEIGHT/2)

text(Assets,WIDTH/2,HEIGHT/2)
fill(255, 23, 0, 255)
end

But when I run the code, I find only the last asset is drawn, and I can’t choose the asset through the parameter slider. Please help me.

Here’s a working version. you were setting up a parameter slider for every single sprite, and had no callback to change the sprite once the slider has been set.

-- Sprite Asset Browser

function setup()
    Assetchange=assetList("Documents",SPRITES)
    parameter.integer("Asset",1,#Assetchange,1, function() Image="Documents:"..Assetchange[Asset] end)
    for i,v in pairs(Assetchange) do
        print(i,v)       
    end
end

function draw()
    background(40, 40, 50)
    
    sprite(Image,WIDTH/2,HEIGHT/2)
    
    text(Asset,WIDTH/2,HEIGHT/2)
    fill(255, 23, 0, 255)
end

Thanks a lot!! Nice to get the help. It’s working perfectly now. And the help was truly quick. And that also shortened the code! Thanks again. The thing is much clear now!