CodeaUnit throwing strange error

Because CodeaUnit wouldn’t work as a dependency, I’ve started including it as a tab, and it has worked. However, in my most recent use, it sometimes gives the strange error reported in Bugs:

attempt to call a table value
stack traceback:

There is no traceback shown, and the program’s setup has already run correctly. The program is now dead in the water: I suppose that’s no surprise.

If I restart the program with the recycle button, it works correctly.

CodeaUnit sets up a parameter:

parameter.action("CodeaUnit Runner", function()
    print("button running")

When it fails, the “button running” message does not come out. So it is as if the failure is near the button logic.

I’m at a loss as to how to chase this. Recycling the program seems always to avoid the problem.

Advise me, please.

That is odd. The button running message should not print unless you tap the button though? And this error occurs before you tap the button?

No, sorry. When the program starts, my setup prints run. The “button running” message does not come up, as expected. If I press the rerun button, then the CodeaUnit button, all works as it should.

In what’s below, by Fresh Run I mean I’ve been in the source and pressed that run button.

Fresh Run
Setup print runs
Button appears (button running does not print)
Press button

  • print does not appear
  • tests do not run
  • error message appears with no stack trace

Fresh Run
Setup print runs
Button appears, button running does not print
Press Recycle
Setup print runs again
Button appears, does not print
Press button
Everything works normally

Thanks you for the steps. Is this project possible for you to export as a zip file and allow me to test it?

Happy to. How shall I get it to you?

Duh. :slight_smile:

@RonJeffries great! I can reproduce the bug here so I’ll try to fix it.

Apple is taking so long with 2.6.2 I think I’ll be rejecting it in favour of submitting 2.6.3 so I can include bug fixes like this (and others)

This bug is fixed for 2.6.3, it happens when parameter.action is defined in the global scope (rather than in the setup() function or similar) and comes about because of the way Codea was checking projects for errors by initially evaluating the Lua code.

@Simeon - I had a funny error, it could be my lack of understanding Codea under the hood, I was playing with a project which operated in two modes. In each mode it used parameters to make changes. The project fired up an error but, if I continued changing the parameters and using an action button part of the program still seemed to be running. I didn’t think that was feasible - the error seemed to be coming from a Craft section and the running part from reading and printing using json decoding a file.

An oddity - whilst setting up a new project, on pressing the new button, the button seemed to rise off the screen with a fainter copy of the button behind it. It does look like you have overlaid the projects screen in a separate layer above the background - is that what I am seeing?

Super, Simeon, thanks!

@Bri_G The first one could be related to this bug, having a test project would be a good way for me to try debug it. On the latter issue it’s because the beta version has drag-and-drop enabled on the project browser so I could see how it feels. That will be disabled for the App Store release until I put in functionality so you can drag and drop projects between sections and into/out of Codea.

@Simeon - you are probably right, looks a little like the error @dave1707 mentioned. Knocked up a bit of code to demonstrate. Note deliberate error introduced in Serror which should be Sview.

-- Error2

-- Use this function to perform your initial setup
function setup()
    scene = craft.scene()
    myEntity = scene:entity()
    parameter.action("Load", function()
    parameter.boolean("EnvMap", false, function(b)
        if b then
 = env     
   = nil       

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

function changeView(S)
    if EnvMap then
        tab1 = readText(views[S].ename)
        env = craft.cubeTexture(json.decode(tab1)) = env
        tab = readText(views[S].ename)
        img = nil
        img = json.decode(tab)
        imgRight = readImage(img[1])       
        imgLeft = readImage(img[2])
        imgBack = readImage(img[3])
        imgUp = readImage(img[4])        
        imgFront = readImage(img[5])
        imgDown = readImage(img[6])

function boxinit()
    views = {{ename = "Environments:Night"},
             {ename = "Environments:Sunny"}

Code based on @Johns Craft demo. If you run and use the slider and action buttons you will see the repeated error and printing of json files.