Codea 3.8 (375)

math.floor seems to work in the different cases.


function setup()
    print(math.floor(12.01))
    print(math.floor(32.99))
    print(math.floor("23.99"))
    print(math.floor(-12.01))
    print(math.floor(-32.99))
end

@skar - I like your truncation function, added it as a function to my utils list.

@dave1707 - thanks for demonstrating the extent of the math.floor function, never really tested this.

@sim couple of things I noticed while putting these into a project. I ran the project then tried to capture the screen image for the project icon. The text when the image dialogue is displayed is truncated so new users won’t know to press S…n to save the image as an icon.

Secondly - I had a funny whilst closing a project - it temporarily froze with the new project dialogue window enlarged and shifted to the right. Shortly after the main project window appeared rotating in from the right axis in a sort of door animation.

By the way, don’t know if this was available before, but I used the emoji button on the keyboard to print (using text()) an emoji to the screen changing its size with textSize() I enclosed the image in inverted commas. Can you use character codes to achieve this ?

@sim @dave1707 - whilst updating my ‘old lady’ project to use emojis I ran it for a while and then came out of Codea. Shortly after Codea crashed. Not sure if it was Codea still running in the background and crashed on closing or Codea leaving residue when closing that was a ‘Codea crash’. Posted a crash report and will try to attach the project here.
oldlady.zip (38.1 KB)

Edit: Weird, had two crashes by running the demo so fairly confident that problem associated with the demo. Since then ran demo twice for different extents and neither resulted in crash of Codea.

@jon @sim - in carbide feedback spreadsheet I suggest you add another column in first row which contains the Build number used by contributor.

1 Like

This is the (unintuitive) but correct behaviour for math.tointeger

If the value x is convertible to an integer, returns that integer. Otherwise, returns nil .

So if it is a float which is integer-convertible (eg. 4.0) it will convert. Otherwise it will return nil. It is purely for changing the type of the value from a float to integer, now that Lua has integer types.

that’s so confusing lol but you’re right

@sim In v4, the constant ZERO prints 4096 instead of 0.

1 Like

We have a constant ZERO? Will look into it!

Do you know what API the constant is used with?

@sim I have a program that displays all the constants, functions, etc . When I was looking thru the constants, the majority of them can be any value that was assigned to them, but the one that stood out was ZERO with a value of 4096. I checked an older version of Codea and ZERO was assigned 0. I don’t know what api ZERO is used with, but 4096 probably isn’t going to work.

@dave1707 - I think 4096 could be the first 12 bits of a 16 bit word. Is there any variable used by Codea that requires 12 bits?

@Bri_G ZERO is a constant just like the other constants with a fixed value like math.maxinteger, math.mininteger, math.pi. I’ve never used the constant ZERO for anything, or seen it used anywhere, but ZERO should be 0. Probably when things got moved around in the new code, something got deleted and ZERO ended up with 4096.

@Bri_G Here’s the program I used for Codea V4. Slide you finger up/down to scroll.

-- constants and functions in Codea V4

viewer.mode=FULLSCREEN

local tab,all,dy={},{},0

local function srch(s)
    for a,b in pairs(tab) do
        if b==s then
            return true
        end
    end 
    return false       
end

function setup()
    for x,y in pairs(_G) do
        if type(x)=="function" then
            --;
        elseif type(y)=="function" then
            table.insert(all,x.."   ==     "..type(y))
        elseif type(y)=="number" then
            table.insert(all,x.."      "..y)
        elseif type(y)=="string" then
            table.insert(all,x.."  "..y)
        elseif type(y)=="table" then
            if srch(x) then
                for a,b in pairs(y) do
                    if type(b)=="string" then
                        b1=string.gsub(b,"\n"," ")
                        table.insert(all,x.."."..a.."  ==  "..string.sub(b1,1,80))
                    elseif type(b)=="number"then
                        table.insert(all,x.."."..a.."  ==  "..b)
                    else
                        table.insert(all,x.."."..a.."  ==  "..type(b))
                    end
                end
            else
                table.insert(all,x.."   ==     "..type(y))
            end
        else
            table.insert(all,x.."   ==     "..type(y))
        end
    end
    table.sort(all)
end

function draw()
    background(0)
    style.fill(255)
    style.textAlign(RIGHT)
    for a,b in pairs(all) do
        text(b,WIDTH/4,HEIGHT-20*a+dy)
    end
end

function touched(t)
    if t.state==MOVING then
        dy=dy+t.deltaY
    end
end

@dave1707 - thanks for that, my thoughts were that there was a list of constants in Codea in a table referenced by number and a new one added or an existing one deleted displacing the pointer to it.

@Bri_G Constants can be anything I guess. You just have to give it a name and a value. In the below example, I gave FIVE the value 5. I can use FIVE wherever I want. Once you create the constant, you can’t accidentally change it’s value, Codea will give an error. You can redefine it with const, but you can’t give FIVE another value without doing so. So somewhere in Codea V4, the const ZERO was given the value of 4096 by mistake.

local FIVE <const> = 5

function setup()    
    print(FIVE)
end

@sim Theres a few things happening with this code for V4. The first problem is the textAlign. If I put textAlign in setup(), it doesn’t center the text on the screen but shows left justified. The line is the center of the screen. If I uncomment textAlign in draw(), then it centers the text. So the textAlign isn’t carried from setup() into draw(). The second problem it the concatenation of z to the end of the alpha text string. If you run this code, the values of z from 1 to 9 are concatenated to the text. If you add one space after the alpha text, it doesn’t print the numbers 1 thru 9. If you add 2 spaces, then it shows the numbers 1 thru 9. The numbers 10 thru 40 don’t seem to be affected.

 viewer.mode=FULLSCREEN

function setup()
    style.textAlign(CENTER)
end

function draw()
    background(0)
    --style.textAlign(CENTER)
    for z=1,40 do
        text("qwertyuiopasdfghjklzxcvbnm"..z,WIDTH/2,HEIGHT-z*30)
    end
    style.stroke(255)  
    style.strokeWidth(1) 
    line(WIDTH/2,0,WIDTH/2,HEIGHT)
end

I can see how ZERO is confusing with no context. It’s actually the constant GL_ZERO from OpenGL and refers to the blending mode (multiplying a src or destination pixel rgb/alpha value by ZERO. That’s why there is also a ONE constant that isn’t actually one). This is what the bindings look like:

I thought it would be convenient for advanced blending techniques and removing the GL_ part just leaves you with the number :sweat_smile:

@John Thanks for the update on ZERO. I didn’t notice that ONE had the value 8192.

1 Like

@John @sim @dave1707 - just loaded @dave1707 demo just posted (ship flying to collect green spheres) and looked at changing the terrain asset. In portrait mode the assets listed in the surfaces box are displaced to the right but it’s OK in Landscape.

Also sent crash report when I was trying to set up a simple project, very little involved just graphics, and when I tried to run in a new window Codea crashed. Haven’t been able to reproduce yet.

Also, the animations when closing a project are slow and not smooth, could be my old crock of a pad. Are these optimised for metal?

@Bri_G When I bring up the Surfaces box in that game, in portrait mode it’s centered on the screen. In landscape mode, it’s in the lower right corner.

@dave1707 - sorry description wasn’t good enough. Ignoring the position of the asset window, what I found was the assets within that window were evenly distributed in landscape but had a displacement in portrait ie there was like a blank column of assets on the left meaning you had to scroll further to see all the assets I’m assuming all assets were still displayed.

Edit: don’t spend any time on this, tried to reproduce but failed. I was using the assets option in the top right menu tab, having just stopped a project running. Could be one of the ‘having run several projects’ then this happened.