Random Procedures
Author |
Message |
Uber Tankz

|
Posted: Thu Jun 01, 2006 10:20 pm Post subject: Random Procedures |
|
|
How can i make these procedures come out randomly?
code: | proc arrowleft
var arrow : int
arrow := Pic.FileNew ("ArrowLeft.jpg")
Pic.SetTransparentColor (arrow, white)
var arsprite : int := Sprite.New (arrow)
Sprite.Show (arsprite)
end arrowleft
arrowleft
proc arrowright
var arrow : int
arrow := Pic.FileNew ("ArrowLeft.jpg")
arrow := Pic.Rotate (arrow, 270, -1, -1)
Pic.SetTransparentColor (arrow, white)
var arsprite : int := Sprite.New (arrow)
Sprite.Show (arsprite)
end arrowright
arrowright
proc arrowup
var arrow : int
arrow := Pic.FileNew ("ArrowLeft.jpg")
arrow := Pic.Rotate (arrow, 180, -1, -1)
Pic.SetTransparentColor (arrow, white)
var arsprite : int := Sprite.New (arrow)
Sprite.Show (arsprite)
end arrowup
arrowup
proc arrowdown
var arrow : int
arrow := Pic.FileNew ("ArrowLeft.jpg")
arrow := Pic.Rotate (arrow, 90, -1, -1)
Pic.SetTransparentColor (arrow, white)
var arsprite : int := Sprite.New (arrow)
Sprite.Show (arsprite)
end arrowdown
arrowdown
|
|
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Clayton

|
Posted: Thu Jun 01, 2006 10:24 pm Post subject: (No subject) |
|
|
make an array of procedures then call one element of the array randomly ex.
code: |
proc myProc1
end myProc1
proc myProc2
end myProc2
proc myProc3
end myProc 3
var myArray:array 1..3 of procedure
myArray(1):=myProc1
myArray(2):=myProc2
myArray(3):=myProc3
loop
myArray(Rand.Int(1,3))
end loop
|
something like that will suit ur needs i think |
|
|
|
|
 |
Uber Tankz

|
Posted: Thu Jun 01, 2006 10:29 pm Post subject: Thanks a lot |
|
|
dude thanks, thats all i needed rigth there, thanks a lot
[/b] |
|
|
|
|
 |
Clayton

|
Posted: Thu Jun 01, 2006 11:00 pm Post subject: (No subject) |
|
|
no problem its what im here for  |
|
|
|
|
 |
Delos

|
Posted: Fri Jun 02, 2006 11:31 am Post subject: Re: Random Procedures |
|
|
Uber Tankz wrote:
code: | proc arrowleft
var arrow : int
arrow := Pic.FileNew ("ArrowLeft.jpg")
Pic.SetTransparentColor (arrow, white)
var arsprite : int := Sprite.New (arrow)
Sprite.Show (arsprite)
end arrowleft
|
Notice how all of your procedures are exactly the same, except for a few values. In cases like these, you ought to save yourself some repitition and use parameters. Simple example:
code: |
proc put_square (num : int)
put num**2
end put_square
proc put_cube (num : int)
put num**3
end put_cube
% Notice that both are exactly the same except for the power...therefore:
proc put_power (num, power : int)
put num**power
end put_power
|
You can achieve the same effect with your procedures. Simply compress them into one, then use Rand.Int() to select some of the necassary parameters. I would also suggest compressing their contents into a record (type). Check out the [Turing Walkthrough] for more info. |
|
|
|
|
 |
zylum

|
Posted: Fri Jun 02, 2006 1:27 pm Post subject: (No subject) |
|
|
+1
theyre exactly the same except for the rotation angle.. so you could do
proc rotateArrow (angle:int)
%blah
%blah
arrow := Pic.Rotate (arrow, angle, -1, -1)
%blah blah
end rotateArrow
rotateArrow(Rand.Int(0,3)*90) |
|
|
|
|
 |
|
|