2017-09-27 33 views
0

這是我的代碼:語法錯誤「‘=’預計近期「_APPNAME」無厘頭

main.lua:

-- start the app, declare some variables, setup the player save file. 

-- APP OPTIONS 
_APPNAME = "The Square Cannon" 
_FONT = "Tolo" 

-- OTHER UPGRADES 

_SHOWADS = TRUE 

-- CONSTANT VALUES 
_CX = display.contentWidth*0.5 --center of the screeen going horizontally 
_CY = display.contentHeight*0.5 --center of the screem going vertically 
_CW = display.contentWidth -- width of the screen 
_CH = display.contentHeight -- height of the screen 
_T = display.screenOriginY -- top of the screen 
_L = display.screenOriginX -- left of the screen 
_R = display.viewableContentWidth - _L -- right of the screen 
_B = display.viewableContentHeight - _T -- bottom of the screen 

-- hide the status bar 
display.setStatusBar(display.HiddenStatusBar) 

-- include composer 
local composer = require "composer" 

-- include load/save library from coronarob 
loadsave = require("loadsave") 

-- load some audio 
_BACKGROUNDMUSIC = audio.loadStream("THESQUARECANNON\audio\IceFLow" , "THESQUARECANNON\audio\FreeInstrumental") 
--{ 
    --load some sound effects, when created 
--} 

-- set up a saved file for our user 
user = loadsave.loadTable("user.json") 
if (user == nil) then 
    user = {} 
    user.playsound = true 
    loadsave.saveTable(user, "user.json") 
end 

composer.gotoScene("scene_menu") 

,這是我的錯誤得到:

main.lua:5: '=' expected near "'_APPNAME'" 

什麼可能是錯的?我有一個=正好在需要的位置,儘管控制檯仍然說我需要一個。

+0

「config.lua」,「main.lua」和「scene_menu.lua」是三個單獨的文件嗎?我假設從這些文件名中的兩個錯誤消息來判斷。鑑於您對代碼進行格式化的方式,這並不完全清楚。我會爲你編輯它;如果它不正確,請隨時恢復我的編輯。 –

+0

我的編輯可能會拋出一些行號。 ''表示文件結束。如果我刪除'config.lua'中的尾隨逗號,''錯誤附近的'意外符號消失。 –

+0

對於'config.lua'錯誤,在最後一次關閉'}'之後擺脫逗號,並且應該擺脫您的錯誤。不確定只要'main.lua'代碼去;它對我來說很合適。你有沒有發佈文件的所有內容? – DavisDude

回答

0

你有沒有顯示的代碼?我計算了3個左括號和只有2個右括號。 你有另一個錯字。

_CX = display.contentWIdth*0.5 - 

應該是

_CX = display.contentWidth*0.5 - 
+0

是的,我喜歡,但是他們在其他班級,我相信他們是特別不相關的。我只是把另一個右括號,它似乎並沒有解決任何問題 –

+0

@CameronLee:這是非常相關的。您向我們展示的代碼無效。如果您說您向我們展示的代碼中的錯誤不是問題,那麼它必須存在於您未向我們展示的代碼中。請用[mcve]更新你的問題。 –

0

即錯誤消息是由於config.lua在文件中的存在。

config.lua更改爲-- config.lua會給您不同的消息,因爲括號不平衡。

+0

我只是把config.lua作爲一個文件名,但是我按照你的說法做了,並且收到一個新的錯誤:「config.lua:14:''附近的意外符號'」,其中14將是新的第三個右括號。 –