{Need Help!} Random Coord Generator and Moving Object There!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
{Need Help!} Random Coord Generator and Moving Object There!
Is there a way to find random coordinates and then proceed to move an object there? This is another extension of the Cannonballs! Tutorial that I did and after the "intersect" command, I now am stuck on someone telling someone the sliders to move to a certain area and hitting the target. Anyone know what to do to make it generate random coordinates?
Thanks!
Thanks!
-
- VIP Livecode Opensource Backer
- Posts: 4000
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: {Need Help!} Random Coord Generator and Moving Object There!
Hi Bradyviz,
look up the random function in the dictionary. There is also an example to get a random number from a lower/upper range. Do that for the x and the y coordinate and there you are.
regards
Bernd
look up the random function in the dictionary. There is also an example to get a random number from a lower/upper range. Do that for the x and the y coordinate and there you are.
regards
Bernd
Re: {Need Help!} Random Coord Generator and Moving Object There!
As you can probably now guess, I am REALLY feeling stupid right now. After the example, I still can't find a way to get the random number in any way whatsoever. When I click the button that is supposed to give me a number when I tested it, nothing happens. When I tell it to put the number into a field, it says there is an error. Any Tips?
-
- VIP Livecode Opensource Backer
- Posts: 4000
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: {Need Help!} Random Coord Generator and Moving Object There!
Hi Bradyviz,
please post your script. You can use the "Code" tab and paste your script in there
regards
Bernd
please post your script. You can use the "Code" tab and paste your script in there
regards
Bernd
Re: {Need Help!} Random Coord Generator and Moving Object There!
Hi Brad,
I also highly recommend to go through these stacks to get the basics of Livecode:
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
I also highly recommend to go through these stacks to get the basics of Livecode:
http://www.runrev.com/developers/lesson ... nferences/
Best
Klaus
Re: {Need Help!} Random Coord Generator and Moving Object There!
Hi,
It is not necessary to shout "need help" in the subject of your script. If a new thread is opened in any other section than the announcements section, it is most likely going to be a "need help" subject. Now, if you don't mean to ask for help, you still don't need to shout but you can write in small capitals and everybody will still hear you. Please, mind your netiquette.
Kind regards,
Mark
It is not necessary to shout "need help" in the subject of your script. If a new thread is opened in any other section than the announcements section, it is most likely going to be a "need help" subject. Now, if you don't mean to ask for help, you still don't need to shout but you can write in small capitals and everybody will still hear you. Please, mind your netiquette.
Kind regards,
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
-
- VIP Livecode Opensource Backer
- Posts: 9655
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: {Need Help!} Random Coord Generator and Moving Object There!
Is your problem just generating a random point? Try:
On mouseUp
put item 3 of the rect of this card into xMax
put item 4 of the rect of this card into yMax
put random(xMax) & "," & random (yMax) into tRandomCoord
answer tRandomCoord
end mouseUp
This will give you a point within the rect of the card window.
Craig Newman
On mouseUp
put item 3 of the rect of this card into xMax
put item 4 of the rect of this card into yMax
put random(xMax) & "," & random (yMax) into tRandomCoord
answer tRandomCoord
end mouseUp
This will give you a point within the rect of the card window.
Craig Newman
Re: {Need Help!} Random Coord Generator and Moving Object There!
The code
did work to make a random point. But the problem is I already have 2 rectangles in the card so it selects the sky (or grass, not sure) but not the rectangle I want. I am experimenting for an hour right now but if anyone has a an idea right now while this I am experimenting that knows please let me know!dunbarx wrote: On mouseUp
put item 3 of the rect of this card into xMax
put item 4 of the rect of this card into yMax
put random(xMax) & "," & random (yMax) into tRandomCoord
answer tRandomCoord
end mouseUp
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Location: Aalst, Belgium
- Contact:
Re: {Need Help!} Random Coord Generator and Moving Object There!
Assuming you have a rectangle "Bounds" within which you want to determine a random point, try this:
HTH,
Jan Schenkel.
Code: Select all
on mouseUp
put (the left of graphic "Bounds") + random(the width of graphic "Bounds") & comma & \
(the top of graphic "Bounds") + random(the height of graphic "Bounds") \
into tNewPoint
answer tNewPoint
end mouseUp
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
-
- VIP Livecode Opensource Backer
- Posts: 4000
- Joined: Sun Jan 07, 2007 9:12 pm
- Location: Bochum, Germany
Re: {Need Help!} Random Coord Generator and Moving Object There!
Bradyviz,
suppose you have an area (rectangle) where you want ramdom coordinates from.
Suppose the rectangle is the rectangle of a hidden graphic (areaOfInterest)
for the x coordinates you want a value between item 1 of the rect and item 3 of the rect
for the y coordinates you want a value between item 2 and item 4 of the rect.
I the dictionary entry for ramdom is a function:
you could code your script:
this would give you random coordinates within the rect that you want.
I just see that Jan has posted something that amounts to the same, I post nevertheless.
regards
Bernd
suppose you have an area (rectangle) where you want ramdom coordinates from.
Suppose the rectangle is the rectangle of a hidden graphic (areaOfInterest)
for the x coordinates you want a value between item 1 of the rect and item 3 of the rect
for the y coordinates you want a value between item 2 and item 4 of the rect.
I the dictionary entry for ramdom is a function:
supposet the rect is called tRect and has "100,400,200,500" as values.function randomInRange lowerLimit,upperLimit
return random(upperLimit - lowerLimit + 1) + lowerLimit - 1
end randomInRange
you could code your script:
Code: Select all
on mouseUp
put "100,400,200,500" into tRect
put randominrange(item 1 of tRect, item 3 of tRect) into tX
put randomInRange(item 2 of tRect, item 4 of tRect) into tY
answer tX & comma & tY
end mouseUp)
function randomInRange lowerLimit,upperLimit
return random(upperLimit - lowerLimit + 1) + lowerLimit - 1
end randomInRange
I just see that Jan has posted something that amounts to the same, I post nevertheless.
regards
Bernd