Codea 3.7.1 (371)

any one else notice that the editor will freeze up every once in a while for a few seconds?

this has been happening to me all day, even after i reset my ipad, i’m thinking it’s related to the to auto save feature? maybe my project is large enough to cause the save to hang for a couple seconds?

@skar - my projects don’t tend to be very big, although I often have several tabs. I occasionally have a slow response which I have assumed was due to poor touch response.

Another feature of the editor I have noticed is sometimes the editing point seems to move for no apparent reason and fires up an error as I start editing on a different line without knowing it. Then I have to search for it as the error report may be several lines away.

@dave1707 - have you noticed anything similar?

@Bri_G I haven’t done any editing of large projects recently, so I don’t see the delays. I just see a lot of popup crashes after I close Codea. I figure those will eventually be corrected as the current version is updated.

Help. I’ve looked and looked and can’t find it; I thought I read that the modern runtime would use new class() code, and I want to find/read that source. I know I saw it before (months and months ago), but 30 minutes of googling and searching here fails to find any reference to it. Can someone point me to that code?

I don’t know if this is what you’re after, but this is all I found.

-- Class.lua

function class(base)
    local c = {}    -- a new class instance
    if type(base) == 'table' then
        -- our new class is a shallow copy of the base class!
        for i,v in pairs(base) do
            c[i] = v
        end
        c._base = base
    end

    -- the class will be the metatable for all its objects,
    -- and they will look up their methods in it.
    c.__index = c

    -- expose a constructor which can be called by <classname>(<args>)
    local mt = {}
    mt.__call = function(class_tbl, ...)
        local obj = {}
        setmetatable(obj,c)
        if class_tbl.init then
            class_tbl.init(obj,...)
        else 
            -- make sure that any stuff from the base class is initialized!
            if base and base.init then
                base.init(obj, ...)
            end
        end
        
        return obj
    end

    c.is_a = function(self, klass)
        local m = getmetatable(self)
        while m do 
            if m == klass then return true end
            m = m._base
        end
        return false
    end

    setmetatable(c, mt)
    return c
end

@blacatena Heres something else I found.


John

I changed the class system to use https://github.com/kikito/middleclass which requires a name when you use class(name) so you would do test = class('test') but I can modify middleclass to make the name optional

Thanks @dave1707 … that’s what I was looking for (middleclass.lua). I have no idea why I couldn’t find it myself. I need to go back to Internet school for a refresher course.

@blacatena I didn’t find it by doing a search. I just looked thru all of the Codea 3. whatever topics and just happened to find it. Glad it’s what you were looking for.

@dave1717
A brute force search algorithm? Ugh, that would use too many of my limited CPU cycles. :slight_smile:

@sim I’ve had multiple crashes when running my game in a separate window and making (minor) changes to the code at the same time. My game also runs at around half the framerate when running it in its own window. The latter isn’t really a big issue, though. I’m not sure if editing + running a large project at the same time is even possible, but I wanted to tell you in case this can be fixed.

Furthermore, putting Codea in the background while the Shader Lab is open, always leads to a crash. In the Shader Lab, the icon for the color-picker is shown in all parentheses. Something like vec2(…, …) has the icon showing right before the closing parenthesis, which means that the last parameter is not visible.

@sim @John @dave1707 - after reporting several crashes in V4 with my NoNo project transfer, I noted an issue with text alignment relative to graphic coordinates. Played around with a few simple graphics to demonstrate. Looks like text is drawn below the target positions, and alignment left and right switched. Played havoc with my project in V4.


-- Texting V4

viewer.mode=FULLSCREEN
function setup() 
    --
end

function draw()
    --
    background(0)
    style.push()
        -- text alignment
        style.fill(239, 255, 0)
        style.font("Baskerville-Bold")
        style.fontSize(64)
        style.textAlign(LEFT)
        text("Socket V4",WIDTH/2,HEIGHT-80)
        style.fill(255, 14, 0)
        style.textAlign(RIGHT)
        text("left aligned - not",WIDTH/2,HEIGHT-160)
        -- line placement
        style.stroke(67, 227, 236)
        style.strokeWidth(4)
        line(68,HEIGHT-80,700,HEIGHT-80)
        -- rect positioning
        style.stroke(67, 236, 78)
        style.noFill()
        style.rectMode(CORNER)
        rect(60,600,160,80)
        style.rectMode(CENTER)
        rect(320,600,160,80)
        style.rectMode(CORNERS)
        rect(420,600,580,680)
        -- line through rectangles
        style.stroke(254, 227, 236)
        style.strokeWidth(4)
        line(60,600,700,600)
        -- ellipse mode test
        style.strokeWidth(8)
        style.stroke(160, 236, 78)
        style.noFill()
        style.ellipseMode(CORNER)
        ellipse(60,400,160,80)
        style.ellipseMode(CENTER)
        ellipse(320,400,160,80)
        -- line through rectangles
        style.stroke(254, 227, 64)
        style.strokeWidth(4)
        line(60,400,700,400)
        --
        style.font("Arial-BoldMT")
        style.textAlign(CENTER)
        style.noStroke()
        style.fontSize(32)
        style.fill(236, 67, 219)
        text("In Ellipse",320,400)
        style.textAlign(RIGHT)
        text("Ellipse Right",60,400)
    style.pop()
end

@Bri_G If you want a temporary fix until it’s permanently fixed, you can add these lines at the start of your code. It just redefines the values for LEFT and RIGHT.

LEFT=4
RIGHT=1

@dave1707 - thanks for that. That would adjust horizontal positioning, I’d have to manually adjust vertical positioning of the text. Rather wait for the corrected update so all is consistent.

The crashing of the V4 project is more worrying though. Think I’ll have to isolate sections of code to identify the cause. Wish we could trap the crash ourselves.

@Bri_G Thanks for that example project, I can use that to identify and fix those alignment issues.

In Codea 4 there is a new form text drawing function overload, text("string", x, y, w[, h]), allowing you to specify the width (and optionally height) of the text box you wish to draw. The text itself is then treated as a rectangular region, and new constants TOP, MIDDLE and BOTTOM can be combined with LEFT, CENTER and RIGHT using the | operator (i.e. style.textAlign(CENTER|MIDDLE))

I haven’t tested every possible combination of alignment settings for both versions of text() so there will probably be more issues to solve here

@John - thanks for the feedback, will play around with the text options. Do the width and height parameters effectively make the fontSize() function redundant.? I suppose you’ll retain it for consistency and standards

Oh, one other thing - I noticed a slight delay on running that demo as compared to V3.

Here’s a little program for V4 to show the text options mentioned above.

viewer.mode=FULLSCREEN

function setup()
    tab1={TOP,MIDDLE,BOTTOM} 
    tab2={LEFT,CENTER,RIGHT} 
    tab3={"TOP","MIDDLE","BOTTOM"} 
    tab4={"LEFT","CENTER","RIGHT"}
end

function draw()
    background(0)   
    for x=1,3 do
        for y=1,3 do
            style.fill(0,50,50)
            style.stroke(255,0,0) 
            style.strokeWidth(2)
            rect(x*200-100,HEIGHT-y*200,160,100)   
            style.textAlign(tab1[x]|tab2[y])
            style.fill(255)
            style.strokeWidth(0)
            text(tab3[x].." "..tab4[y],x*200-100,HEIGHT-y*200,160,100)
        end
    end
end

The width and height parameters don’t effect the size of the font used but just the size of the box the text is laid out in, so it replaces textWrapWidth() while also giving you an optional height for the box, with is effected by vertical alignment

I’m also building in support for text styles (shadows, outlines, etc) in native text, which won’t be 1:1 with regular text but should come in handy:

2 Likes

@John @dave1707 - thanks for text demo and outline of textual things to come. I like using shadow/3D effects with text so the new features look interesting. Thanks again.

Thank you for this @dave1707, putting it on the list to fix