Help with listing

How do I make a little system like say I have five texts like text(100,100,100,100) and I make a command like

function test:draw()

Texts:draw()

I’m trying to make my Codea project draw all my texts next to each other. I’m hoping I’m explaining this well I’m not very good at it. If anyone knows how please tell me :slight_smile:

Thank you

Are you after something like this, if not let me know and I’ll show something else.

EDIT: Changed code.

function setup()
    txt={"line1","line2","line3","line4","line5"}
end

function draw()
    background(40, 40, 50)
    drawText(200,400,20)    
end

function drawText(startX,startY,inc)
    fill(255)
    for z=1,#txt do
        text(txt[z],startX,startY-inc*z)
    end
end

@dave1707 not really. My project is a Mac simulator. It’s not really suppose to act like a real make but I just like coding stuff like that. I’m trying to make finder list all the default applications next to each other without me adding the X and Y to it.

@AveryD Changed the above code. Is that closer.

@dave1707 not what I’m looking for I’ll just send you my code

OK

@dave1707 I got a error in my code and I been trying to fix it. Can you help


-- SynOSX
    
-- Created By: AveryDee

-- Coded By: AveryDee

function setup()
    displayMode(FULLSCREEN)
    func=desktop
    -- Plugins
    
    pos = vec2(10,300)
    size = vec2(202,342)
    
    -- Default Applacations
    da1=dmg(WIDTH/2,HEIGHT-200,100,50,"Finder")
    da2=dmg(WIDTH/2,HEIGHT-400,100,50,"TextEdit")
    da3=dmg(WIDTH/2,HEIGHT-600,100,50,"SynStore")
    -- Downloaded Applacations
    
    
    -- Exit Buttons
    xb1=X(WIDTH/2,HEIGHT-200,100,50,"Desktop")
    xb2=X(WIDTH/2,HEIGHT-300,100,50,"Desktop")
    xb3=X(WIDTH/2,HEIGHT-400,100,50,"Desktop")
end

function draw()
    background(40, 40, 50)
    func()
end

function touched(t)
    Finder:touched(t)
    if t.state==BEGAN then
        if func==desktop and da1:touched(t)=="Finder" then
            func=easy
        elseif func==desktop and da2:touched(t)=="TextEdit" then
            func=normal
        elseif func==desktop and da3:touched(t)=="SynStore" then
            func=hard
        elseif func==easy and xb1:touched(t)=="Desktop" then
            func=desktop
        elseif func==normal and xb1:touched(t)=="Desktop" then
            fund=desktop
        elseif func==hard and xb1:touched(t)=="Desktop" then
            func=desktop
        end 
    end  
end

function desktop()
    background(167, 125, 96, 255)
    da1:draw()
    da2:draw()
    da3:draw()
end

function Finder()
    background()
    
    Finder:draw()

end

function TextEdit()
    background(0,0,255)
    fill(255)
    text("NORMAL Screen",WIDTH/2,HEIGHT/2)
    nb1:draw()
end

function SynStore()
    background(0,0,255)
    fill(255)
    text("HARD Screen",WIDTH/2,HEIGHT/2)
    hb1:draw()
end

-- Default Applacations

Finder = class()

function Finder:draw()
    background()
    spriteMode(CORNER)
    sprite("Documents:Finder",pos.x,pos.y,650)
end

function Finder:touched(t)
    tpos = vec2(t.x,t.y)
    if tpos.x>=pos.x and tpos.x<=pos.x+size.x and tpos.y>=pos.y and tpos.y<=pos.y+size.y then
        if t.state == BEGAN then 
            anchor = tpos - pos
        end
    end
    
    if anchor then pos = tpos - anchor end  
    if t.state == ENDED then anchor = nil end
end

-- .dmg

dmg = class()

function dmg:init(x,y,w,h,txt)
    self.x=x
    self.y=y
    self.w=w
    self.h=h
    self.txt=txt
end

function dmg:draw()
    rectMode(CENTER)
    fill(255)
    rect(self.x,self.y,self.w,self.h)
    fill(255,0,0)
    text(self.txt,self.x,self.y)
end

function dmg:touched(t)
    if t.state==BEGAN then
        if t.x>self.x-self.w/2 and t.x<self.x+self.w/2 and
            t.y>self.y-self.h/2 and t.y<self.y+self.h/2 then
                return self.txt
        end
    end
end

-- Exit

X = class()

function X:init(x,y,w,h,txt)
    self.x=x
    self.y=y
    self.w=w
    self.h=h
    self.txt=txt
end

function X:draw()
    rectMode(CENTER)
    fill(255)
    rect(self.x,self.y,self.w,self.h)
    fill(255,0,0)
    text(self.txt,self.x,self.y)
end

function X:touched(t)
    if t.state==BEGAN then
        if t.x>self.x-self.w/2 and t.x<self.x+self.w/2 and
            t.y>self.y-self.h/2 and t.y<self.y+self.h/2 then
                return self.txt
        end
    end
end

Oops hang on


-- SynOSX
    
-- Created By: AveryDee

-- Coded By: AveryDee

function setup()
    displayMode(FULLSCREEN)
    func=desktop
    -- Plugins
    
    pos = vec2(10,300)
    size = vec2(202,342)
    
    -- Default Applacations
    da1=dmg(WIDTH/2,HEIGHT-200,100,50,"Finder")
    da2=dmg(WIDTH/2,HEIGHT-400,100,50,"TextEdit")
    da3=dmg(WIDTH/2,HEIGHT-600,100,50,"SynStore")
    -- Downloaded Applacations
    
    
    -- Exit Buttons
    xb1=X(WIDTH/2,HEIGHT-200,100,50,"Desktop")
    xb2=X(WIDTH/2,HEIGHT-300,100,50,"Desktop")
    xb3=X(WIDTH/2,HEIGHT-400,100,50,"Desktop")
end

function draw()
    background(40, 40, 50)
    func()
end

function touched(t)
    Finder:touched(t)
    if t.state==BEGAN then
        if func==desktop and da1:touched(t)=="Finder" then
            func=easy
        elseif func==desktop and da2:touched(t)=="TextEdit" then
            func=normal
        elseif func==desktop and da3:touched(t)=="SynStore" then
            func=hard
        elseif func==easy and xb1:touched(t)=="Desktop" then
            func=desktop
        elseif func==normal and xb1:touched(t)=="Desktop" then
            fund=desktop
        elseif func==hard and xb1:touched(t)=="Desktop" then
            func=desktop
        end 
    end  
end

function desktop()
    background(167, 125, 96, 255)
    da1:draw()
    da2:draw()
    da3:draw()
end

function Finder()
    background()
    
    Finder:draw()

end

function TextEdit()
    background(0,0,255)
    fill(255)
    text("NORMAL Screen",WIDTH/2,HEIGHT/2)
    nb1:draw()
end

function SynStore()
    background(0,0,255)
    fill(255)
    text("HARD Screen",WIDTH/2,HEIGHT/2)
    hb1:draw()
end

-- Default Applacations

Finder = class()

function Finder:draw()
    background()
    spriteMode(CORNER)
    sprite("Documents:Finder",pos.x,pos.y,650)
end

function Finder:touched(t)
    tpos = vec2(t.x,t.y)
    if tpos.x>=pos.x and tpos.x<=pos.x+size.x and tpos.y>=pos.y and tpos.y<=pos.y+size.y then
        if t.state == BEGAN then 
            anchor = tpos - pos
        end
    end
    
    if anchor then pos = tpos - anchor end  
    if t.state == ENDED then anchor = nil end
end

-- .dmg

dmg = class()

function dmg:init(x,y,w,h,txt)
    self.x=x
    self.y=y
    self.w=w
    self.h=h
    self.txt=txt
end

function dmg:draw()
    rectMode(CENTER)
    fill(255)
    rect(self.x,self.y,self.w,self.h)
    fill(255,0,0)
    text(self.txt,self.x,self.y)
end

function dmg:touched(t)
    if t.state==BEGAN then
        if t.x>self.x-self.w/2 and t.x<self.x+self.w/2 and
            t.y>self.y-self.h/2 and t.y<self.y+self.h/2 then
                return self.txt
        end
    end
end

-- Exit

X = class()

function X:init(x,y,w,h,txt)
    self.x=x
    self.y=y
    self.w=w
    self.h=h
    self.txt=txt
end

function X:draw()
    rectMode(CENTER)
    fill(255)
    rect(self.x,self.y,self.w,self.h)
    fill(255,0,0)
    text(self.txt,self.x,self.y)
end

function X:touched(t)
    if t.state==BEGAN then
        if t.x>self.x-self.w/2 and t.x<self.x+self.w/2 and
            t.y>self.y-self.h/2 and t.y<self.y+self.h/2 then
                return self.txt
        end
    end
end

@AveryD What are you doing with easy, normal, hard. Did you pull this code from another program and not change things. Since func() is calling a function, then anything you set func equal to needs to exist as a function.

@AveryD my friend sent me the code. And thanks I will try that

@dave1707 I fixed the problem

Can u make codea free on the appstore

@Maison If you’re asking if I can, the answer is NO.

@Maison code is worth the money. You can create games with Codea then sale it on the App Store. Seems cheap

@Masison codea*