Skip to main content
added 31 characters in body
Source Link
Tanner H.
  • 111
  • 1
  • 4

Okay so I am making a tower defense game in GML and I came across a small problem when making a switch statement, I want to have anything from 1-10 to result in a variable changing to 1, anything from 11-20 result in the variable changing to 2, and anything 21-30 to change to 3. It would look something like this. Yes I know I'm new to coding..

switch(test)
{
    case (1-10):
        test = 1;
        break;

    case (11-20):
        test = 2;
        break;

    case (21-30):
        test = 3;
        break;
}

Except for the fact that that does not work and to actually do something like that, in my knowledge you'd have to make a case for every single number in the range which would take ~3 years. Help?

Okay so I am making a tower defense game in GML and I came across a small problem when making a switch statement, I want to have anything from 1-10 to result in a variable changing to 1, anything from 11-20 result in the variable changing to 2, and anything 21-30 to change to 3. It would look something like this.

switch(test)
{
    case (1-10):
        test = 1;
        break;

    case (11-20):
        test = 2;
        break;

    case (21-30):
        test = 3;
        break;
}

Except for the fact that that does not work and to actually do something like that, in my knowledge you'd have to make a case for every single number in the range which would take ~3 years. Help?

Okay so I am making a tower defense game in GML and I came across a small problem when making a switch statement, I want to have anything from 1-10 to result in a variable changing to 1, anything from 11-20 result in the variable changing to 2, and anything 21-30 to change to 3. It would look something like this. Yes I know I'm new to coding..

switch(test)
{
    case (1-10):
        test = 1;
        break;

    case (11-20):
        test = 2;
        break;

    case (21-30):
        test = 3;
        break;
}

Except for the fact that that does not work and to actually do something like that, in my knowledge you'd have to make a case for every single number in the range which would take ~3 years. Help?

Source Link
Tanner H.
  • 111
  • 1
  • 4

Is there a way to set a range on a case argument in a switch statement in Game Maker: Studio?

Okay so I am making a tower defense game in GML and I came across a small problem when making a switch statement, I want to have anything from 1-10 to result in a variable changing to 1, anything from 11-20 result in the variable changing to 2, and anything 21-30 to change to 3. It would look something like this.

switch(test)
{
    case (1-10):
        test = 1;
        break;

    case (11-20):
        test = 2;
        break;

    case (21-30):
        test = 3;
        break;
}

Except for the fact that that does not work and to actually do something like that, in my knowledge you'd have to make a case for every single number in the range which would take ~3 years. Help?