So, I program for the arduboy very casually. I mostly just play games on it and sometimes make code that generates patterns, or something else thats super basic. This time I wanted to try finishing an actual project for the thing. As I’m working on it yesterday it started acting odd. The arduboy would restart roughly every 12 seconds.
In addition, I can’t upload anything else to it.
using different cables
Kevin’s restart tutorial
uninstalling and reinstalling drivers
uninstalling and reinstalling arduino
The code that I have (And what presumibly started all this) manipulates a couple of large arrays of objects.
The issue started when I tried to move a bit of code from the maingame() to its own function, placeunit()
any ideas? Also, let me know if I’m getting terminology wrong, or if there’s something I can do to better with my program. I’m still learning.
I find when I get in this state, it usually means I’ve written to memory I didn’t mean to, like beyond the end of an array. What happens when you do that just depends on what that memory is being used for. Sometimes nothing major happens, and sometimes the Arduboy crashes.
If you run your app in the emulator, you’ll likely see the emulator crash. If so, it is likely a similar issue.
city41 I’ll give the emulator a shot once I get a chance to sit down at my comp again. do you have a link to one?
Thank you guys for the quick response. I had to go to work so I’m not able to give the specific error code, but it says that an error occurred whenever I try to upload new code. Whether its mine or someone else’s.
When you’re iterating through AllyUnits, you’re checking for x <= UNIT_COUNT instead of x < UNIT_COUNT.
Arrays are 0-based.
A 25 element array has indices running from 0 to 24.
I.e. 25 is an invalid index.
(Also UNIT_COUNT should be const or constexpr.)
The moral of this story is:
put warnings on verbose, read the warnings, try to eliminate all warnings, they’re usually bugs.
(There’s a number of other issues with the code, but none that I can see that are actual bugs,
mainly redundancy and stylistic issues, like using and instead of && and using == true.)
Do you mind if I ask, have you been learning mainly from looking at crait and filmote’s code and/or tutorials?
Also, I played around with the code for a bit and managed to cut it down to around 10454 bytes (36%) of program storage space and 1828 bytes (71%) of dynamic memory, but then I realised you haven’t put a licence on it, just a copyright notice, so I can’t publish my edits.
I didn’t realize I wasn’t use verbose, I will in the future. I was planning on cleaning things up after I had some semblence of a working project. but I see now thats probably is not the best way to go about it.
I’ve read Crait’s tutorials, but I haven’t seen filmotes.The bulk of what I know comes from my background in java that I learned back in college.
I’m guessing that’s where you learnt about and, or, == true, == false and possibly byte and boolean and the outdated ‘button buffer’ technique?
Typically && and || are used instead of and and or (like in Java).
if(x == true) is redundant because x == true evaluates to just x so you can use if(x) instead, as in if(arduboy.justPressed(A_BUTTON)).
Likewise if(x == false) is redundant because it evaluates to !x, so you can use if(!x) instead, as in if(!arduboy.nextFrame()).
(Again, this is the same in Java.)
byte and boolean are Arduino-specific types that aren’t available in a non-Arduino environment.
It’s better to get used to using uint8_t and bool. bool is a fundamental type, while uint8_t comes from a library, but that library is standardised.
As for the ‘button buffer’ technique, that’s just an archaism from the days when the original Arduboy library didn’t have justPressed, but now most people use Arduboy2, which does have justPressed (and justReleased).
No, but you do have a habit of using x instead of i in your for loops. (e.g. here and here.)
@Nolan_Maxwell_Gams and you are the only people I’ve ever seen do that (when the thing being manipulated doesn’t actually involve x and y coordinates).
That’s one of the many changes I made on my local copy.
if you do decide to licence your code then I’ll show you the rewrites I did so you can decide if you’re interested in any of them (and if you are, I’d be happy to explain the rationale behind them).
The copywrite notice is just a holdover from one of my old professors. The same goes for using ‘x’. I’ve just been doing it outta habit, I would love to see your changes! How would i go about that? Just getting rid of the comment at the top?
Thank you for your time, and I’m sorry I’m so slow to respond. I’ve been way busier than I thought I would be this weekend.
It’s a little bit more complicated than that to licence code.
Adding a licence is easy, but picking one can be difficult,
it depends what you want to allow people to do with it.
Most people who publish Arduboy games pick either MIT, Apache 2.0 or BSD 3-clause.
All of them allow people to copy and modify your code as long as they retain the licence and copyright notice, and all of them state that your code has no warranty (which is standard for almost all licences).
Apache 2.0 requires people to document the fact the code is modified if they modify it.
BSD 3C explicitly prevents people from using the names of any contributors to the code to promote any modified versions of the code (though this is probably implicit in most countries).
MIT doesn’t have either of those restrictions.
There’s lots of other licences that have different levels of restriction, but those three are the most popular.
The only licence I’d advise against is the GPL because it prevents people from mixing your code into theirs unless they publish their code under the same licence.
With the other ones, people are free to take bits and pieces of your code if they keep the licence notice to indicate that part of their code is licenced differently.
Whatever you decide to do, any licence is usually better than no licence, because not having a licence implies that other people can’t actually do anything with the code other than look at it.
Strictly speaking, most people who don’t use a licence aren’t likely to try to take legal action against someone who does use their code,
but using a licence makes it clear to people what is and what isn’t allowed and gives people assurance that you won’t change your mind about it later.
Sorry if that’s a lot to take in.
There’s no rush, I understand that a lot of people have commitments.
I won’t get bored waiting, I have plenty to do myself.
Besides which, as long as my opinion is valued, I’m always happy to help people.
The i habit or the x habit?
I must admit, I sometimes try to use index instead if I want to be particularly well documenting.
Fortran had a nasty feature called ‘implicit typing’ where you didn’t have to declare variables before use. If you didn’t declare them, the compiler assumed anything starting with and i, j, k, l, m or n was an integer - the rest were considered to be real.
So, I managed to unfutz my Arduboy. I transferred the ‘hello world’ example code, while the arduboy was in flashlight mode. This made the screen bug out. but after that, I was able to upload another game with no problems.
I looked through the licenses, and I’m going to go with the MIT license. Would It be better if I made a new thread in Games or continue the conversation here?