Hey all!

I just posted what i’ve been working on not too long ago.

http://maven.smith.edu/~220b-ae/Site/projecttwo.html

I’m kind of having trouble though, I’m trying to get the user to input a number from 1 through 9 and have those spheres show up on the screen. But im gettng an array Index out of bounds error which means im probably adding more things into an array that i havent defined the length to.

I have an array of springs that i define as ‘ Spring[] springs; ‘ but i dont give it a length until the user has pressed a number value. I fixed the ascii numbering so i know im working with numbers instead of ascii values, but its still giving me this error. Can anyone help me out? thanks =)

EDIT: another problem i ran into. I want the user to be able to set the velocity for the spheres. But when i press the specific key button (a for lower and s for higher) it resets it self to where it started initially…and i dont want that ='( I want it to continue ‘springing’ around with a slower or faster K. If i can get help with this i can get a lot of other things cleared up like shape size and stuff. thanks again =)

Advertisements

~ by christineg on March 10, 2008.

One Response to “”

  1. The out of bounds error is being thrown by the lines

    for (int gen = 0; gen < num+1; gen++) {
    springs[number] = new Spring(random(550), random(550), 30, velocity, 8.0, 0.1, springs, 0);
    number += 1;

    in keyPressed

    You are create a Spring array of size num but try to assign num+1 springs to it.

    As for your 2nd problem – it looks like you are creating a new spring instead of accessing the existing spring and adjusting K. The new spring is what is causing the “reset”

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: