Novice Question

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Novice Question

Esther McKay
Hi all-

This is one of the first programs I've built from scratch and am really excited about it, except that no one else at my school knows Lua to help me trouble shoot.  I'm using Xcode 7.3 beta 3.  I'm sure there are better ways to code it, I'm just a novice!  I've been looking for other tutorials that might be good to use with my students (who have Codea) but haven't found a lot that teach - more that are just references.

Anyhow, how it's working in the simulator is different from how it works on the iPad.  I have a rectangle printing each time to cover the prior score and in the simulator, it puts up one "cover rectangle" and then the new score.  But when I build it on the iPad mini itself, it seems to write 2 scores at the same time so it looks messy.  Any help/suggestions? Any reasons why it would work differently in the simulator than the iPad?

Thanks so much for your time.  I don't know any one else that knows Lua :)
~Esther


>From Main.lua



function setup()



    --Set the viewer to fullscreen

    displayMode( FULLSCREEN )



    total = 0



    perry = {points=50}

    bridge = {points=100}

    acadia = {points=150}


    print("Width ", WIDTH)

    print("Height ", HEIGHT)


end




function draw()



    fontSize(50)

    fill(150,0,0,255)

    --Score words

    text("Score", WIDTH/2, 650)





    fontSize(20)



    --Perry's Rectangle

    fill( 150, 0, 150,255)

    rect( 0, 0, 300, 500 )



    --Bridge Rectangle

    fill(0,150, 150, 255)

    rect(300,0,600,500)



    --Acadia Rectangle

    fill(150, 150, 0, 255)

    rect(600,0,WIDTH, 500)



    --Bridge Words

    fill(150,0,0,255)

    text("Perry's", 100, 450)

    text("Bridge", 450, 450)

    text("Acadia", 750, 450)








    fill(100, 100, 200, 255)

    ellipse (CurrentTouch.x, CurrentTouch.y, 100, 100)


    if CurrentTouch.state == BEGAN then


        if CurrentTouch.x <=300

            then total = total + perry.points

            else if CurrentTouch.x >=600

                then total = total + bridge.points

                else total = total + acadia.points

                end

        end



       --Rectangle to cover previous score

        fill(0,100,0,255)

        rect(WIDTH/2-100, 500, 200, 100)



        fill(255,255,255,250)

        fontSize(30)

        text(total, WIDTH/2, 550)

        print(total)


    end


end




---
Technology Integrator
Oceanside High School (East & West)
Owls Head Central School
Gilford Butler School
[hidden email]<mailto:[hidden email]>


Reply | Threaded
Open this post in threaded view
|

Re: Novice Question

Jonne Ransijn

Hi Esther.

Did you try clearing the entire screen at the begin of each draw, instead of clearing small areas at a time (Specifically, drawing a rectangle above the old score, which seems to use some "magic variables" (never a good idea))? I think the problem has to do with the small size of the iPad screen, and could imagine the font size being bigger aswell.
(Disclaimer: I have never used XCode before)

Reply | Threaded
Open this post in threaded view
|

Re: Novice Question

Esther McKay
Thanks so much!

Is there a command that clears the screen?  I haven't been able to locate one yet...

~Esther


---
Technology Integrator
Oceanside High School (East & West)
Owls Head Central School
Gilford Butler School
[hidden email]


From: <[hidden email]<mailto:[hidden email]>> on behalf of Jonne Ransijn <[hidden email]<mailto:[hidden email]>>
Reply-To: Lua mailing list <[hidden email]<mailto:[hidden email]>>
Date: Friday, May 20, 2016 at 7:52 AM
To: Lua mailing list <[hidden email]<mailto:[hidden email]>>
Subject: Re: Novice Question


Hi Esther.

Did you try clearing the entire screen at the begin of each draw, instead of clearing small areas at a time (Specifically, drawing a rectangle above the old score, which seems to use some "magic variables" (never a good idea))? I think the problem has to do with the small size of the iPad screen, and could imagine the font size being bigger aswell.
(Disclaimer: I have never used XCode before)

Reply | Threaded
Open this post in threaded view
|

Re: Novice Question

Jonne Ransijn

local bgcolor = {255, 255, 255, 255} -- White background color

function clear()
    fill(unpack(bgcolor)) -- Set background fill color
    rect(0, 0, WIDTH, HEIGTH) -- Fill the entire screen
end

...

function draw()
    clear() -- Clear the screen
    ...
end

This most likely works. XCode probably has a similair function, but I couldn't find any documentation. If you could tell me where you got it from I might be able to help you further.

Reply | Threaded
Open this post in threaded view
|

Re: Novice Question

Duncan Cross
In reply to this post by Esther McKay
On Fri, May 20, 2016 at 1:42 PM, Esther McKay <[hidden email]> wrote:
> Thanks so much!
>
> Is there a command that clears the screen?  I haven't been able to locate one yet...
>
> ~Esther

I don't know Codea myself, but from a quick search it looks like
background(...) is the one you want:

http://twolivesleft.com/Codea/Reference/Graphics.html#background

(Unfortunately the people on this list will mostly only be able to
help you with Lua's standard built-in functions, which do not include
any graphics functions - Codea's functions are their own thing and not
a part of Lua itself, so I'm afraid you are likely to only get guesses
here instead of truly knowledgeable responses.)

-Duncan

Reply | Threaded
Open this post in threaded view
|

Re: Novice Question

Jonne Ransijn
In reply to this post by Jonne Ransijn

I think there has been a slight misunderstanding. From what I had read from the mail, XCode is the graphics library you use, and Codea is the library your students (classmates?) use. From what I have read on the internet however, XCode is a IDE, and Codea a graphics library.  I have never used either but have found documentation for Codea and will see what I can do.

Reply | Threaded
Open this post in threaded view
|

Re: Novice Question

Jonne Ransijn

Code rewritten for Codea (Thanks, Duncan!)

local bgcolor = color(255, 255, 255) -- White background color

-- Other local variables (avoid globals in setup())

function draw()
    background(bgcolor) -- Clear the screen
    ...
end

I have to agree with Duncan that most people on this list probably can't help you with extern libraries like Codea, but also remember that the most important skill for a programmer is to be able to use Google :)

Most of the functions you need can probably be found here: http://twolivesleft.com/Codea/Reference/

- Jonne

Reply | Threaded
Open this post in threaded view
|

Re: Novice Question

Esther McKay
Thank you both very much!

---
Technology Integrator
Oceanside High School (East & West)
Owls Head Central School
Gilford Butler School
[hidden email]


From: <[hidden email]<mailto:[hidden email]>> on behalf of Jonne Ransijn <[hidden email]<mailto:[hidden email]>>
Reply-To: Lua mailing list <[hidden email]<mailto:[hidden email]>>
Date: Friday, May 20, 2016 at 9:27 AM
To: Lua mailing list <[hidden email]<mailto:[hidden email]>>
Subject: Re: Novice Question


Code rewritten for Codea (Thanks, Duncan!)

local bgcolor = color(255, 255, 255) -- White background color

-- Other local variables (avoid globals in setup())

function draw()
    background(bgcolor) -- Clear the screen
    ...
end

I have to agree with Duncan that most people on this list probably can't help you with extern libraries like Codea, but also remember that the most important skill for a programmer is to be able to use Google :)

Most of the functions you need can probably be found here: http://twolivesleft.com/Codea/Reference/

- Jonne