Home: Perl Programming Help: Intermediate:
Moving positions



Lynn
Novice

Sep 23, 2012, 1:01 PM


Views: 3395
Moving positions

I need to increment xpos according to a random number 1-6 or deincrement it 1-6. I do not know how to go about that. My thought was:

Code
my $range = 1; 
my $minimum = 6;

my $random_number = int(rand($range)) + $minimum;

$xpos = $random_number; #instead of $xpos++ to move one position at a time


And then to deincrement 1-6 spaces, I have no idea. Can anyone point me in the right direction, or a good tutorial?
Thanks


BillKSmith
Veteran

Sep 23, 2012, 2:06 PM


Views: 3393
Re: [Lynn] Moving positions


Code
 
$xpos += (1 + int rand 6); # increment

$xpos -= (1 + int rand 6); # decrement

Good Luck,
Bill


Lynn
Novice

Sep 24, 2012, 11:21 AM


Views: 3373
Re: [BillKSmith] Moving positions

Thank you! This helped so much!