I'm pulling together a simple animation that shows some electrochemical concepts.
I've managed to get an "ion" moving around a simple electrochemical cell (anticlockwise flow) using some random movements with some bias to help "push" the ion in the right direction to simulate flow. Its not perfect and there are no doubt much simpler ways to do this, but my coding skills aren't up to it so I've hacked this together - please excuse the mess!
Anyway, I am trying to get the white "ion" to turn green when it hits the electrode (aka grey box) and stay green. I'm doing this by checking if the "ion" is within the bounds of the electrode, and also that the electrode is powered up (variable pwr=1). As far as I can see, it should work, but after literally hours trying to figure out why its not working, I'm close to giving up, and thought I'd see if I was missing a really obvious thing - as I say, I'm not a good coder, just muddle by!
Any help would be very much appreciated.
All the best,
PS: another problem that I've not fixed is the switching on/off of the power to the electrode. Should be done using a simple btn press, but for some reason this isn't working either. Again, any suggestions much appreciated. Thanks :-)
Your _update function has its end on line 119, which means the code that checks for button presses and for whether the electron is inside the electrode is outside of _update.
That's why it's important to have good indentation and to keep your code organized, it's not just form it's also function. I spent a good 5 minutes looking at your code, not understanding where it went wrong, and it's when I started indenting it properly so it would be easier to read that I immediately found the issue.
The good news is that once you move that end to its proper place, the rest of your code works great!
Thanks SO much Valkhiya!
Such a simple thing once you know what the problem is - I can see it so obviously now, and as you say, had I structured the code with indents (something I never do - tut tut!) I would have spotted it much more easily and saved myself a few hours! Lesson well and truly learnt!
Thanks for taking the time to review my code, and its great that the rest of my spaghetti works! Now I need to work out how to increase the number of electrons whizzing around! Should be simpler now I know one works :-)
Thanks again - very much appreciated.
All the best,
[Please log in to post a comment]