编译时case 0出现Expected Expression错误的排查与修复
问题定位与修复方案
错误原因
编译提示case 0处Expected Expression错误,核心原因是case分支没有被包裹在switch代码块内,同时代码末尾存在多余的闭合括号,且函数声明后缺失代码块起始的{。case是switch语法的组成部分,必须紧跟switch(变量)声明才能被编译器识别。
修复后的完整代码
function changeDifficulty(change:Int = 0):Void { switch(change) { case 0: easy.loadGraphic(Paths.image('storymenu/easyglow')); normal.loadGraphic(Paths.image('storymenu/normal')); hard.loadGraphic(Paths.image('storymenu/hard')); FlxTween.tween(easy,{y: 286},0.1,{ease: FlxEase.expoInOut, onComplete: function(flxTween:FlxTween){}}); FlxTween.tween(normal,{y: 266},0.1,{ease: FlxEase.expoInOut, onComplete: function(flxTween:FlxTween){}}); FlxTween.tween(hard,{y: 266},0.1,{ease: FlxEase.expoInOut, onComplete: function(flxTween:FlxTween){}}); case 1: easy.loadGraphic(Paths.image('storymenu/easy')); normal.loadGraphic(Paths.image('storymenu/normalglow')); hard.loadGraphic(Paths.image('storymenu/hard')); FlxTween.tween(easy,{y: 266},0.1,{ease: FlxEase.expoInOut, onComplete: function(flxTween:FlxTween){}}); FlxTween.tween(normal,{y: 286},0.1,{ease: FlxEase.expoInOut, onComplete: function(flxTween:FlxTween){}}); FlxTween.tween(hard,{y: 266},0.1,{ease: FlxEase.expoInOut, onComplete: function(flxTween:FlxTween){}}); case 2: easy.loadGraphic(Paths.image('storymenu/easy')); normal.loadGraphic(Paths.image('storymenu/normal')); hard.loadGraphic(Paths.image('storymenu/hardglow')); FlxTween.tween(easy,{y: 266},0.1,{ease: FlxEase.expoInOut, onComplete: function(flxTween:FlxTween){}}); FlxTween.tween(normal,{y: 266},0.1,{ease: FlxEase.expoInOut, onComplete: function(flxTween:FlxTween){}}); FlxTween.tween(hard,{y: 286},0.1,{ease: FlxEase.expoInOut, onComplete: function(flxTween:FlxTween){}}); } }
关键修改点
- 新增
switch(change)语句,将所有case分支包裹在switch代码块内 - 补全函数声明后缺失的代码块起始
{ - 移除末尾多余的闭合括号
内容的提问来源于stack exchange,提问作者HollowFans
相关产品推荐
相关产品推荐

