how do i fix expected error on a case when compiling

53 Views Asked by At

Where did I go wrong with this code? I've done lots of changes but it just seems to give the same error all over and over again :/

    function changeDifficulty(change:Int = 0):Void
     
            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){}});
        }
    }

The error said the expected expression error was on the case 0

Can't seem to tell where is the problem

1

There are 1 best solutions below

0
On

It is missing the switch statement and curly braces - maybe a copy-paste typo? See the docs for the switch expression.

I'm guessing the top of your function should look something like:

function changeDifficulty(change:Int = 0):Void { 
     switch change {
            case 0:
            // ...snip...
     }
}