
-----------------------------------
basketball4ever
Wed Jan 19, 2005 9:47 pm

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:

%S & L map2
proc slmap
    % Going Up ladder 2 to 11
    if pos1 = 2 then
        delay (1000)
        pos1 := 11
        put "You just went on a ladder!" ..
        map2pos1
    end if
    if pos2 = 2 then
        delay (1000)
        pos2 := 11
        put "You just went on a ladder!" ..
        map2pos2
    end if
    if pos3 = 2 then
        delay (1000)
        pos3 := 11
        put "You just went on a ladder!" ..
        map2pos3
    end if
    if pos4 = 2 then
        delay (1000)
        pos4 := 11
        put "You just went on a ladder!" ..
        map2pos4
    end if
    % Going Up ladder 6 to 9
    if pos1 = 6 then
        delay (1000)
        pos1 := 9
        put "You just went on a ladder!" ..
        map2pos1
    end if
    if pos2 = 6 then
        delay (1000)
        pos2 := 9
        put "You just went on a ladder!" ..
        map2pos2
    end if
    if pos3 = 6 then
        delay (1000)
        pos3 := 9
        put "You just went on a ladder!" ..
        map2pos3
    end if
    if pos4 = 6 then
        delay (1000)
        pos4 := 9
        put "You just went on a ladder!" ..
        map2pos4
    end if
    % Going up ladder 7 to 21
    if pos1 = 7 then
        delay (1000)
        pos1 := 21
        put "You just went on a ladder!" ..
        map2pos1
    end if
    if pos2 = 7 then
        delay (1000)
        pos2 := 21
        put "You just went on a ladder!" ..
        map2pos2
    end if
    if pos3 = 7 then
        delay (1000)
        pos3 := 21
        put "You just went on a ladder!" ..
        map2pos3
    end if
    if pos4 = 7 then
        delay (1000)
        pos4 := 21
        put "You just went on a ladder!" ..
        map2pos4
    end if
    % Going up ladder 10 to 25
    if pos1 = 10 then
        delay (1000)
        pos1 := 25
        put "You just went on a ladder!" ..
        map2pos1
    end if
    if pos2 = 10 then
        delay (1000)
        pos2 := 25
        put "You just went on a ladder!" ..
        map2pos2
    end if
    if pos3 = 10 then
        delay (1000)
        pos3 := 25
        put "You just went on a ladder!" ..
        map2pos3
    end if...continued.


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  :wink:

-----------------------------------
cycro1234
Wed Jan 19, 2005 9:54 pm


-----------------------------------
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?

-----------------------------------
Bacchus
Wed Jan 19, 2005 9:55 pm


-----------------------------------
use arrays and fors

-----------------------------------
eNc
Wed Jan 19, 2005 9:59 pm

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

-----------------------------------
cycro1234
Wed Jan 19, 2005 10:05 pm


-----------------------------------
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]

-----------------------------------
basketball4ever
Wed Jan 19, 2005 10:15 pm


-----------------------------------
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. :P i figured i wouldnt use arrays already : P cos i'm too lazy.  But i know using a simple parameter pass can fix up the whole code

-----------------------------------
cycro1234
Wed Jan 19, 2005 10:18 pm


-----------------------------------
And what, might I ask, is a parameter pass???

-----------------------------------
basketball4ever
Wed Jan 19, 2005 10:19 pm


-----------------------------------
parameter pass = 
proc cycro (var:n:int) something like that :S ionno ms.**** said to use it : P

-----------------------------------
Neo
Wed Jan 19, 2005 10:30 pm


-----------------------------------
First setup your variables into an array, then you can make a procedure like this:

proc slmap (player : int)
    % Going Up ladder 2 to 11
    if pos (player) = 2 then
        delay (1000)
        pos (player) := 11
        put "You just went on a ladder!" ..
        map2pos (player)
    end if
end slmap


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:

for i : 1 .. 4
    slmap (i)
end for


-----------------------------------
basketball4ever
Wed Jan 19, 2005 10:32 pm


-----------------------------------
lol as i mentioned... i'm not an array user : P

-----------------------------------
Cervantes
Wed Jan 19, 2005 10:34 pm


-----------------------------------
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.
