Coding problem

hi guys,
I’m trying to making my own game.

i’ve to do something like this

#include <Arduboy2.h>

Arduboy2 arduboy;

int selectedmenu = 0;
int menustate = 0;
bool inmenu = true;
int lbuffer = 0;
int rbuffer = 0;

void setup() {
  arduboy.begin();
  arduboy.setFrameRate(60);
  arduboy.bootLogoExtra();

}

void loop() {
  arduboy.clear();
  //**********************************//
  
  arduboy.drawCircle(64, 32, 30);
  
  if(menustate == 0){
  arduboy.setCursor(51 ,55);
  arduboy.print("start");
  arduboy.setCursor(53, 0);
  arduboy.print("info");
  }
  if(menustate == 1){ 
   arduboy.setCursor(51, 0);
   arduboy.print("start");
   arduboy.setCursor(53, 55);
   arduboy.print("info");
    }
if(arduboy.pressed(RIGHT_BUTTON) && rbuffer == 0 && menustate == 1) { menustate = 0; rbuffer = 1;}
if(arduboy.pressed(LEFT_BUTTON) && lbuffer == 0 && menustate == 0){ menustate = 0; lbuffer = 1;}

  
  if(!arduboy.notPressed(LEFT_BUTTON)) {
  lbuffer = 0;
  }
  if(arduboy.notPressed(RIGHT_BUTTON)) {
  rbuffer = 0;
  }
  
  //*********************************//
  arduboy.setCursor(0,0);
  arduboy.print(arduboy.cpuLoad());
  arduboy.display();
}

but it doesn’t work,
can someone help me to find the error please?

Are those underscores present in your original code or are you just using those to mark the start and end of your code?

If you want to put your code in a code block on the forums here then start and end it with ```(three ‘graves’).

When you say the code “doesn’t work” do you mean it doesn’t compile or it doesn’t do what you want it too?

If it’s not compiling, what is the compilation error?

If it doesn’t do what you want it to:

  • what is it doing?
  • what do you want it to do?
  • how is what it is doing different from what you want it to do?
1 Like

edited, thank you.

I mean that it doesn’t do what I want it do

invert the position of the two text ( info , start)

nothing only this part of code:

I think your main problem is with:

if(arduboy.pressed(RIGHT_BUTTON) && rbuffer == 0 && menustate == 1) { menustate = 0; rbuffer = 1;}
if(arduboy.pressed(LEFT_BUTTON) && lbuffer == 0 && menustate == 0){ menustate = 0; lbuffer = 1;}

It looks like the second one should be menustate = 1; instead of menustate = 0;


I also notice that there’s a small discrepency here:

  if(!arduboy.notPressed(LEFT_BUTTON)) {
  lbuffer = 0;
  }
  if(arduboy.notPressed(RIGHT_BUTTON)) {
  rbuffer = 0;
  }

The first one has a ! which inverts the result, meaning !arduboy.notPressed(LEFT_BUTTON) is the same as arduboy.pressed(LEFT_BUTTON).

thank you for the reply, now it works!

1 Like

:scream: I’ve been using 3x Tilde

~~~
Code
~~~

In my defence graves are hidden under a long key press on the IOS keyboard. Making it 2 presses and a swipe for each one.

1 Like

At least you know now, that’s the important thing.

The list of reasons I don’t like smartphones never stops growing it seems. :P

On a standard British keyboard layout the grave is to the left of the 1 key, above the tab.

It’s also a ¬ (a logical negation in certain mathematical logic systems) if you hold shift or a ¦ if you use alt-gr (a broken vertical bar, which is pretty useless. I’d rather it were an obelus.).

1 Like

I You do know that you can simply highlight the text and press either the quote or code button?

1 Like

Good tip, though it seems someone hasn’t had their breakfast yet. :P

Yeah … I did that on my phone (and I have fat fingers). And I have just revised history.

```cpp
```

will hint that you’re enclosing C++

```text
```

will hint that you’re enclosing plain text, so it won’t try to use syntax highlighting.

1 Like