Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

parameter.action outside a function?

edited January 20 in Questions Posts: 237

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!

Comments

  • Posts: 237

    Message is

    attempt to call a table value
    stack traceback:

    And nothing else.

  • Posts: 237

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

    function setup()
    print("Hello World!")
    end

    function draw()
    end

    parameter.action("hello", function()
    print("hi")
    end)

    ‘’’

  • Posts: 237

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

  • dave1707dave1707 Mod
    Posts: 6,787

    @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.

  • dave1707dave1707 Mod
    Posts: 6,787

    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.

  • Posts: 237

    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

  • dave1707dave1707 Mod
    Posts: 6,787

    @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
    
  • edited January 20 Posts: 237

    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.

  • dave1707dave1707 Mod
    Posts: 6,787

    @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.

Sign In or Register to comment.