parameter.action outside a function?

I’ve been away from Codea, sadly. This means i’ll be ignorant all over again. Sorry.

Sorry, post somehow got truncated. Try again:

CodeaUnit is old code. It has a parameter.action naked, outside any function, to set up a button to call the testrunner, so you need not put any test code in your app code. A naked parameter.action gets the message

attempt to call a table value
stack traceback:

With nothing else, when you press the button. This is new-ish behavior as CodeaUnit used to work. Has something changed on purpose, or is this a bug?

I’ll put a simpler example below.

Thanks!

Message is

attempt to call a table value
stack traceback:

And nothing else.

‘’’
– CUtest
– run and press button for error

function setup()
print(“Hello World!”)
end

function draw()
end

parameter.action(“hello”, function()
print(“hi”)
end)

‘’’

Also preview didn’t work, sorry for wrong code markdown.

@RonJeffries None of my code has the parameters outside a function. I do know that if you put the parameter inside setup, it does work. So if it used to work for you, then I would say something did change.

There’s only two things I put outside a function at the top of the code. That’s supportedOrientations and displayMode. Everything else I put inside functions.

Makes sense for most purposes, but i’d guess naked code has some intended meaning, like run at init time, in Lua. Will look it up when I get a chance

@RonJeffries Some values aren’t defined properly before setup() is run. The first time you run this code, the variables w and h won’t have the correct values for WIDTH and HEIGHT. Also, if you uncomment the xxx() call, you’ll have an error because the function xxx() isn’t defined yet when xxx() is parsed. Only TLL can fully explain what happens because they’re the ones with the Codea code.

w=WIDTH
h=HEIGHT

--xxx() 

function setup()
    print(WIDTH,HEIGHT)
    print(w,h)
    xxx()
end

function xxx()
    print("xxx")
end

True, but xxx() after it’s defined does work. I don’t see why the parameter.action at the end of CodeaUnit shouldn’t work. I’ll see if I can gin up a simple bug report.

@RonJeffries Maybe the reason that the parameter.action at the end doesn’t work in your example above is because Codea doesn’t know anything about parameters until after setup() is executed. I think Codea tries to run any code not in a function before it runs any function irregardless of where it’s placed in the list of code. Since parameter.action isn’t in a function it’s being executed before the setup() function. TLL will have to answer this since they know how the code executes.