Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Function
Author Message
Hunter007

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.
Sponsor
Sponsor

Tony

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.
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
Hunter007

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.
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
Hunter007

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.
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
Hunter007

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?
Sponsor
Sponsor

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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 9 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: