Snippet: multi-line coding with graphics from the console

Hi, Everyone.

For I project I’m working on, I wanted to be able to test out small snippets of graphics code in the Codea console. Unfortunately, that doesn’t seem possible from the current Codea console so I figured out how to add this small snippet of code which makes it possible using the parameter functionality to set a variable that gets picked up in function draw(). In addition, by waiting for the user to enter <enter/return> twice, it allows the user to enter multi-line text more easily in the console:

function setup()
parameter.text("LuaCommandsEnterTwiceToRun","")
-- add your additional setup code here
end

function draw()
background(0,0,0,0)
if LuaCommandsEnterTwiceToRun ~= "" then
        if string.find(LuaCommandsEnterTwiceToRun, "\n\n") then
            load(LuaCommandsEnterTwiceToRun)()
        end
    end
end

Fyi, in case others find it useful :blush:

Sorry, Everyone, I realized the snippet functions better using 'return ’ in the load statement like so:

function setup()
parameter.text("LuaCommandsEnterTwiceToRun","")
-- add your additional setup code here
end

function draw()
background(0,0,0,0)
if LuaCommandsEnterTwiceToRun ~= "" then
        if string.find(LuaCommandsEnterTwiceToRun, "\n\n") then
            load('return '..LuaCommandsEnterTwiceToRun)()
        end
    end
end

Fyi :slight_smile:

Wow, that’s a super neat hack. I can’t think of an immediate use for it for myself but it’s cool to know it’s possible.

1 Like

Another way to do this might be to choose the Run menu and select “Run in New Window” (iPad only). Then you can edit the code live on the left, while the project runs on the right

Thanks, @sim :blush:

On the previous App Store release some of my scripts would crash when I’d do that for unclear reasons. I’ll try this method in the new release and send logs if I get any further crashes.

FWIW imho running while windowed in any way will crash if the keyboard is open when the run button is pushed. If I’m working windowed I always close the keyboard before running.

1 Like