FAQ  •  Register  •  Login

Code questions

<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Tue Jun 07, 2016 1:34 am

Code questions

First question: Is this real Lua? I am (still) a complete programming noob. Sorry guys :oops:

  Code:
function setup()
    fors()
end

function draw()
    background(50,50,50,255)
    fill(150,200,100,255)
    strokeWidth(2)
    for a = 1,w do
        for b = a,h do
            rect(xX[a],yY[b],WIDTH/w,HEIGHT/h)
        end
    end
end

function fors()
    h = 80
    w = 100
    xX = {}
    yY = {}
    for a = 1,w do
        local x = WIDTH/w*a-WIDTH/w
        table.insert(xX,x)
    end
    for a = 1,h do
        local y = HEIGHT/h*a-HEIGHT/h
        table.insert(yY,y)
    end
end



Second question, if I bump up w to 1000 and h to 800, it won't draw the rectangles. I'm not sure why.

I'm just playing around with drawing lots of rectangles on an iPad and wondering if maybe I have terrible methods for drawing grids :P
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

bobdaduck

User avatar

Global Moderator

Posts: 790

Joined: Thu Mar 11, 2010 1:39 pm

Location: Utah

Post Tue Jun 07, 2016 6:48 pm

Re: Code questions

Looks like lua to me! Does it throw any error messages? Maybe the rectangles are just too big.
Little_Apple wrote:DnD: the REAL bitfighter levelgen documentation

Santiago ZAP wrote:bob doesn't make new maps, he makes new gamemodes
<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Wed Jun 08, 2016 9:52 pm

Re: Code questions

^didnt see any, but idk how Codea works tbh

But, new theory, maybe iPad has limitations on what it can draw on screen. Also, realized that it was making the rectangles smaller than a pixel anyway which may have had something to do with it :oops:

ANYWAY... Ignoring that problem, I'll make a new question.

How should I save user inputs for a music writing app? Should I just throw everything in tables?
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

Fordcars

User avatar

Posts: 1016

Joined: Fri Apr 20, 2012 3:51 pm

Location: Some city, somewhere

Post Thu Jun 09, 2016 4:54 pm

Re: Code questions

Yes, or even a table of tables if you want to be object oriented :)
skybax: Why is this health pack following me?
bobdaduck: uh, it likes you.
<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Sat Jun 11, 2016 9:08 pm

Re: Code questions

  Code:
-- Table Of Tables

function setup()
    tables()
end

function draw()
    background(40, 40, 50)
    strokeWidth(2)
    fill(50,20,100,255)
    for i = 1,a*b do
        rect(coordinates[1][i],coordinates[2][i], WIDTH/a,HEIGHT/b)
        --X y width height of rectangle
    end
end

function tables()
    coordinates = {{},{}}
    a = 12
    b = 7
    for i = 1,a do
        for j = 1,b do
            local x = WIDTH/a*i-WIDTH/a
            local y = HEIGHT/b*j-HEIGHT/b
            table.insert(coordinates[1],x)
            table.insert(coordinates[2],y)
        end
    end
end


Table of tables like this?

Also, I only need 12 X coordinates and 7 y coordinates but I am pretty sure my for loops actually make 84 of each. Not sure, still trying to find a print command that actually tells me the number of items in a table
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

Fordcars

User avatar

Posts: 1016

Joined: Fri Apr 20, 2012 3:51 pm

Location: Some city, somewhere

Post Sun Jun 12, 2016 9:52 am

Re: Code questions

Try logprint(#table) to print the amount of elements in a table :)

I am not really sure what you are trying to do though, is it supposed to draw a bunch of triangles based on user input?
skybax: Why is this health pack following me?
bobdaduck: uh, it likes you.
<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Mon Jun 13, 2016 10:26 pm

Re: Code questions

Actually rectangles arranged to look like a triangle, idk if rect(x, y, w, h) is a standard Lua command or if it's only in Codea like the touched function

Be easier if I had a desktop :(
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002

Return to Off-Topic

Who is online

Users browsing this forum: No registered users and 9 guests

cron