0

I am coding in Gamemaker Studio 2 and this is my code:

if selected {
value = clamp((mouse_x-x)/sprite_width, 0, max_value);
}
if value < 0 and value >= 0.1 {
    avLevels = 1
} else {
    if value < 0.1 and value >= 0.2 {
        avLevels = 2
    } else {
        if value < 0.2 and value >= 0.3 {
            avLevels = 3
        } else {
            if value < 0.3 and value >= 0.4 {
                avLevels = 4
            } else {
                if value < 0.4 and value >= 0.5 {
                    avLevels = 5
                } else {
                    if value < 0.5 and value >= 0.6 {
                        avLevels = 6
                    } else {
                        if value < 0.6 and value >= 0.7 {
                            avLevels = 7
                        } else {
                            if value < 0.7 and value >= 0.8 {
                                avLevels = 8
                            } else {
                                if value < 0.8 and value >= 0.9 {
                                    avLevels = 9
                                } else {
                                    if value < 0.9 and value >= 1 {
                                        avLevels = 10
                                    } else {
                                        return
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

}

And on the last line (the last curly bracket) there is a "malformed assignment" syntax error. Does anyone know what this is and how I deal with it?

Anonymous
  • 31
  • 3
  • 1
    side note: `value < 0 and value >= 0.1 ` - what value should be in variable `value` to make this condition true? – Iłya Bursov Sep 03 '22 at 03:06
  • it is a slider that I am getting a decimal from the position of – Anonymous Sep 03 '22 at 03:07
  • 1
    I'm not familiar with this language, but I was curious and checked out the [documentation](https://manual.yoyogames.com/GameMaker_Language/GML_Overview/Basic_Code_Structure.htm), and it looks like you're missing semicolons, like `avLevels = 1;` – wjandrea Sep 03 '22 at 03:07
  • 1
    This entire block of code could be replaced with something like `avLevels = ceil(value*10);`. Watch your edge cases for 0 and 1. – Tangentially Perpendicular Sep 03 '22 at 04:27

1 Answers1

2

I think the last curly bracket isn't necessary, as it's not assigned with another curly bracket. (The formatting already shows that the curly bracket is out of place, and pasting the code in notepad shows that the curly bracket is not connected.)

However, I think your code block is also unnecessary complicated, as it has a lot of repeating code (that you'll also need to repeat for each level).

It also looks like your code is looking if the value is smaller than the smallest number, and higher than the highest number. Instead of, presumingly, the value inbetween.

Like Tangentially Perpendicular mentioned, you can summarise the whole if-statement nesting with a single line of code using ceil() (Which lets you round the number to upper).

avLevels = ceil(value*10);
Steven
  • 1,996
  • 3
  • 22
  • 33