Help for new game I'm making

Well here is the tab

Wood = class()

function Wood:init(x)
    -- you can accept and set parameters here
    self.x = x
    self.size = 50
    self.spawn = {}
    spawn = vec2(0,math.random(HEIGHT))
    table.insert(self.spawn,spawn)
    for i,v in ipairs(self.spawn) do

function Wood:draw()
 v.x = v.x + 5
    line(v.x,v.y,v.x,0)

      
    end 
    end
end
function Wood:touched(touch)
    -- Codea does not automatically call this method
end

Main is

-- construction dodge

-- Use this function to perform your initial setup
function setup()
    Wood()
    end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)
Wood:draw()
    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    
end


How would I make the line repeat once the other line disapears from the screen

Maybe something more like this?

-- main

function setup()
    wood = Wood(50)
end

function draw()
    background(40, 40, 50)
    strokeWidth(5)
    wood:draw()
end


Wood = class()

function Wood:init(x)
    self.size = x
    self.spawn = {}
    for i=1,self.size do
        spawn = vec2(0, math.random(HEIGHT))
        table.insert(self.spawn, spawn)
    end
end

function Wood:draw()
    for i,v in ipairs(self.spawn) do
        line(i*5,v.y,i*5,0)
    end
end 

I’m not quite sure what you want to do, but hopefully the code below will help. If you want to create a table of lines marching across the screen, then define the table in setup, and create as many copies of Wood as you want. I’ve created one to start with (note how I don’t just say “Wood()”, but I assign it to a table value - effectively I’m saying w[1]=Wood(). Then each time you touch the screen it will add another Wood item to the table, so you get multiple lines.

So basically, the Wood class only refers to a single line, not a table of lines. The table with all the different lines in it is held in Main.

Note that the loop through the table pairs then happens in the Main draw function

In case you just want the line to start again from the left when it reaches the right, I added a line that deducts WIDTH from the value of x

If this isn’t clear, I suggest reading up some more on classes. I have a tutorial here

https://coolcodea.wordpress.com/2013/03/22/7-classes-in-codea/


-- construction dodge

function setup()
    w={}
    table.insert(w,Wood())
    end

function draw()
    background(40, 40, 50)
    for i,ww in pairs(w) do
        ww:draw()
    end
end

function touched(touch)
    if touch.state==ENDED then table.insert(w,Wood()) end
end

Wood = class()

function Wood:init()
    self.x = 0
    self.size = 50
    self.y = math.random(HEIGHT)
end    

function Wood:draw()
    self.x = self.x + 5
    if self.x>WIDTH then self.x=self.x -WIDTH end 
    pushStyle()
    strokeWidth(2)
    stroke(255)
    line(self.x,0,self.x,self.y)
    popStyle()  
end

Thx