Computer Science Canada Understanding parameter pass.. |
Author: | basketball4ever [ Wed Jan 19, 2005 9:47 pm ] | ||
Post subject: | Understanding parameter pass.. | ||
K... so in my code, i want whatever applies to player 1, apply to players 2,3, and 4 (aka: i'm doing snakes and ladders. thus, whatever happens to player 1, can also happen to player 2... like going up a snake or going down a snake.. or the position at which they're at:
See how whatever i had to do for pos1 i had to do for pos2 and pos3 and pos 4 also... is there a way i can simplify this to make 400 lines into 100 ![]() |
Author: | cycro1234 [ Wed Jan 19, 2005 9:54 pm ] |
Post subject: | |
Well, since the rules may apply to more than one player, why don't you use AND in your if statements. Also, why don't you have any elsifs in ur code? |
Author: | Bacchus [ Wed Jan 19, 2005 9:55 pm ] |
Post subject: | |
use arrays and fors |
Author: | eNc [ Wed Jan 19, 2005 9:59 pm ] |
Post subject: | Re: Understanding parameter pass.. |
Do you know how to use a case statement ? This may help you out a bit, also you can try setting a variable to the delay number so that you don't have to type as much, just some thoughts |
Author: | cycro1234 [ Wed Jan 19, 2005 10:05 pm ] |
Post subject: | |
Here's an example: var mark : int put "Enter a mark from 1 - 10: " .. get mark case mark of label 9, 10 : put "Excellent" label 7, 8 : put "Good" label 6 : put "Fair" label : put "Poor" end case as opposed to: var mark : int put "Enter a mark from 1 - 10: " .. get mark if mark = 9 or mark = 10 then put "Excellent" elsif mark = 7 or mark = 8 then put "Good" etc. etc. [/code] |
Author: | basketball4ever [ Wed Jan 19, 2005 10:15 pm ] |
Post subject: | |
Quote: Well, since the rules may apply to more than one player, why don't you use AND in your if statements. Also, why don't you have any elsifs in ur code?
Lol well i'm waiting for my whole thing to be simplified first. ![]() |
Author: | cycro1234 [ Wed Jan 19, 2005 10:18 pm ] |
Post subject: | |
And what, might I ask, is a parameter pass??? |
Author: | basketball4ever [ Wed Jan 19, 2005 10:19 pm ] |
Post subject: | |
parameter pass = proc cycro (var:n:int) something like that :S ionno ms.**** said to use it : P |
Author: | Neo [ Wed Jan 19, 2005 10:30 pm ] | ||||
Post subject: | |||||
First setup your variables into an array, then you can make a procedure like this:
That shortened your first 4 if statements into 1. I'll leave the rest up to you Once you have that you can call ur procedure for each player by using a for loop:
|
Author: | basketball4ever [ Wed Jan 19, 2005 10:32 pm ] |
Post subject: | |
lol as i mentioned... i'm not an array user : P |
Author: | Cervantes [ Wed Jan 19, 2005 10:34 pm ] |
Post subject: | |
You should be. If you don't know how to use arrays, read one of CompSci.ca's tutorials. They can be found in the Turing Tutorials section. You can also do a search. Arrays are easy to learn, and incredibly useful. You'll be glad you learned them, when you do. |