How to randomize moving objects on a path
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 34
- Joined: Mon Nov 03, 2014 7:11 pm
How to randomize moving objects on a path
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.
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.
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: How to randomize moving objects on a path
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:
Hope that helps,
Sefro
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
Sefro
-
- Posts: 34
- Joined: Mon Nov 03, 2014 7:11 pm
Re: How to randomize moving objects on a path
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.
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: How to randomize moving objects on a path
Maybe name them rthand1 and rtHand2,(etc) and something like this:
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
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
-
- Posts: 34
- Joined: Mon Nov 03, 2014 7:11 pm
Re: How to randomize moving objects on a path
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
double checked the name of the rthand1,2 and lfthand1,2 and they agree with the code
-
- Posts: 34
- Joined: Mon Nov 03, 2014 7:11 pm
Re: How to randomize moving objects on a path
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.
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: How to randomize moving objects on a path
Hi again, the reason for the error above was missing parenthesis in the code:
--Sefro
Edit: I made a sample stack, that I think does what you're asking for
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
Edit: I made a sample stack, that I think does what you're asking for
- Attachments
-
- handstest.zip
- (26.13 KiB) Downloaded 188 times
-
- Posts: 34
- Joined: Mon Nov 03, 2014 7:11 pm
Re: How to randomize moving objects on a path
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