Page 1 of 1
How to randomize moving objects on a path
Posted: Sat Nov 15, 2014 7:26 pm
by Peacfulrvr
I am a newbie with programming experience 20 years ago. I am making a beginner game and am trying to automate a left and and a right hand to move along 4 paths. The left will use path 1 and 2 and the right will use path 3 and 4. I want to randomize so one hand will move at one time then the next will move. Here is the code I have so far...
On moveobj
move image "rthand.gif" to the points of graphic "path4" in 6 seconds without waiting
move image "rthand.gif" to the points of graphic "path3" in 6 seconds without waiting
move image "lfthand.gif" to the points of graphic "path2" in 6 seconds without waiting
move image "lfthand.gif" to the points of graphic "path1" in 6 seconds without waiting
send "moveobj" to me in 7 seconds
end moveobj
I have tried putting a random(4) into a variable and then checking the variable using if then statements but that did not work.
I have tried concatinating a variable onto the path but dont know what I am doing.
Any ideas how to do this.
Re: How to randomize moving objects on a path
Posted: Sat Nov 15, 2014 8:39 pm
by sefrojones
If I understand what you're asking for, and the right hands should only move on 2 of the paths, and the left will move on the other 2, you could name them accordingly like this: RightPath1 & RightPath2 for the right hand and LeftPath1/2 for the left hand. You can randomize it without a variable,try something like this:
Code: Select all
On moveobj
move image "rthand.gif" to the points of graphic ("RightPath"&random(2)) in 2 seconds
move image "rthand.gif" to the points of graphic ("RightPath"&random(2)) in 2 seconds
move image "lfthand.gif" to the points of graphic ("LeftPath"&random(2)) in 2 seconds
move image "lfthand.gif" to the points of graphic ("LeftPath"&random(2)) in 2 seconds
send "moveobj" to me in 7 seconds
end moveobj
Hope that helps,
Sefro
Re: How to randomize moving objects on a path
Posted: Sat Nov 15, 2014 9:01 pm
by Peacfulrvr
That is so close to what I am trying to do. However, that does 2 random rights then 2 random lefts and I am trying to get it to randomize 1 of the 4 hands so the player will not know which hand is going to be reaching next.
Re: How to randomize moving objects on a path
Posted: Sat Nov 15, 2014 9:14 pm
by sefrojones
Maybe name them rthand1 and rtHand2,(etc) and something like this:
Code: Select all
On moveobj
move image "rthand"&random(2)&".gif" to the points of graphic ("RightPath"&random(2)) in 2 seconds
move image "lfthand"&random(2)&".gif" to the points of graphic ("LeftPath"&random(2)) in 2 seconds
send "moveobj" to me in 7 seconds
end moveobj
If this isn't what your looking for, upload a sample stack (remember to zip it first) and I will give it a look.
--Sefro
Re: How to randomize moving objects on a path
Posted: Sat Nov 15, 2014 9:40 pm
by Peacfulrvr
I get the error card "card id 1033": compilation error at line 44 (move: missing 'to'), char 12
double checked the name of the rthand1,2 and lfthand1,2 and they agree with the code
Re: How to randomize moving objects on a path
Posted: Sat Nov 15, 2014 9:53 pm
by Peacfulrvr
Thank you for the help. I went to one hand going on a random path1-4. I will try to figure out another way later after I have hammered out the basics of this first game.
Re: How to randomize moving objects on a path
Posted: Sat Nov 15, 2014 10:09 pm
by sefrojones
Hi again, the reason for the error above was missing parenthesis in the code:
Code: Select all
On moveobj
move image ("rthand"&random(2)&".gif") to the points of graphic ("RightPath"&random(2)) in 2 seconds
move image ("lfthand"&random(2)&".gif") to the points of graphic ("LeftPath"&random(2)) in 2 seconds
send "moveobj" to me in 7 seconds
end moveobj
--Sefro
Edit: I made a sample stack, that I think does what you're asking for
Re: How to randomize moving objects on a path
Posted: Mon Nov 17, 2014 10:21 pm
by Peacfulrvr
That is exactly what I was trying to do. I think I might have to go through some tutorials. I am not sure when to put code on the card, stack or object. Well I better get to work. I have not programmed in years and time flies by before I realize I have not gotten my real job done. Thanks for the help