LoveCodea Problem

Hi All,

I know this is strictly not Codea - I use LoveCodea to develop on the PC. Most of you know that it is a wrapper for Love2D which enables you to run Codea code in a window on a PC (or Mac). I have used it for some time now with only a few niggles. But I ran into a problem when looking at basic terrain code, see the ignatz thread on Noise …

I had a problem getting the basic code to run on my iPad (blue screen only - no terrain) so I started to play around with it on LoveCodea. Managed to get the code running but after a short time Love2D shutdown with an error. What the code does is build up a terrain by drawing lines which are stored in an image() using setContext() and then used as a sprite to reduce maintain a good FPS. I think there is an error in LoveCodea which leads to memory leaks so I’m not expecting any help there. Could someone please check the code from @ignatz on their iPad to see if they have a similar problem. I use an iPad 2.

This example falls down on LoveCodea:


-- demo of shaped image

if require ~= nil then
    require("loveCodea")
end

function setup()
    img = image(1023,767)
    setContext(img)
    -- background(255, 255, 255, 255)
	strokeWidth(1)
	stroke(255,0,0,255)
    for x=0,1023 do
        y = math.random(1)*767
            line(x,0,x,y)
    end
	setContext()
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(255, 255, 255)
    -- This sets the line thickness
    strokeWidth(5)
    -- Do your drawing here
    sprite(img, WIDTH/2, HEIGHT/2)
end

Also, I know @Zoyt was looking at a javascript wrapper to run in canvas, which should be cross platform compatible. Has there been any progress there? I really prefer coding on a desktop environment and find it frustrating on my iPad when programming for long lengths of time.

Thanks,

Bri_G

:-S

@Bri_G

your code just draws 1023 lines of 767px

Therefor you just get a ‘blank’ screen (red-ish) in this case

function setup()
    -- creating an image
    img = image(1023,767)
    setContext(img)
    -- background(255, 255, 255, 255)
    strokeWidth(1)
    stroke(255,0,0,255)
    -- repeat 1023 times
    for x=0,1023 do
        y = math.random(1)*767  -- this is ALWAYS 767
            line(x,0,x,y) -- thus draw 1023 lines of 767 pixels in height.
    end
    setContext()
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(255, 255, 255)
    -- This sets the line thickness
    strokeWidth(5)
    -- Do your drawing here
    sprite(img, WIDTH/2, HEIGHT/2)
end

Hi @stevon8er,

Thanks for the reply - yes the screen generated is red. But that’s not the point - the code I provided was for the LoveCodea example on a PC/Mac to see if the Love2D error was reproducible on other machines.

The code for the iPad, I’d like to see checked on other machines, is the code written by @ignatz in the above link. It generates a mid blue landscape against a light blue background. I’ve reprinted his code here if you’d like to try it:


function setup()
    parameter.color("Colour",color(50, 100, 150, 255),UpdateLandscape)
    parameter.integer("AveHeight",300,600,200,UpdateLandscape)
    parameter.integer("VariableHeight",100,400,200,UpdateLandscape)
    ready=true --this is just here to stop UpdateLandscape doing anything before we've defined all parameters
    parameter.number("Roughness",0,1,0.5,UpdateLandscape)
    parameter.action("Create Landscape",UpdateLandscape)
end
 
function UpdateLandscape()
    if ready then --only create landscape if all parameters are defined
        img=CreateLandscape(0,0,WIDTH,AveHeight,Colour,VariableHeight,Roughness)
    end
end
 
function draw()
    background(154, 187, 194, 255)
    if img then 
        spriteMode(CORNER)
        sprite(img,0,0)
    end
end
 
--w,h are width, ave height in tiles, c is colour, v is variable height, r is roughness
function CreateLandscape(x,y,w,h,c,v,r)
    local i=image(w,h)
    setContext(i)
    strokeWidth(1)
    stroke(c)
    local z=math.random()
    for u=1,w do
        local a=h-v+v*noise(z+u*r/100)
        line(u,1,u,a)
    end
    setContext()
    return i
end

@ignatz has also provided a description of this code on the following page Simplex Noise discussion. I am worried that there may be a problem with my iOS8 installation or a change in iOS8 which stops me seeing the 2D terrain in the picture @ignatz has provided.

Thanks,

Bri_G

:-S

I am on iOS8 and it works fine on my iPad

does LoveCodea use the same noise function?

Hi @Ignatz,

Thanks for the feedback - my main problem is on LoveCodea, but the blank blue background screen with your code is worrying me - I can’t see the problem with the code. What generation pad are you using and how quickly is the terrain displayed?

Thanks,

Bri_G

:-S

@Bri_G - iPad 3, and 1 second

I would start debugging by replacing the noise function with a constant, eg 1, and seeing if you get a blue rectangle. If that doesn’t help, check the values of the variables being used in the formula.

@Bri_G, I also have an iPad 3 and the terrain generates in 1 second, as @Ignatz’s iPad

Also, sorry for my derpyness, it’s been a while since I’ve been here

Hi @Ignatz,

Thanks for the tip - changed the calculation to a = math.random(HEIGHT) but still no joy so I changed the strokeWidth to 3 and I started to see output. Put in the original code with strokeWidth(3) and it generated a terrain. So why does it fail with strokeWidth(1)? Wonder if this is something to do with the retina display?

Thanks,

Bri_G

=;

@Bri_G - may be to do with lower screen resolution on iPad2

strokeWidth=2 may be sufficient, but you’ll need to test

Hi @Ignatz,

Already tested and fine at 2. Maybe this is a feature that slipped through the gap with the introduction of retina screens. It would only show up with a setting of 1. Does Codea check the system it is used on? It would seem sensible to do so and global settings could then be set up for all machines.

Thanks,

Bri_G

=;

@Bri_G - @toffer mentioned he was creating a Codea runtime using WebGL. I’m not really doing much with Codea anymore, since my current project is very time consuming.

Hi @Zoyt,

Thanks for the reply - I see you’ve stepped into the big wide world - time pressures!

Just scanned the Codea archives from your link to @toffer. Staggered by the amount of effort that has gone into trying to get Codea onto a desktop development environment. A lot of talented people have been involved. I think I’ll stick with loveCodea and work around the bugs. Love2D has stepped up to version 9.0 introducing a lot of new functionality and the inevitable incompatabilities so I’ll stick with version 8.

Hope your project goes well.

Bri_G

:wink:

@Bri_G - What drives me crazy is @John and @Simeon got Codea running on the Mac, but they haven’t released it because they haven’t written anything to allow better interactions with Mac OS X. :-L

Hi @Zoyt,

That seems a real shame. Better to get it out there, the interest is now - need to take advantage of the opportunity. What do you mean better interactions? Do you mean demo apps? Or do you mean better gui. I think they should follow the example of Love2D, let you choose your own editor and just use the Codea engine to do the work.

LoveCodea was a real boon to me but it remains unfinished. An update to take advantage of their version 9.1 would be great but beyond me. Might be able to add a few frills, but never seem to have the time.

Thanks for the info, and - @Simeon get your finger out and launch Mac Codea.

Bri_G

:smiley:

@Zoyt @Bri_G
if I could get some free time during/after college etc, I could give a shot at updating LoveCodea, tho it probably wouldn’t be as efficient as when @Zoyt codes it, but I could give it a shot (not making promises tho, so don’t expect me to finish it soon/ever)

Hi @stevon8ter,

Is that 6th form college or uni?
It would be great if someone could look over the code and list the missing parts/bugs so that I could contribute to at least part. I’just looking now on changing the watch variables colours so that they don’t clash with the background.

The other thing would be what needs changeing for Love2D 9.1.

Thanks @stevon8ter.

Bri_G

:smiley:

@Bri_G, Idk what you mean with 6th form, I live in Belgium, and it’s my first year in college, doing industrial engineer sciences.

And I hope I’ll get some time to help with this, we’ll see what the time brings :stuck_out_tongue:

EDIT: @Bri_G, I’ve started resolving several problems with loveCodea for LOVE2D 0.9.0, I’ve already resolved things like sprites, and now working on it a bit more

Hi @stevon8ter,

On the 6th form front, your English is excellent so I thought you could be from UK. The 6th Form is age 17 to 18 ish, usually called 6th Form College. Beyond that Uni. On the career front - always fascinates with sciences, I’m an industrial R&D Chemist with a big interest i anything connected to computing. Good luck with your studies.

On the loveCodea front I’ve just printed out the 0.8 version to digest.

On the 0.9 front, how have you got round the new window approach in Love2D. Haven’t even looked at that yet, none of my programs run on it so I shelved for the moment.

Suggest any changes you make you should fork on the original Gist and document then we can keep pace with you.

Thanks for the update.

Bri_G

:smiley:

@Bri_G thx, and yeah I’m 18

as of the 0.9.0, I’ve really just loaded a program into the 0.9.0 and then, looking at the errors it gave, started updating small snippets at a time

As for the window update, haven’t really looked at it alot but I noticed that setMode (or so) is no longer in love.graphics but in love.window, so that was just a small adjustment

But I might have to adjust bigger parts and create new ones, since colorMode got removed in the 0.9.0 function (this is just 1 example)

If I undergo to much difficulties, I might just keep the loveCodea core, and build the rest from scratch again, I’ll just have to see how much time I have etc

Hi @stevon8ter,

Modified the setMode on mine but still a problem loading sprites - seems to be an escape sequence used in a function _loadSprite(filename) so I’m playing around with that at the moment.

Building from scratch would be a major work. If you start with that one - best of luck. I’m trying to make it compatible with Love2D versions 0.8.0 and 0.9.1 at the moment.

Thanks,

Bri_G

:smiley: