PDA

View Full Version : Use an array value to generate a random number



IronTeapot
10-14-2006, 03:20 PM
This is part of my code so far, it compiles but everytime it doesn't run for a full for loop.



program designCharacter;
{.include srl/srl.scar}

var i,a,iMax: Integer;
yc: Integer;

var lookMax: array [0..11] of Integer;

procedure setlookMax;
begin
lookMax[0]:=8
lookMax[1]:=7
lookMax[2]:=7
lookMax[3]:=5
lookMax[4]:=2
lookMax[5]:=4
lookMax[6]:=2
lookMax[7]:=11
lookMax[8]:=15
lookMax[9]:=15
lookMax[10]:=5
lookMax[11]:=8
end;

procedure makeCharacter;
begin
setlookMax;
yc:=90
for a:=0 to 6 do //Only runs 4 times
begin
iMax:=Random(lookMax[a])
for i:= 0 to iMax do
begin
Mouse(165,yc,2,2,true)
Wait (50 + Random (250));
end;
a:=a+1
yc:=yc+35
Wait (25 + Random (50));
end;
Wait (50 + Random (250));
end;

procedure colorCharacter;
begin
setlookMax;
yc:=95
for a:=7 to 11 do //Only runs 3 times
begin
iMax:=Random(lookMax[a])
for i:= 0 to iMax do
begin
Mouse(467,yc,2,2,true)
Wait (50 + Random (250));
end;
a:=a+1
yc:=yc+35
end;
Wait (50 + Random (250));
end;

procedure designCharacter;
begin
makeCharacter;
colorCharacter;
//Mouse(260,280,5,5,true) clicks accept
//Wait(1000+Random(500))
end;

begin
designCharacter
End.


Your welccome to run it on a new account. It randomly generates your character's looks as part of my upcomming 'create your army' script.

with the character design screen up, locate the rs window, and click play.

I Pick Axes
10-14-2006, 06:38 PM
Why not just have them all click random(25) times or something, because the character trait selection wraps around?

As for the loops, why not change them to while loops?

Oh, and more importantly for you,
for loops automatically increment, and if you call a:=a+1 then you're incrementing again, and it's really incrementing twice a run.

IronTeapot
10-14-2006, 07:13 PM
YAY! Thank you I Pick Axes! I didn't know that for loops auto increment. Deleting the a:=a+1 made it work flawlessly with the current setup. I just tested it with a while loop, and it works the same. Ill stick with the for loop for now, but may change it in the final setup. I used an array because my original one was 185 lines because I did each character attribute in its own procedure. Im using the constants of the array instead of Random(#) just so its more organized I suppose, and saves time. Imagine having it get 24 on Random(25) for the feet attribute. Alot of wasted clicks.

It works now, and Im happy nontheless. Thank you :)

OH and what is that mouse function that move the mouse instead of instantly placing it at x,y? not movemousesmoth, but the better srl one?

I Pick Axes
10-14-2006, 07:45 PM
Mouse handles spline movement and randomized click. MMouse is for moving but not clicking.

lardmaster
10-18-2006, 02:07 AM
hmm... we may be building competing scripts, mine also makes the characters, but benmouse commits suicide when i try to find a color and move there!

IronTeapot
10-18-2006, 02:45 PM
I have actually put the script on hold because i read somewhere that a srl scripter is soon to be launching his version of a tut runner. most likely sooner than i can have mine completed. im only at the bread baking stage :(.

CamHart
10-18-2006, 11:23 PM
I have actually put the script on hold because i read somewhere that a srl scripter is soon to be launching his version of a tut runner. most likely sooner than i can have mine completed. im only at the bread baking stage :(.

Keep it going man, thats how you learn new stuff. And who's to say your script won't be better?

IronTeapot
10-18-2006, 11:59 PM
Humm, your right. I guess ill just keep going. Never hurts to have multiple versions of one script. Matbe it will get me a membership status :)