Out of segment space in Piece.move.3

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

Out of segment space in Piece.move.3

A_Random_Person

I am creating a tetris game and the function that moves a piece is going wrong (even though it perfectly makes sense. Here is the code for the function (p1-4 are the parts the piece consists of):

    /** Moves the piece one space down. */
    method void move() {
        do p3.move();
        do p4.move();
        do p2.move();
        do p1.move();
        return;
    }
    
And here is the code for Block.move() (p1-4 is a block):
    /** Moves block one space down. */
    method void move() {
        do clear();
        let y = y+16;
        do draw();
        return;
    }
    
Where clear() fills the block with white, y is the y position, and draw() draws the block. I don't see any errors. Can someone help? 😕

Reply | Threaded
Open this post in threaded view
|

Re: Out of segment space in Piece.move.3

A_Random_Person
This post was updated on .

And I just found out the buggy bit. In Piece.vm, function Piece.move:

    function Piece.move 0
    push argument 0
    pop pointer 0
    push this 5 ⬅The part that is erroneous
    call Block.move 1
    pop temp 0
    push this 6
    call Block.move 1
    pop temp 0
    push this 4
    call Block.move 1
    pop temp 0
    push this 3
    call Block.move 1
    pop temp 0
    push constant 0
    return
    
But I can't seem to find out why this part has problems. 😒

Reply | Threaded
Open this post in threaded view
|

Re: Out of segment space in Piece.move.3

ivant
Are you using the standard Jack to VM compiler or your own?
Reply | Threaded
Open this post in threaded view
|

Re: Out of segment space in Piece.move.3

WBahn
Administrator
In reply to this post by A_Random_Person
It's really hard to look for what is wrong unless you tell us what is happening that shouldn't be happening.

Is it going into an infinite loop and becoming nonresponsive?

Is it moving the piece to the wrong place?

Is the shape of the piece changing?

What???

One problem I can see is that if you aren't careful and doing the individual moves in the correct order, you could erase one of the other parts that has already been moved when you move a later part.

For instance, let's say that you have a part that looks like this:

P1
P2

If you move them in numerical order, you will erase P1 from its old location and then draw it at the new location (which overwrites the old P2 -- which is not a problem). But then when you move P2 you will erase it from its old location... which means that you will erase the new P1 since it's already been drawn at that location!
Reply | Threaded
Open this post in threaded view
|

Re: Out of segment space in Piece.move.3

A_Random_Person

I wrote the code it that particular order so that no blocks will be erased, And when I tried the move() function to get the correct order, it ran flawlessly. I can't understand why this is happening. It might be the part that calls the function. In case it is, I will copy it below:

let action = Keyboard.keyPressed();
let temp = Pieces[pieceIndex];
if (action = 130) {
    do temp.moveRight();
}
if (action = 132) {
    do temp.moveLeft();
}
if (action = 133) {
    do temp.move();
}
do Sys.wait(250);
do temp.move();
Is there anything wrong with this?

Reply | Threaded
Open this post in threaded view
|

Re: Out of segment space in Piece.move.3

A_Random_Person
In reply to this post by ivant

The Jack âž¡ VM compiler that was included in the download. I havn't gotten to the Compiler yet.

Reply | Threaded
Open this post in threaded view
|

Re: Out of segment space in Piece.move.3

A_Random_Person
In reply to this post by WBahn
And it moves it down.
Reply | Threaded
Open this post in threaded view
|

Re: Out of segment space in Piece.move.3

A_Random_Person
In reply to this post by A_Random_Person

Now I have even more "Out of segment space in ..." problems. I added the LFSR32Rand Random number generator and now it says "Out of segment space in LFSR32Rand.randBit.3". "Out of segment space in ..." is driving me CRAZY! 🤬🤬🤬

💣💨ARRRRRRRRRRGH!!! 👿