All,
Sorry about the slow response on this but I have not been able to get enough time to resolve the issues I have encountered. So I am posting the current state of my code (based on @dave1707 s code) with different approach. Please feel free to recommend changes.
Several points to note:
- Lost a lot of time trying to find addressing needed until I used “Examples:Lines” for instance.
- There seems to be a hangover from the menu in some of the examples eg in ‘bubbles’ the text at the top is very big.
- Errors keep cropping up for the touched() function, tried to add parsing for the touched() function but wouldn’t run properly.
- I use an image of the screen from Codea for the menu, it includes my chain2 project (top left) which runs within the examples collection properly using @dave1707 s button menu system. Trying to attach my image.
-- ProjectRunner
function setup()
--
bck = readImage(asset.documents.XamplesD)
button = readImage(asset.builtin.UI.Grey_Button_03)
st1="if not reStarting then reStarting=true setup() end"
st2="parameter.action('Main Menu',function() restart() end)"
projNo = #proj
dbug = false
path = "Examples:"
demo = 999
str = ""
menu = true
v = 0
lstart = HEIGHT - 40
path = "Examples:"
posX = {128,256,384,512,640}
posY = {875,714,553,392,231,70}
end
function draw()
-- This sets a dark background color
background(40, 48, 50)
spriteMode(CENTER)
sprite(bck,WIDTH/2,HEIGHT/2-40,WIDTH*0.9,HEIGHT*0.9)
sprite(button,WIDTH/2,lstart,520,80)
fontSize(56)
fill(255, 21, 0)
text("EXAMPLES MENU",WIDTH/2,lstart)
end
function touched(t)
--
if t.state == ENDED then
for tx = 1,5 do
if math.abs(t.x - posX[tx]) < 64 then
for ty = 1,6 do
if math.abs(t.y - posY[ty]) < 80 then
demo = (ty-1)*5 + tx
end
end
end
end
if demo ~= 999 then
b = proj[demo]
b = path..b
if b=="Exit" then
close()
else
if demo ~= 999 and menu == true then
projectBuild(b)
loadstring(str)()
menu = false
end
demo = 999
end
end
end
end
function projectBuild(b)
--
lst=listProjectTabs(b)
for c,d in pairs(lst) do
str=str..readProjectTab(b..":"..d)
str = str.."\
"
end
if dbug == true then print(str) end
a,v=string.find(str,"function setup()",1,true)
str=string.sub(str,1,v)..st2..string.sub(str,v+1,#str)
a,v=string.find(str,"function draw()",1,true)
str=string.sub(str,1,v)..st1..string.sub(str,v+1,#str)
end
proj = {
"Lines",
"Multi Touch",
"Handling Touches",
"Pencil Case",
"Ellipse Modes",
"Shapes and Smooth",
"Graphics Styles",
"Blend Modes",
"Speakeasy",
"Sounds Plus",
"Parameters",
"Animation",
"Camera",
"Basic Physics",
"Physics Lab",
"Mesh",
"Shaders",
"Roller Coaster",
"Flappy",
"Cargo-Bot",
"Anagrams",
"Brickout",
"Lua Jump",
"Gravity",
"Hoops n Bubbles",
"Ping",
"Bubbles",
"Image IO",
"Exit"
}
Edit: added the forgotten Carg-Bot to the project list, and corrected search and replace errors in Mesh and Shaders.