• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker Wrong switch statement

S

SuG4Ru

Guest
Ok i have problem with this. My switch statement make fatal error at line 20 and in line 29 i think same issue.Please little help with this.

Code:
//variables

kspace   = keyboard_check ( vk_space ) ;
attackspeed = 3 ;
dire   = 0  ;

//code for attack move

enum dir
    {
    maxx,
    minn,
    }

current_dir = dir.maxx ;

switch (current_dir)
    {
    case dir.maxx :    // it say here is problem ----line 20
        {
        if direction >= 50
            {
            dire = - attackspeed ;
            }
        } 
        ;break;
     
    case dir.minn :   // here is problem too i think if problem ot dir.maxx  --- line 29
        {
        if direction <=0
            {
            dire = + attackspeed ;
            }
        }
        ;break;
    }




if kspace
    {
    image_angle = direction -50 + obj_player_player1.image_angle + 0;   // this is code for rotation by the attack speed
    direction = dire ;
    }
else if !kspace
    {
    image_angle = -50 + obj_player_player1.image_angle + 0;
    direction = 0 ;
    }
For short this code for moving animation with sword without picture animation just with one picture and code.
Or if you have difrent way how to code moving between 0° and 50° and from 50° to 0° and retry this motion. Pls help with this.. Thank you for read and answere.
Ok i edit main code now game start, but didnt work this switch statement.
How i do case 1 work if direction is 50° or more [direction >= 50] change the attackspeed from possitive to negative and in case 2 if direction 0° [direction <= 0 ] change againg from negative attackspeed to positive [case 1].

O
 
Last edited by a moderator:

breakmt

Member
I think problem is in "switch (dir)" line. You should use variable for this operation not enum itself.
For example:
Code:
enum dir
    {
    maxx,
    minn,
    }

current_dir = dir.maxx;

switch (current_dir)
    {
    case dir.maxx :    // it say here is problem ----line 20
        {
        if direction >= 50
            {
            dire = - attackspeed ;
            }
        }
        ;break;
     
    case dir.minn :   // here is problem too i think if problem ot dir.maxx  --- line 29
        {
        if direction <=0
            {
            dire = + attackspeed ;
            }
        }
        ;break;
    }
 
S

SuG4Ru

Guest
Ok now run the game but didnt work at all no move when press space. But game start and no fatal error. Ok can someone help fix this ??
 

Hyomoto

Member
You need to post the actual error you get verbatim, that information is vital to understanding crashes. Without it there's no point in guessing.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Please make it easier for our members to help you by posting full contextual information any time you create a topic or post a reply. Without this information, it can be incredibly cumbersome if not impossible to provide accurate help. Help us help you.

For future reference: How to Q&A
 
Top