Author |
Message |
Hunter007
![](http://server5.uploadit.org/files/Hunter007-antim.jpg)
|
Posted: Mon Jan 19, 2004 6:26 pm Post subject: Function |
|
|
I need to have an understanding of the "function" command (creates function) I have to explain it tommorow and I'm just not getting it-Any help would be greatly appreciated. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon Jan 19, 2004 6:38 pm Post subject: (No subject) |
|
|
function is a set of operations that return a value. The value is obtrained by ether calculating it from the parameters passed to it, or by fetching the value from else where (such as from a database).
basically function is like a procedure (techincally procedure is a void function) that returns a value. Just like in math really |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Mon Jan 19, 2004 6:42 pm Post subject: (No subject) |
|
|
think of a function as the black box
you shove something in
and something else comes out
you can shove multiple things in, but only onething comes out |
|
|
|
|
![](images/spacer.gif) |
Hunter007
![](http://server5.uploadit.org/files/Hunter007-antim.jpg)
|
Posted: Mon Jan 19, 2004 6:45 pm Post subject: (No subject) |
|
|
Ok thanks. One more question though. How does this part of my code relate to another if.
code: |
function collided (x1, x2, y1, y2, radius : int) : boolean
for xCheck : x1 - radius .. x1 + radius
if xCheck >= x2 - radius and xCheck <= x2 + radius then
for yCheck : y1 - radius .. y1 + radius
if yCheck >= y2 - radius and yCheck <= y2 + radius then
result (true)
end if
end for
end if
end for
result (false)
end collided
|
code: |
if collided (x1, x2, y1, y2, 20) then
tempx := dx1
tempy := dy1
dx1 := -dx1
dy1 := -dy1
dx1 := round (dx1 / 2 + dx2 / 2)
dy1 := round (dy1 / 2 + dy2 / 2)
dx2 := -dx2
dy2 := -dy2
dx2 := round (dx2 / 2 + tempx / 2)
dy2 := round (dy2 / 2 + tempy / 2)
count := count + 1
end if
|
I don't understand how if result is true in this case, it goes down to this if. By the way I want it to do that, I just don't understand how it was done. |
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Mon Jan 19, 2004 6:50 pm Post subject: (No subject) |
|
|
ur collided function returns true or false...
now if the ball has collided, it will become true so ur if statement becomes
if true=true then
tempx := dx1
tempy := dy1
dx1 := -dx1
dy1 := -dy1
dx1 := round (dx1 / 2 + dx2 / 2)
dy1 := round (dy1 / 2 + dy2 / 2)
dx2 := -dx2
dy2 := -dy2
dx2 := round (dx2 / 2 + tempx / 2)
dy2 := round (dy2 / 2 + tempy / 2)
count := count + 1
end if
now if the balls dont collide ur function will return false
and the if statement becomes
if false=true then
tempx := dx1
tempy := dy1
dx1 := -dx1
dy1 := -dy1
dx1 := round (dx1 / 2 + dx2 / 2)
dy1 := round (dy1 / 2 + dy2 / 2)
dx2 := -dx2
dy2 := -dy2
dx2 := round (dx2 / 2 + tempx / 2)
dy2 := round (dy2 / 2 + tempy / 2)
count := count + 1
end if
so the first time it will work and the second wont since false not=true |
|
|
|
|
![](images/spacer.gif) |
Hunter007
![](http://server5.uploadit.org/files/Hunter007-antim.jpg)
|
Posted: Mon Jan 19, 2004 7:21 pm Post subject: (No subject) |
|
|
OK in that last part of code if you just clarify something for me that would help a lot. Why does the "if" have "tempx" and "tempy"? Also what does dx1,dx1,dy1,dy2 do? I thought that was the speed of the ball, but it looks different when used here. |
|
|
|
|
![](images/spacer.gif) |
Andy
|
Posted: Mon Jan 19, 2004 7:33 pm Post subject: (No subject) |
|
|
it is the speed of the ball, but since ur bouncing off the other ball, the speed changes |
|
|
|
|
![](images/spacer.gif) |
Hunter007
![](http://server5.uploadit.org/files/Hunter007-antim.jpg)
|
Posted: Mon Jan 19, 2004 7:36 pm Post subject: (No subject) |
|
|
Sorry, but is that why tempx and tempy are used? Because when the balls hit the speed changes? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Andy
|
Posted: Mon Jan 19, 2004 7:38 pm Post subject: (No subject) |
|
|
since i have to change one variable at a time, tempx and tempy are used to store the values of the speed of ball one before the changes occured |
|
|
|
|
![](images/spacer.gif) |
|