Lvalue required as left operand of assignment

Hello everyone. I am working on a ssd1306 alien-blast style game and this is my code. I dont know why but everytime I try to check it, it says" lvalue required as left operand of assignment" Can somebody fix this please?

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
 int a1h = 0;
   int a2h = 0;
   int a3h = 0;
#define SCREEN_HEIGHT 64
#define SCREEN_WIDTH 128
#define OLED_RESET     -1 
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
float x = 9.13392857143;
#define imageWidth 15
#define imageHeight 16
int userx = 55;
int usery= 40;
int deathraytimer = 0;
int deathray = 0;
int deathrayx = userx;
const unsigned char bitmap2 [] PROGMEM=
{
0x8F, 0x73, 0xFD, 0xC1, 0xBF, 0x01, 0xFD, 0xF3, 0xFD, 0x01,
0xBF, 0xC1, 0xFD, 0x73, 0x8F, 0xFF, 0xFF, 0xFC, 0xF8, 0xF3,
0xE6, 0x80, 0x07, 0x80, 0xE6, 0xF3, 0xF8, 0xFC, 0xFF, 0xFF
};

const unsigned char bitmap [] PROGMEM=
{
0xFF, 0x7F, 0xBF, 0x5F, 0x5F, 0x6F, 0x27, 0xC1, 0x27, 0x6F,
0x5F, 0x5F, 0xBF, 0x7F, 0xFF, 0xFF, 0xFC, 0x03, 0xB7, 0xD6,
0xE1, 0x87, 0x6B, 0x87, 0xE1, 0xD6, 0xB7, 0x03, 0xFC, 0xFF
};
int a3x = random(0,113);
   int a1x = random(0,113);
   int a2x = random(0,113);
void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();


}

void loop() {
  display.clearDisplay();
  userx = analogRead(A6) / x;
  if(a3h=1){
  int a3x = random(0,113);
  }
  if(a1h=1){
   int a1x = random(0,113);
  }
  if(a2h=1){
   int a2x = random(0,113);
  }
   a1h = 0;
   a2h = 0;
   a3h = 0;
if(digitalRead(3)= HIGH, deathraytimer = 0){
  deathrayx = userx;
  deathraytimer = 100; 
  deathray = 1;
}
if(deathray = 1){
  display.drawLine(deathrayx +7,45,deathrayx +7, 0, WHITE );
  if(deathraytimer > 0){
    deathraytimer = deathraytimer - 1;
if (deathrayx + 7 = a1x){
  a1h = 1;
}
if (deathrayx + 7 = a2x){
  a2h = 1;
}
if (deathrayx + 7 = a3x){
  a3h = 1;
}
  }
  else(){
    deathray = 0;
  }
}
display.drawBitmap(userx, usery, bitmap, 15, 16);
display.drawBitmap(a1x, 0, bitmap2, 15, 16);
display.drawBitmap(a2x, 0, bitmap2, 15, 16);
display.drawBitmap(a3x, 0, bitmap2, 15, 16);
display.display();
delay(20);
}

First of all, post your code correctly, using the tags you should click on the toolbar under < code > .

All "ifs" are written wrong
all have 1 sign =
If equality comparison must have 2 signs ==.

Ex:
wrong if (deathrayx + 7 = a1x) {
right if (deathrayx + 7 == a1x) {

and
what is this ???

if (digitalRead(3) = HIGH, deathraytimer = 0) {

may be
if (digitalRead(3) == HIGH && deathraytimer == 0) { ?

and
wrong else() {
right else {

and.... so....

This will help you very much: You should start Arduino programming with the IDE >> EXAMPLES >> BUILT-IN >> sketches to help you understand how the code works before blasting aliens. You will have more fun writing code yourself than expecting others to fix broken internet finds for you.

Please edit your post, select all code and click the <CODE/> button; next save your post. This will apply code tags which makes your code easier to read, easier to copy and the forum software will handle it correctly.

Thanks for your answer, I am new at coding at I knew I had mistakes.

Done.

1 Like

I didnt know about that, thanks for your help.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.