Text formatting

All,

Anyone know how to include the --[[ and --]] characters in a string which is hiding code from the rest of the project. I have this present in some code which I want to enclose in the this same character set so that I can copy parts of the code into another area without destroying the original until I get something that works, but Codea keeps throwing up errors so I cant get anything running.

Short of printing it out or flipping between different projects I cant see a way through.

I’m not clear on what you’re trying to do.

You’re trying to copy code from one tab onto another but you don’t want it to be visible to the rest of the program?

If that’s it, it’s definitely possible with [[ and ]], but another trick is to wrap it in a function call so that no other code can access it without running the function.

@UberGoober - thanks for that but that’s not the problem. My bad very poor description. I’ll try again. I copied the contents of one tab in a project to a new tab in another project. I wanted to copy the key parts to another tab in the new project. So I enclosed all the transferred code in the new tab between —[[ and —]]. But, I immediately got an error cause there was another —[[ and —]] embedded in the transferred code enclosed in inverted commas as it was there in part of a string to be printed in another tab. I didn’t want to remove these for matters as it would invalidate the code so I was asking if there was a way to remove the error. Probably OK to remove short term but I always worry that I might miss this later as I tend to flip around with different projects.

Ah, I think I get it.

If I understand correctly, the root of the problem is that you want to import some text and keep it from being active in the code, but you can’t easily comment it out because it already has bracket comments inside it.

I think that’s a pretty thorny problem, and my question would be do you need that code to hang around before you actually use it?

If it’s not supposed to be used right away, maybe you’re importing it too early?

@Bri_G Try putting a space between the [[ and ]] as in —[ [ and—] ] .

PS. That got rid of the error, but didn’t comment out the code. So ignore the above suggestion.

PSS. If you put spaces between the [[ and ]] inside of the ‘ ‘ that seems to work. I knew the spaces went someplace.

You can nest --[[ / ]] and [[ / ]] by inserting an = sign between the brackets. Codea supports nesting up to two = signs, so:

--[[/]]
--[=[/]=]
--[==[/]==]

For multiline strings

[[/]]
[=[/]=]
[==[/]==]

Here’s an example:

function setup()
    -- Expose parameters to control our line
    
    -- The start point

    --[=[
    parameter.number("x1",0,WIDTH,100)
    parameter.number("y1",0,HEIGHT,100)

    --[[
    -- The end point
    parameter.number("x2",0,WIDTH,WIDTH-100)
    parameter.number("y2",0,HEIGHT,HEIGHT-100)
    ]]

    -- The stroke width
    parameter.number("width",1,100,10)
    ]=]

    -- The line cap type
    parameter.integer("lineCap",0,2,0)
end  

@Simeon @dave1707 - thanks for the info both spaces and = worked. Now I can progress, — hopefully!