This site requires JavaScript, please enable it in your browser!
Greenfoot back
Duta
Duta wrote ...

2011/9/27

Crash issue?

1
2
brian brian

2011/9/27

#
Arrrggghhh... I hate intermittent errors. It does appear that every so often the wrong counter is updated. I have only ever seen it happen when the ball is going off the left hand side though - has it happened the other way round to you? So why is this happening. It appears that your first counter is overlapping your second so that when you call getObjectsAt (310, 15, Counter.class) it returns two items in the list and every so often the items are in a different order so the wrong counter gets updated. A quick fix seems to be to change that piece of code to getObjectAt(340, 15, Counter.class).get(0); This should work because only the second counter is found that far along the screen so the list only contains the correct counter. See if that fixes the error for you. The better fix would appear to be to re-write your counter class so that the one object deals with both scores and you call methods on it like addToLeftScore etc. This way there can't be any confusion about which counter you are adding to! I'm fairly certain either fix will work but obviously the first one is a lot quicker to implement - just remember to change the numbers for every other call of getObjectAt.
brian brian

2011/9/27

#
Glad you fixed it yourself... still not sure I was seeing the same problem as you! Anyway after all this I really want to see this when it is finished... make sure you upload it!
Duta Duta

2011/9/27

#
Haha yeah :D I've uploaded one that... well it works. I've got a lot of good stuff to add to it, but that can wait for tomorrow :) http://www.greenfoot.org/scenarios/3553
Duta Duta

2011/9/27

#
Thanks again. Happy that I've been able to do this as I'm only just starting my fourth week at sixth form college, at which I'm doing (among several subjects) higher level computer science... so yeah I'm very new :)
brian wrote...
Arrrggghhh... I hate intermittent errors. It does appear that every so often the wrong counter is updated. I have only ever seen it happen when the ball is going off the left hand side though - has it happened the other way round to you? So why is this happening. It appears that your first counter is overlapping your second so that when you call getObjectsAt (310, 15, Counter.class) it returns two items in the list and every so often the items are in a different order so the wrong counter gets updated. A quick fix seems to be to change that piece of code to getObjectAt(340, 15, Counter.class).get(0); This should work because only the second counter is found that far along the screen so the list only contains the correct counter. See if that fixes the error for you. The better fix would appear to be to re-write your counter class so that the one object deals with both scores and you call methods on it like addToLeftScore etc. This way there can't be any confusion about which counter you are adding to! I'm fairly certain either fix will work but obviously the first one is a lot quicker to implement - just remember to change the numbers for every other call of getObjectAt.
Also, sadly the fix where you change it from 310 to 340 didn't work and caused an error upon running.... oh well I've got it fixed up so it doesn't matter :) EDIT: I've fixed the counter error.
You need to login to post a reply.
1
2