I use to program although it has been quite a few years so Im having to relearn most of it, Im trying to make it so when one of the 3 buttons are clicked it reads the file attached to the button but all i get at the moment is nul in the terminal when i run it
Ive tried moving around sections of code but I cant find anything that works
local centerX = display.contentCenterX local centerY = display.contentCenterY local background = display.newImage("background.png") background.x = centerX background.y = centerY local widget = require( "widget" ) -- Path for the file to read local cluthaDirect = system.pathForFile( "clutha\_Run.txt" ) local ranfDirect = system.pathForFile( "ranf\_Run.txt" ) local centDirect = system.pathForFile( "cent\_Run.txt" ) local function cluthaButtonEvent(event) local phase = event.phase if "ended" == phase then print(cluthaFile) end end local function centButtonEvent(event) local phase = event.phase if "ended" == phase then print("C E N T R A L") end end local function ranfButtonEvent(event) local phase = event.phase if "ended" == phase then print("R A N F U R L Y") end end local cluthaButton = widget.newButton { left = centerX - 60, top = centerY - centerY, width = display.contentWidth/2, height = 60, defaultFile = "buttonUnpressed.png", overFile = "buttonPressed.png", label = "clutha", onEvent = cluthaButtonEvent, } local centButton = widget.newButton { left = centerX - 60, top = centerY - centerY + 80, width = display.contentWidth/2, height = 60, defaultFile = "buttonUnpressed.png", overFile = "buttonPressed.png", label = "central", onEvent = centButtonEvent, } local ranfButton = widget.newButton { left = centerX - 60, top = centerY - centerY + 160, width = display.contentWidth/2, height = 60, defaultFile = "buttonUnpressed.png", overFile = "buttonPressed.png", label = "ranf", onEvent = ranfButtonEvent, } -- Path for the file to read --local cluthaDirect = system.pathForFile( "clutha\_Run.txt" ) --local ranfDirect = system.pathForFile( "ranf\_Run.txt" ) --local centDirect = system.pathForFile( "cent\_Run.txt" ) -- Open the file handle local cluthaFile, errorString = io.open( cluthaDirect, "r" ) local centFile, errorString = io.open( centDirect, "r" ) local ranfFile, errorString = io.open( ranfDirect, "r" ) if not cluthaFile then -- Error occurred; output the cause print( "cluthaFile error: " .. errorString ) else -- Output lines for line in cluthaFile:lines() do print( line ) end -- Close the file handle --io.close( cluthaFile ) end cluthaFile = nil