Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
So many errors D:
Old
AliceAppreciationSociety
Guest
 
Status:
Posts: n/a
Default So many errors D: - 11-29-2013, 09:11 AM

Hey guys,

We as the Alice Appreciation Society where set a task in university to make a game on Alice with a two week deadline. We came up with a zombie FPS however we started to get some bugs with the ending screen.

We've used a decrement operator within a loop to reduce player lives when the proximity of an enemy is within 2 metres of the player. However, once the lives reaches 0, the game displays a bug. It states:

Code:
Error during simulation.

Throwable that caused the error:

java.lang.ArrayIndexOutOfBoundsException: -1 not in range [0,5)

We have an array for our enemies (six zombies). Something is wrong with the way we have implemented this array into the game. If anybody could take a look at this soon and offer some suggestions, we'd be eternally grateful.


Kindest regards,

~AAS
Attached Files
File Type: a2w zombies28NovemberCommented.a2w (4.46 MB, 2 views)

Last edited by AliceAppreciationSociety; 11-29-2013 at 03:15 PM.
   
Reply With Quote
Didn't crash for me
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default Didn't crash for me - 11-30-2013, 09:32 AM

But-

That kind of error indicates that your program went out of range when dealing with arrays. When using parallel arrays for things like your zombies, all relevant arrays should be the same length, or problems can occur.
Also cross-check all logic that decrements array pointers to make sure that you don't accidently slip past zero.
   
Reply With Quote
Solution and a couple of suggestions
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default Solution and a couple of suggestions - 12-13-2013, 12:56 PM

The problem is in the zombieXai methods. You step through each zombie using indexes and comparing zombie to zombie+1. This works fine until you get to either an empty item in the list (item 6 = none) or you get to the last item where you are trying to compare the last zombie to the last zombie +1, which doesn't exist.

Usually either you would not use the last element or you would compare it to the first one at index zero. The index 0 alternative involves using modular arithmetic which is not directly available in Alice but can be simulated.

The major suggestion I would make is to get rid of your zombie ids and different methods and events for each zombie and use the list functions.
In a mouse clicked event you can call a method and pass it the "object under the cursor" then use this object to each one in the list until you find the matching one. Also you can get rid of zombieMaximum by using the length of the list if you need to know the number of items in the zombie list. WARNING: remove item 6 from you list, or make it a zombie.
Finally, you can get rid of the zombiesAlive list. This can be done by simply removing dead zombies from the list and checking for a length of 0.

So you would be going for something like:

Code:
event 
if the mouse is clicked on anything call zombieAi with the item under the cursor.

ZombieAI  curZombie

  For all in zombieArray one zombie at a time
    if(curZombie == zombie) then
      do your stuff here.
    else
      do nothing


Mark Henwood
mhenwood@ieee.org
   
Reply With Quote
Adivce
Old
clk4suport
Junior Member
 
Status: Offline
Posts: 12
Join Date: Nov 2013
Location: new delhi
Smile Adivce - 01-02-2014, 01:17 AM

Hello,

As per me, you have concern your problem with some expert in particular field.
Because it requires expert attention.

Thank You.
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2019, Carnegie Mellon University
Alice 2.x 1999-2012, Alice 3.x 2008-2012, Carnegie Mellon University. All rights reserved.