Codea 2.3 Beta

Here’s the thread about Codea 2.3 beta.

Tell me about your broken code!

I’m finding that i have to call string.format a lot more than before because decimals are appearing a lot more, and i’m adding integers

tween.delay doesn’t seem to be working for me. Any idea why?

@SkyTheCoder could be broken by Lua 5.3. A brief look suggests that it might need some updating to migrate from the old varargs style.

Edit: Actually are you calling tween.delay with an integer? That might be an issue now — e.g., tween.delay(5) instead of tween.delay(5.0)

@CodeaNoob you might want math.floor and math.tointeger

Ran through a couple of my more important current programs and fixed them.

  • I have no issues with tween.delay

  • background now wants integers (was an annoying but quick fix in my programs that animate background colors)

  • clip also now wants integers, again an easy fix.

It’d be nice if these functions could take non-integer values and convert them for us, would make the transition easier.

I also ran a few of my projects and the only thing that really changed was in my binairo game, I had to add 4 lines of code, because a ‘0’ was being shown as ‘0.0’ but it’s no big deal to change that.

Then there’s math.random… it’s a shame we can’t produce floats anymore, tho the easy fix would be to, for example if you want something between 0 and 1, you could just ask for a random between 0 and 100, and divide it by 100, again, not a big deal

@stevon8ter math.random generates both floats and integers now. Here is the documentation

math.random ([m [, n]])

When called without arguments, returns a pseudo-random float with uniform distribution in the range [0,1). When called with two integers m and n, math.random returns a pseudo-random integer with uniform distribution in the range [m, n]. (The value m-n cannot be negative and must fit in a Lua integer.) The call math.random(n) is equivalent to math.random(1,n).

This function is an interface to the underling pseudo-random generator function provided by C. No guarantees can be given for its statistical properties.

So to produce a float in the range [0, 5) you do

x = math.random() * 5.0

To produce an integer in the range [1, 5] you do

x = math.random(5)

@simeon sorry, silly me, I should’ve read the documentation :stuck_out_tongue:

thanks for the explanation :slight_smile:

@Simeon Okay, I got it: collectgarbage() now stops any Tweens currently running. Kind of a big problem because it broke the entire functionality of my game I was planning to release to the App Store soon.

On a parallel thread - is there a way of Testflighting 2.3 and keeping the current released version (2.2) installed?

I think i’d like if poss to run these in parallel, as I really dont want to update my code on some existing projects im working on currently and rather sandbox/ring-fence the 2.3 stuff.

As this looks like a major update, it sort of makes sense as theres a fair bit of stuff that may break ‘ongoing’ projects. What do people think?

@SkyTheCoder I’ll have to look into why that is.

@andymac3d unfortunately not. It is required to have the same identifier as the released app (on Apple TestFlight the last beta is basically the store version). The 2.3 stuff should rapidly gain maturity in the next few updates as people find and report bugs. I want it to be equivalent aside from the language changes (which are pretty minor, mostly varargs and integers, and your code should migrate towards anyway)

Thanks @Simeon - good to know. I’ll have a look at migrating things to 2.3 over the weekend :wink:

Looping tweens no longer seems to work

@SkyTheCoder, garbage collection will take tweens that haven’t been assigned to a variable yet. Going something like safe = tween() should not get collected

@JakAttak It seems to be deleting some Tweens that are assigned to variables. Does the ID being in a table count? There are way too many animations to add variables for all of them.

I tried this code:

local _t = tween.__callback
local _td = tween.delay
_vars = {}

local mt = debug.getmetatable(tween)

mt.__callback = function(...)
    local t = _t(...)
    table.insert(_vars, t)
    return t

mt.delay = function(...)
    local t = _td(...)
    table.insert(_vars, t)
    return t

debug.setmetatable(tween, mt)

But it doesn’t seem to work. Any ideas?

Edit: Flickable, my touch library, seems to be broken because of this too, because it used tween.delay(0, …) to add its code to the touched function.

@Simeon I don’t know if this is a bug specific to the 2.3 beta or not, but when I sync a file from dropbox, and it has the same name as an image I already had on there, but I delete that image on my pc already, then put the other one in… I then try to display the image onto the screen but get and error that a code image is expected. If I then completely close codea, and restart it, this error is gone and my image can be seen using the sprite command.

Idk if this made any sense, and idk if this is something dropbox related or lies within codea, I just thought I’d let you know

I’m not a fan of the new underlined words for all the buttons

Memo to self: don’t update Codea just before using a program in a live environment!

(Fortunately, I realised in time and downgraded to Codea 2.2 from the App store.)

More things that have vanished:

  • table.getn no longer works, use #table instead
  • string.gfind no longer works, use string.gmatch instead (CC devs, please note)
  • after function (...) then arg is not populated. Quick fix is local arg={...} and (if needed) arg.n = #arg.
  • getfenv/setfenv no longer exist

That last one is pretty annoying. Lua 5.1 to 5.2 has changed how environments are handled, and I don’t seem to be able to get a handle on upstream local variables any more. I can get them via debug.getlocal and if they already exist I can set them via debug.setlocal, but I can’t set new ones. This is somewhat annoying.

It therefore breaks my localisation code for conditionally selecting a particular tab to run. It also breaks some of my modifications to toadkick’s cmodule library. Not sure what else is broken, and how much of it is fixable.

@JakAttak what underlined words for all the buttons? Can you show a screenshot of what you are referring to?

@Andrew_Stacey the setfenv/getfenv is a big change. Googling around gives a few workarounds for reproducing its behaviour.