OK, here is how the code works.
The database:
[lua]
id value
1 100
2 25
3 60
[/lua]
And here is the .lua file
[lua]
local composer = require( “composer” )
local scene = composer.newScene()
local widget = require “widget”
require( “sqlite3” )
local path = system.pathForFile( “data.db”, system.DocumentsDirectory )
local db = sqlite3.open( path )
local masterSdr
local sfxSdr
local musicSdr
local sliders = {} – Begins empty
for row in db:nrows(“SELECT * FROM sound”) do
print( "Row " … row.name )
– Create table at the next available array index
sliders[#sliders+1] =
{
id = row.id
value = row.value
}
end
– Slider listeners
local function sliderMasterSdrListener( event )
print(“Slider at”…event.value…"%")
local q = [[UPDATE sound SET value=’]]…event.value…[[’ WHERE id=1;]]
db:exec( q )
end
local function sliderSfxSdrListener( event )
print(“Slider at”…event.value…"%")
local q = [[UPDATE sound SET value=’]]…event.value…[[’ WHERE id=2;]]
db:exec( q )
end
local function sliderMusicSdrListener( event )
print(“Slider at”…event.value…"%")
local q = [[UPDATE sound SET value=’]]…event.value…[[’ WHERE id=3;]]
db:exec( q )
end
– Image sheet for horizontal slider
local optionsHorizontal = {
frames = {
{ x= 1, y= 40, width= 15, height= 15 },
{ x= 18, y= 40, width= 15, height= 15 },
{ x= 35, y= 40, width= 15, height= 15 },
{ x= 1, y= 1, width=50, height=10 },
{ x= 1, y= 13, width=50, height=25 }
},
sheetContentWidth = 52,
sheetContentHeight = 56
}
local slider1Sheet = graphics.newImageSheet( “Assets/sliderSheet.png”, optionsHorizontal )
– “scene:create()”
function scene:create( event )
local sceneGroup = self.view
– Initialize the scene here.
– Example: add display objects to “sceneGroup”, add touch listeners, etc.
– The background
local background = display.newImageRect( “Backgrounds/OptionsMenu.png”, display.contentWidth, display.contentHeight )
background.anchorX = 0
background.anchorY = 0
background.x, background.y = 0, 0
– Master slider
masterSdr = widget.newSlider {
sheet = slider1Sheet,
leftFrame = 1,
middleFrame = 2,
rightFrame = 3,
fillFrame = 4,
frameWidth = 50,
frameHeight = 10,
handleFrame = 5,
handleWidth = 50,
handleHeight = 25,
width = 600,
name = sliders[1].name,
description = sliders[1].description,
value = 100,
orientation = “horizontal”,
listener = sliderMasterSdrListener
}
masterSdr.x = display.contentWidth-950
masterSdr.y = display.contentHeight*0.38
– SFX slider
sfxSdr = widget.newSlider {
sheet = slider1Sheet,
leftFrame = 1,
middleFrame = 2,
rightFrame = 3,
fillFrame = 4,
frameWidth = 50,
frameHeight = 10,
handleFrame = 5,
handleWidth = 50,
handleHeight = 25,
width = 600,
name = “SFX”,
description = “SFX Slider”,
value = 100,
orientation = “horizontal”,
listener = sliderSfxSdrListener
}
sfxSdr.x = display.contentWidth-950
sfxSdr.y = display.contentHeight*0.48
– Music slider
musicSdr = widget.newSlider {
sheet = slider1Sheet,
leftFrame = 1,
middleFrame = 2,
rightFrame = 3,
fillFrame = 4,
frameWidth = 50,
frameHeight = 10,
handleFrame = 5,
handleWidth = 50,
handleHeight = 25,
width = 600,
name = “Music”,
description = “Music Slider”,
value = 100,
orientation = “horizontal”,
listener = sliderMusicSdrListener
}
musicSdr.x = display.contentWidth-950
musicSdr.y = display.contentHeight*0.58
– Insert display objects into the group
sceneGroup:insert( background )
sceneGroup:insert( masterSdr )
sceneGroup:insert( sfxSdr )
sceneGroup:insert( musicSdr )
end
– “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Called when the scene is still off screen (but is about to come on screen).
elseif ( phase == “did” ) then
– Called when the scene is now on screen.
– Insert code here to make the scene come alive.
– Example: start timers, begin animation, play audio, etc.
end
end
– “scene:hide()”
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Called when the scene is on screen (but is about to go off screen).
– Insert code here to “pause” the scene.
– Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == “did” ) then
– Called immediately after scene goes off screen.
end
end
– “scene:destroy()”
function scene:destroy( event )
local sceneGroup = self.view
– Called prior to the removal of scene’s view (“sceneGroup”).
– Insert code here to clean up the scene.
– Example: remove display objects, save state, etc.
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/lua]
This is the code if you can help please do. Thank you in advance.