How to randomize moving objects on a path

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Peacfulrvr
Posts: 34
Joined: Mon Nov 03, 2014 7:11 pm

How to randomize moving objects on a path

Post by Peacfulrvr » Sat Nov 15, 2014 7:26 pm

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.

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: How to randomize moving objects on a path

Post by sefrojones » Sat Nov 15, 2014 8:39 pm

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

Peacfulrvr
Posts: 34
Joined: Mon Nov 03, 2014 7:11 pm

Re: How to randomize moving objects on a path

Post by Peacfulrvr » Sat Nov 15, 2014 9:01 pm

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.

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: How to randomize moving objects on a path

Post by sefrojones » Sat Nov 15, 2014 9:14 pm

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

Peacfulrvr
Posts: 34
Joined: Mon Nov 03, 2014 7:11 pm

Re: How to randomize moving objects on a path

Post by Peacfulrvr » Sat Nov 15, 2014 9:40 pm

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

Peacfulrvr
Posts: 34
Joined: Mon Nov 03, 2014 7:11 pm

Re: How to randomize moving objects on a path

Post by Peacfulrvr » Sat Nov 15, 2014 9:53 pm

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.

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: How to randomize moving objects on a path

Post by sefrojones » Sat Nov 15, 2014 10:09 pm

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
Attachments
handstest.zip
(26.13 KiB) Downloaded 188 times

Peacfulrvr
Posts: 34
Joined: Mon Nov 03, 2014 7:11 pm

Re: How to randomize moving objects on a path

Post by Peacfulrvr » Mon Nov 17, 2014 10:21 pm

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

Post Reply