Hi Forum,
I was trying to run several events practically at the same time in order to test this capability for some more involved development. In fact I had 10 cars running along 3 routes and my first attempt was succesful but not elegant. This is what I have done for each car:
on moveMe
if not the uAllowMove of me the exot moveMe
#Calculation of the coordinates of the next point and the time between the points (i.e. time of travelling between two points, denoted as "tSecs"), and then using
set loc of me to xLoc, yLoc
send "moveMe" to me in tSecs seconds
send "showTime" ~ this was for the time loop; pls see below.
end moveMe
This moves the object in "jumps" or steps and waits for the required timne of passage. However, I then found out that I could use "move" command so instead of "set loc of me .." and "send "moveMe" to me in tSecs", I utilised the following code:
move me to Xloc,yLoc in tSecs seconds
send "moveMe" to me in 10 milliseconds #Tried without any milliseconds, and then up to 5 seconds)!
This second version was more elegant when one car was tested (because the nobject has nearly continuous movement), but started to misbehave as soon as 10 cars were introduced. Not only that some objects disapeared along the route, but some cars jumped a few route segments.
Could someone explian the following:
1. reasons for such different behavious when using "move" command; Is there a better way to use "move" command?
2. what is the best way to run and control several objects doing something, interacting, etc at the same time;
3. best ways for the time "loop". I used "on showTime / end showTime" on the card, and "send "showTime" in the script for each object.
Please note that I find object oriented programming quite difficult (but atractive).
Many thanks.
Best regards,
Vladimir
Running several events at the same time
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Running several events at the same time
Hi Vladimir,
I started to write an answer with a few scripts, but then I realised it would be easier to just make an example. I have made a simple stack, which you can download here.
Can you explain how your objects should interact? The example I made doesn't contain any kind of interaction between the objects.
Best,
Mark
I started to write an answer with a few scripts, but then I realised it would be easier to just make an example. I have made a simple stack, which you can download here.
Can you explain how your objects should interact? The example I made doesn't contain any kind of interaction between the objects.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 14
- Joined: Mon Dec 21, 2009 10:37 pm
Re: Running several events at the same time
Hi Mark,
Very many thanks! It is avery elegant script. I will try to copy parts of it to see why my code was so slow. It seems to me that all that I was doing differently was to set the xLoc, yLoc to the next point coordinates. Since my objects were moving along three routes (for eacxh route along the points of polygon), I had a counter for each object which determines the next point and the coresponding coordinates were read from the field. Each object started at different time. The other difference, was that with "move" command I was moving objects between the points in a continuus fashion, while the "set loc of me to XLoc,YLoc.." was done in time jumps. The time jumps for continuoes movement and for ther jumps were the same (i.e they corresponded to the time required to cover the distance at some specified speed).
I will try now to rewrite the code accordingly and may come back with some questions, if I may. In the meantime I have a silly question: is the button property term "cIsMoving" (and one tha I used "uAllowMove") predefined in the sense that one has to use cIsMOving, or is it just a container for specifying variables which are specific for the object. For example, if I use "global m1, m2, m3,.." to specify the current point for objects (btn 1, bth 2, bth3, etc), could I also specify in btn "custom property" say "m1"; what I am trying to say, can we use custom properties to pass arguments to objects, or are these properties prespecified?
Beast regards,
Vladimir
www.risk-support.co.uk
Very many thanks! It is avery elegant script. I will try to copy parts of it to see why my code was so slow. It seems to me that all that I was doing differently was to set the xLoc, yLoc to the next point coordinates. Since my objects were moving along three routes (for eacxh route along the points of polygon), I had a counter for each object which determines the next point and the coresponding coordinates were read from the field. Each object started at different time. The other difference, was that with "move" command I was moving objects between the points in a continuus fashion, while the "set loc of me to XLoc,YLoc.." was done in time jumps. The time jumps for continuoes movement and for ther jumps were the same (i.e they corresponded to the time required to cover the distance at some specified speed).
I will try now to rewrite the code accordingly and may come back with some questions, if I may. In the meantime I have a silly question: is the button property term "cIsMoving" (and one tha I used "uAllowMove") predefined in the sense that one has to use cIsMOving, or is it just a container for specifying variables which are specific for the object. For example, if I use "global m1, m2, m3,.." to specify the current point for objects (btn 1, bth 2, bth3, etc), could I also specify in btn "custom property" say "m1"; what I am trying to say, can we use custom properties to pass arguments to objects, or are these properties prespecified?
Beast regards,
Vladimir
www.risk-support.co.uk
Re: Running several events at the same time
Hi Vladimir,
Have a look at the docs. There is an example there, which shows how to move an object along the point of a polygon. Replace mouseControl with target and you get:
You can use custom properties to store the points of a path. You can, but don't have to, use a polygon. For example, you can do this:
Best,
Mark
Have a look at the docs. There is an example there, which shows how to move an object along the point of a polygon. Replace mouseControl with target and you get:
Code: Select all
move the target to the points of graphic "Polygon" in 10 seconds
Code: Select all
move the target to the cPoints of the target in 10 seconds
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
- Posts: 14
- Joined: Mon Dec 21, 2009 10:37 pm
Re: Running several events at the same time
Hi Mark,
Many thanks! It is very elegant and fast. Last two questions:
1. Which documents did you refer to?
2. the attached case with 4 + 1 balls using cPoints property behaves in a funny way. I wanted to space the balls on route 1 (long route) by sending "mouseUp" command in x, y, z seconds and it did not work; the firts pass was done by the red ball, and the next ball followed in the second pass, etc. I then tried to altyer the "speed" of the balls and it works during the pass, but then there is a delay at the last point. The answer must be in the way the messages travel in REV. In any case this will not do for me because i would like to be able to stop all the balls at the certain point along the route by sending the command.
Unrelated question - what do you think about Ruby and Rails software? Is it similar to RunRev? I met some young people who think that it is best thing on Earth, but they did not know about MetaCard, etc.
Best regards,
Vladimir
PS. test is attached!
Many thanks! It is very elegant and fast. Last two questions:
1. Which documents did you refer to?
2. the attached case with 4 + 1 balls using cPoints property behaves in a funny way. I wanted to space the balls on route 1 (long route) by sending "mouseUp" command in x, y, z seconds and it did not work; the firts pass was done by the red ball, and the next ball followed in the second pass, etc. I then tried to altyer the "speed" of the balls and it works during the pass, but then there is a delay at the last point. The answer must be in the way the messages travel in REV. In any case this will not do for me because i would like to be able to stop all the balls at the certain point along the route by sending the command.
Unrelated question - what do you think about Ruby and Rails software? Is it similar to RunRev? I met some young people who think that it is best thing on Earth, but they did not know about MetaCard, etc.
Best regards,
Vladimir
PS. test is attached!