There are a few issues with your code:
First of all, this isn't really an issue but more like bad habit which can lead to seemingly random errors:
- Code: Select all
if (chain <= 69)
chance = chain / 4096;
if (chain >= 70)
chance = chain / 1024;
if (chain >= 256)
chain = 1;
In this block, while this would work as it are all one-line if conditions, it is still recommended to add the curly brackets as else, when adding another line and you forget adding the curly brackets, the code does unexpected things.
So it would look like this:
- Code: Select all
if (chain <= 69) {
chance = chain / 4096;
}
if (chain >= 70) {
chance = chain / 1024;
}
if (chain >= 256){
chain = 1;
}
Second of all, you defined your variable 'chance' as an integer (Keyword
int), however due to the context it seems like you actually want a floating point number (Keyword
float), as it seems like you want to store the probability between 0 and 1 in it. An integer is only a whole number, so like 0,1,2,3 etc,
So instead of
- Code: Select all
int chance = 0;
you'd do
- Code: Select all
float chance = 0;
There is another thing to take into consideration here: You are deviding integers with one another, meaning that you are performing integer devision. So like 2/4 will actually return 0 instead of 0.5 as those are both integers, and thus the result is floored (everything after the comma is simply cut off).
To overgo this you'd replace lines such as
- Code: Select all
chance = chain / 4096;
with
- Code: Select all
chance = chain / 4096.0;
Here I force one of the arguments to be a floating point number, due to the value being 4096.0 rather than 4096, and thus floating point devision is performed.
Now let's get to your syntax error (at least from what I could spot, if it still doesn't compile please copypaste us the error output :3 )
- Code: Select all
gb.display.println(F("Chain Length:")Serial.print(fchain))
gb.display.println(F("Chance of Shiny:")Serial.print(chance))
I am not sure what you were trying to do here, were you trying to gb.display.println or were you trying to do Serial.print ?
If you were trying to do gb.display.println:
- Code: Select all
gb.display.print(F("Chain Length:"));
gb.display.println(fchain);
gb.display.print(F("Chance of Shiny:"));
gb.display.println(chance);
If you wanted to do Serial.print then substitude accordingly.
Then there is also this block:
- Code: Select all
if (gb.buttons.pressed(BTN_A)) {
chain = chain + 1
}
if (gb.buttons.pressed(BTN_B)) {
chain = chain - 1
}
It simply lacks semi-columns:
- Code: Select all
if (gb.buttons.pressed(BTN_A)) {
chain = chain + 1;
}
if (gb.buttons.pressed(BTN_B)) {
chain = chain - 1;
}
There are also shorthands for increasing and decreasing numbers:
- Code: Select all
if (gb.buttons.pressed(BTN_A)) {
chain++;
}
if (gb.buttons.pressed(BTN_B)) {
chain--;
}
Whew, this post got long, I hope I could help!