Hi,
sorry for the formatting i’ll make sure to know for next time and I’ve made a few changes for general tidy up and i now have a new error that says line 79 end expected to close funtion at line 63, however when a add an end it gives me a new error that says main.lua 81 <eof> expected near end. i have put the before and after code below (let me know if i should be starting new topic for this)
local widget = require( “widget” )
local speedField = native.newTextField( 160, 450 , 150, 30 )
–
– main.lua
–
–function to handle button events
local function handleButtonEvent( event )
if ( “ended” == event.phase ) then
print ( "Speed = " … tonumber(speedField.text) * 2.55 )
if speedField.text == “” then
local alert = native.showAlert( “Error”, “No value entered” )
elseif tonumber(speedField.text) == nil then
local alert = native.showAlert( “Error”, “Must be a number” )
elseif tonumber(speedField.text) > 100 then
local alert = native.showAlert( “Error”, “Speed must be inbetween 1 and 100” )
elseif tonumber(speedField.text) < 1 then
local alert = native.showAlert( “Error”, “Speed must be inbetween 1 and 100” )
else
local myText = display.newText(tonumber (speedField.text) * 2.55, 150, 18, native.systemFont, 16 )
myText.text = (speedField.text) * 2.55
end
end
end
–create the widget
local button = widget.newButton(
{
left = 70,
top = 460,
id = “button”,
label = “Continue”,
onEvent = handleButtonEvent
}
)
–Create function for stop button
local function displayStop()
local StopButton = display.newImage(“stop.png”)
StopButton.x = display.contentCenterX
StopButton.y = display.contentCenterY
StopButton.xScale = 0.5
StopButton.yScale = 0.5
function StopButton:touch (event)
if ( event.phase == “ended” ) then
print("#CS")
local stopText = display.newText( “Stop”, 160, -10, native.systemFontBold, 18 )
end
return true
end
StopButton:addEventListener(“touch”, StopButton)
end
local myText = display.newText( “”, 160, -10, native.systemFontBold, 18 )
local function addArrows( fullw, fullh, centerX, centerY, rotatione, command, code)
local arrow = display.newImage(“arrow.png”)
arrow.x = fullw
arrow.y = fullh
arrow.xScale = centerX
arrow.yScale = centerY
arrow.rotation = rotatione
commande = command
codee = code
function arrow:touch (event) – add the listener
print("#" … command)
myText.text = code
myText:setFillColour( 1, 0, 0)
end
return true
local arrow:addEventListener(“touch”, arrow)
end
local fullh = {160, 230, 260, 230, 160, 90, 60, 90}
local fullw = {140, 170, 240, 310, 340, 310, 240, 170}
local centerX = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30}
local centerY = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30}
local rotatione = {0, 45, 90, 135, 180, 225, 270, 315, 360}
local command = {“Forward”, “Right Forward”, “Hard Right”, “Right Backward”, “Backward”, “Left Backward”, “Hard Left”, “Left Forward”}
local code = {CF, CRF, CHR, CRB, CB, CLB, CHL, CLF}
for i = 1, #fullh do
addArrows( fullh[i], fullw[i], centerX[i], centerY[i], rotatione[i], command[i], code[i] )
end
displayStop()
Then this is the code after i add in the extra end
local widget = require( "widget" ) local speedField = native.newTextField( 160, 450 , 150, 30 ) ----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- --function to handle button events local function handleButtonEvent( event ) if ( "ended" == event.phase ) then print ( "Speed = " .. tonumber(speedField.text) \* 2.55 ) if speedField.text == "" then local alert = native.showAlert( "Error", "No value entered" ) elseif tonumber(speedField.text) == nil then local alert = native.showAlert( "Error", "Must be a number" ) elseif tonumber(speedField.text) \> 100 then local alert = native.showAlert( "Error", "Speed must be inbetween 1 and 100" ) elseif tonumber(speedField.text) \< 1 then local alert = native.showAlert( "Error", "Speed must be inbetween 1 and 100" ) else local myText = display.newText(tonumber (speedField.text) \* 2.55, 150, 18, native.systemFont, 16 ) myText.text = (speedField.text) \* 2.55 end end end --create the widget local button = widget.newButton( { left = 70, top = 460, id = "button", label = "Continue", onEvent = handleButtonEvent } ) --Create function for stop button local function displayStop() local StopButton = display.newImage("stop.png") StopButton.x = display.contentCenterX StopButton.y = display.contentCenterY StopButton.xScale = 0.5 StopButton.yScale = 0.5 function StopButton:touch (event) if ( event.phase == "ended" ) then print("#CS") local stopText = display.newText( "Stop", 160, -10, native.systemFontBold, 18 ) end return true end StopButton:addEventListener("touch", StopButton) end local myText = display.newText( "", 160, -10, native.systemFontBold, 18 ) local function addArrows( fullw, fullh, centerX, centerY, rotatione, command, code) local arrow = display.newImage("arrow.png") arrow.x = fullw arrow.y = fullh arrow.xScale = centerX arrow.yScale = centerY arrow.rotation = rotatione commande = command codee = code function arrow:touch (event) -- add the listener print("#" .. command) myText.text = code myText:setFillColour( 1, 0, 0) end return true end arrow:addEventListener("touch", arrow) end local fullh = {160, 230, 260, 230, 160, 90, 60, 90} local fullw = {140, 170, 240, 310, 340, 310, 240, 170} local centerX = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30} local centerY = {0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30, 0.30} local rotatione = {0, 45, 90, 135, 180, 225, 270, 315, 360} local command = {"Forward", "Right Forward", "Hard Right", "Right Backward", "Backward", "Left Backward", "Hard Left", "Left Forward"} local code = {CF, CRF, CHR, CRB, CB, CLB, CHL, CLF} for i = 1, #fullh do addArrows( fullh[i], fullw[i], centerX[i], centerY[i], rotatione[i], command[i], code[i] ) end displayStop()