Arrays and Math classes

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Arrays and Math classes

Adam
Hello,
Where can I find the Interface\API for Math and Array classes? I have some methods I would like to use but don't know how they are called.

On another issue I seem to be running out of segment space while attempting to do the following

someArray[0] = someInt;

Are arrays not zero based? I printed someInt just to make sure that it's not that.
Reply | Threaded
Open this post in threaded view
|

Re: Arrays and Math classes

ybakos
They're in the book. (A highly recommended purchase, if possible.)
Reply | Threaded
Open this post in threaded view
|

Re: Arrays and Math classes

cadet1620
Administrator
In reply to this post by Adam
Adam wrote
Hello,
Where can I find the Interface\API for Math and Array classes? I have some methods I would like to use but don't know how they are called.

On another issue I seem to be running out of segment space while attempting to do the following

someArray[0] = someInt;

Are arrays not zero based? I printed someInt just to make sure that it's not that.
There are skeleton .jack files in project 12 that include the interface for the OS .vm files, albeit with minimal documentation.

Did you create the someArray object before trying to use it? Otherwise its this pointer is 0.
    someArray = Array.new(size);

You will want the book if you are planning to do the remaining software chapters.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Arrays and Math classes

Adam
This post was updated on .
I did initialize the array.
in the constructor I have:
let someArray = Array.new(ARRAY_SIZE);

I am currently building a snake game. and I need to handle arrays as the snake moves.
I wrote a method shifting right the array cells and adding to the array at cell 0.
That method works just fine.
I also have a method that returns the head of the array i.e. value at cell 0.
The getter method has the following command:
return someArray[0];

This call happens after the array was handled so there is no problem with the array itself.
But I still get a segment exception. Even though I know for a fact the array is initialized in scope and holds values.
Why would this happen? I have spent a few days now trying to understand it. There seems to be nothing wrong and no object has been deallocated. It seems that every time I try to pass the contents of someArray[0] between my classes I get a segment exception...

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Arrays and Math classes

cadet1620
Administrator
Nothing obviously wrong. It still feels like the getter is being called with a null pointer. Check that it is being called as a method. It's easy to forget that Jack doesn't automatically use method semantics when calling between an class's methods.

If you want to, you may send me your program and I can take a look at it.

--Mark