Jump to content

Photo

Bounce! Grrr...


  • Please log in to reply
10 replies to this topic

#1 Linkus

Linkus

    .

  • Members
  • Real Name:Adam

Posted 03 March 2008 - 05:56 PM

CODE
import "std.zh"

ffc script dvdbounce{
    //Remember the episode "Launch Party" from the TV show The Office?
    //At the beginning, everyone was in the meeting room "listening"
    //to Michael's rant on qurater reports when they "reply" with a
    //groan? They were watching the bouncing box on the screen, hoping
    //it would hit one of the corners. This is where the script's idea  
    //came from, except with "plus" features.
    void run(){
        while(true){
            int x; int y;
            int cnt;
            this->X == x; this->Y == y;
            if(x == 0){
                this->Vx == 1;
            }
            if(x == 256){
                this->Vx == -1;
            }
            if(y == 0){
                this->Vy == 1;
            }
            if(y == 168){
                this->Vy == -1;
            }
            if(((x == 0) && (y == 0)) || ((x == 256) && (y == 0)) || ((x == 0) && (y == 168)) || ((x == 256) && (y == 168))){
                cnt + 1;
            }
        Waitframes(1);
        }
    }
}

most frustrating attempt to code a simple function ever. It's the if statements; the cnt thing isn't the cause of the problem. I just can't understand why the FFC's x and y positions aren't recognized, and thus it goes off screen...

Oh, and try to keep the code somewhat the same...

#2 Joe123

Joe123

    Retired

  • Members

Posted 03 March 2008 - 06:07 PM

Yes, the cnt thing is a problem.

CODE
cnt + 1;

is wrong.

You can't just say 'cnt +1'.

You mean this:
CODE
cnt += 1;


You need an assigment operator, you can't just say plus.


And another thing.
'=' <- 'Is set to'
'==' <- 'Is equal to'

CODE
this->Vx == 1; // this is wrong.
this->Vx = 1; //this is correct


http://www.shardstor...nment_operators
Assignment operators are what you need.


You also don't need 'Waitframes(1);', it's just 'Waitframe();'.


And the cnt thing doesn't do anything anyway icon_confused2.gif
Just gets incremented by one...

CODE

ffc script dvdbounce{
    void run(){
    this->X = Rand(240)+8; this->Y = Rand(130)+8;
    this->Vx = 1; this->Vy = 1;
    int x; int y;
        while(true){
            x = this->X; y = this->Y;
            if(x <= 0) this->Vx = 1;
            if(x >= 256) this->Vx = -1;
            if(y <= 0) this->Vy = 1;
            if(y >= 168) this->Vy = -1;
        Waitframe();
        }
    }
}

Edited by Joe123, 03 March 2008 - 06:11 PM.


#3 Linkus

Linkus

    .

  • Members
  • Real Name:Adam

Posted 03 March 2008 - 06:29 PM

Bah! It still won't work.

CODE
import "std.zh"

ffc script dvdbounce{
    //remember the episode "Launch Party" from the TV show The Office?
    //at the beginning, everyone wasin the meeting room "listening"
    //to Michael's rant on qurater reports when they "reply" with a
    //groan? They were watching the bouncing box on the screen, hoping
    //it would hit one of the corners. This is where the script's idea  
    //came from, except with "plus" features.
    void run(){
        while(true){
            float x; float y;
            int cnt;
            this->Vy = -1;
            this->Vx = 1;
            this->X == x; this->Y == y;
            if(x <= 0){
                this->Vx = 1;
            }
            if(x >= 256){
                this->Vx = -1;
            }
            if(y <= 0){
                this->Vy = 1;
            }
            if(y >= 168){
                this->Vy = -1;
            }
        Waitframe();
        }
    }
}


It's prone to keep going off the screen, and the Vx and Vy variables don't seem to recognize negative numbers; it just keeps going down and to the right.

#4 Joe123

Joe123

    Retired

  • Members

Posted 03 March 2008 - 06:46 PM

Did my script from the last post not work?
It should've done...

CODE
import "std.zh"

ffc script dvdbounce{
    void run(){
    // Please declare integers before the while loop, we don't want them declared every frame, thankyou.
    int x; int y; // (x,y) coordinates are never going to take on decimal values, so there's no need to make them floats.
              // remember though, ZScript's ints and floats are identical anyway, there are no true integers.
    int cnt; // what's this doing exactly?

    this->Vy = -1; // if you're going to set the speed of the ffc to go down and right every frame then obviously it will always
    this->Vx = 1;  // go down and right. Remember, whatever's within the while loop will occur every frame.
        while(true){
            x = this->X; y = this->Y; // =, not ==.
            if(x <= 0) this->Vx = 1; // no need for brackets if you only have one command within the if.
            if(x >= 256) this->Vx = -1;
            if(y <= 0) this->Vy = 1;
            if(y >= 168) this->Vy = -1;
        Waitframe();
        }
    }
}

Edited by Joe123, 04 March 2008 - 04:21 PM.


#5 Linkus

Linkus

    .

  • Members
  • Real Name:Adam

Posted 04 March 2008 - 03:57 PM

Still won't work. This might have to do with the this->Vx and this->Vy pointers, as it should change their velocity when it the reaches the screen's maximum and minimum x and y component.

For some reason, it just won't register negatives, but given that I work in 737, I wonder if it's a bug...

#6 LostInHyru1e

LostInHyru1e

    Can you take me as far as PureZC?

  • Members
  • Real Name:Lost
  • Location:Refer to Screename

Posted 04 March 2008 - 04:04 PM

Question: what do you plan to use this for?

#7 jman2050

jman2050

    Illustrious

  • Members

Posted 04 March 2008 - 04:19 PM

x= this->X not this->X = x

#8 Joe123

Joe123

    Retired

  • Members

Posted 04 March 2008 - 04:21 PM

Oops, I caught that the first time round but I missed it that time.

#9 Linkus

Linkus

    .

  • Members
  • Real Name:Adam

Posted 04 March 2008 - 05:18 PM

D'oh! That was indeed the problem. Works like a charm now, as for now I will go further into this.

As for the idea, it was just experimentation. Just something to try...

#10 jman2050

jman2050

    Illustrious

  • Members

Posted 04 March 2008 - 07:12 PM

You've done well. As with any sort of skill or knowledge, it's best to start small and grasp the basics. Concepts like the difference between an assignment (=) and a conditional (==) as well the as concept of variable assignment itself seems trivial to programmers, but we had to learn that too at first. Also, I guarantee you that this will not be the first time you mix up = and ==. Everyone says they won't do it, but it's an inevitability, so just accept it icon_wink.gif

#11 Linkus

Linkus

    .

  • Members
  • Real Name:Adam

Posted 04 March 2008 - 07:42 PM

Thanks for the support, jman. Now my next trick will be making an addition to an item I've had in mind for a while... It's an awesome update to a classic item. icon_wink.gif


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users