Making Buttons Solid
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 81
- Joined: Mon Jan 09, 2012 4:48 pm
Re: Making Buttons Solid
nope i cant do the random button thing
my mind is blank.
Grade = F
my mind is blank.
Grade = F
Re: Making Buttons Solid
OK - here's a hint:
There are (at least) a couple of ways to get a random number:
1. Use the random() function - the documentation for it is in the dictionary
2. Use the any keyword:
There are (at least) a couple of ways to get a random number:
1. Use the random() function - the documentation for it is in the dictionary
Code: Select all
put random(10) into tSomeRandomNumber
Code: Select all
put any item of "14,78,9,63,2,65,35,4,5,8" into tSomeRandomNumber
-
- Posts: 81
- Joined: Mon Jan 09, 2012 4:48 pm
Re: Making Buttons Solid
i am really struggling with this,
i understand random and put and i have a field the size of my card
but my mover button just ends up in the top left corner?
the start location of the button mover is in the middle of the screen.
Code: Select all
on mouseUp
put random(10) into tMovex
put random(10) into tMovey
put the loc of btn "mover" into startLoc
repeat until intersect(btn "mover",button "theTarget") = "true"
get the loc of btn "mover"
set the loc of btn "mover" to (tMovex + 5) & "," & (tMovey + 5)
wait 2
if the loc of button "mover" is not within the rect of field "screen" then
set the loc of btn "mover" to startLoc
end if
end repeat
end mouseUp
but my mover button just ends up in the top left corner?
the start location of the button mover is in the middle of the screen.
Re: Making Buttons Solid
Struggle, profanity, triumph.
These are the stages of learning to program. And of writing programs. And of debugging. And...
The intersect function was tested through the loop and forked when you hit the target in that first example. But it was a set-up. the movement was restricted to the right, and the target was already in the path.
In the screen model, you have to use the borders of the card as an intermediate target to bounce off of. You will not be able to use the intersect function in this case. If you read the docs, you can see that this function is tailor made for a pair of objects. It has no way of knowing that you are at the edge of the card window. But there are other ways to know that. Read up on the "rect", "top", "left", bottom, and "right" keywords. You will HAVE to know what an item is.
When you do get a "hit" on a card edge, you will want to change direction. You need to make sure that your new random offset values make sense based on which edge you hit. But they stay the same until you hit that edge. Then they can change again.
You yourself saw that you could move the button in any direction by modifying both x and y offsets. So you need to set that up, and make your initial offsets random.
Or maybe start with having the "mover" button just bounce left and right from the edges. Then do diagonals and random changes in x,y.
You are in the struggle stage. You will be fine.
Craig Newman
These are the stages of learning to program. And of writing programs. And of debugging. And...
The intersect function was tested through the loop and forked when you hit the target in that first example. But it was a set-up. the movement was restricted to the right, and the target was already in the path.
In the screen model, you have to use the borders of the card as an intermediate target to bounce off of. You will not be able to use the intersect function in this case. If you read the docs, you can see that this function is tailor made for a pair of objects. It has no way of knowing that you are at the edge of the card window. But there are other ways to know that. Read up on the "rect", "top", "left", bottom, and "right" keywords. You will HAVE to know what an item is.
When you do get a "hit" on a card edge, you will want to change direction. You need to make sure that your new random offset values make sense based on which edge you hit. But they stay the same until you hit that edge. Then they can change again.
You yourself saw that you could move the button in any direction by modifying both x and y offsets. So you need to set that up, and make your initial offsets random.
Or maybe start with having the "mover" button just bounce left and right from the edges. Then do diagonals and random changes in x,y.
You are in the struggle stage. You will be fine.
Craig Newman
Re: Making Buttons Solid
Just so you know, this random move exercise is not a trivial thing. It is not hard, but involves lots of basic LC stuff, and is really an intermediate level project. You will get support here until you either become proficient or die trying. Keep writing back, keep experimenting.
Craig Newman
Craig Newman
-
- Posts: 81
- Joined: Mon Jan 09, 2012 4:48 pm
Re: Making Buttons Solid
Code: Select all
repeat forever
get the loc of button "mover"
set the loc of btn "mover" to (item 1 of it + 1) & "," & (item 2 of it)
wait 2
if (the right of button "mover" - 10) > the right of this card then
get the loc of button "mover"
set the loc of btn "mover" to (item 1 of it - 1) & "," & (item 2 of it)
wait 2
end if
if (the left of button "mover" - 10) > the left of this card then
end if
end repeat
Re: Making Buttons Solid
OK, I am giving you this because you have been good. You are therefore obliged to spend much time and sweat making it your own. In the same three button card, place this in the starting button script
Now and then there could be an issue with this code. Not that it doesn't work, mind you. What do you think about that?
Can you find the rationale behind each line of the code? Homework.
There are more elegant ways to do this, relying less on repeat loops, by using the "send" command with its "in time" variant to a subroutine. But that is for another day.
Craig Newman
Code: Select all
on mouseUp
put random(10) - random(10) into xOffset
put random(10) - random(10) into yOffset
put item 3 of the rect of this cd into rightEdge
put item 4 of the rect of this cd into bottomEdge
repeat until the top of btn "mover" < 0 or the bottom of btn "mover" > bottomEdge\
or the left of btn "mover" < 0 or the right of btn "mover" > rightEdge
get the loc of btn "mover"
set the loc of btn "mover" to (item 1 of it + xOffset) & "," & (item 2 of it + yOffset)
wait 2
get the rect of btn "mover"
switch
case item 1 of it <= 0
set the loc of btn "mover" to (item 1 of the loc of btn "mover"+ abs(xOffset)) & "," & (item 2 of the loc of btn "mover" )
put 0 - xOffset into xOffset
break
case item 2 of it <= 0
set the loc of btn "mover" to (item 1 of the loc of btn "mover") & "," & (item 2 of the loc of btn "mover" + abs(yOffset))
put 0 - yOffset into yOffset
break
case item 3 of it >= rightEdge
set the loc of btn "mover" to (item 1 of the loc of btn "mover" - xOffset) & "," & (item 2 of the loc of btn "mover" )
put 0 - xOffset into xOffset
break
case item 4 of it >= bottomEdge
set the loc of btn "mover" to (item 1 of the loc of btn "mover") & "," & (item 2 of the loc of btn "mover" - yOffset )
put 0 - yOffset into yOffset
break
end switch
if intersect(btn "mover",btn "tTarget") = "true" then exit to top
end repeat
end mouseUp
Can you find the rationale behind each line of the code? Homework.
There are more elegant ways to do this, relying less on repeat loops, by using the "send" command with its "in time" variant to a subroutine. But that is for another day.
Craig Newman
-
- Posts: 81
- Joined: Mon Jan 09, 2012 4:48 pm
Re: Making Buttons Solid
thats really good, bit mind blowing BUT still really good.
its pretty far out from what i needed but i this hase been a wonderful learning experience
so thanks to everyone who has added to this post with advice and help.
now i just need to work out how i can work this with touch instead of buttons.
thanks again tho everyone!
its pretty far out from what i needed but i this hase been a wonderful learning experience
so thanks to everyone who has added to this post with advice and help.
now i just need to work out how i can work this with touch instead of buttons.
thanks again tho everyone!
-
- Posts: 81
- Joined: Mon Jan 09, 2012 4:48 pm
Re: Making Buttons Solid
Code: Select all
if intersect(btn "mover",btn "tTarget") = "true" then exit to top
Code: Select all
if intersect(group "movers",btn "tTarget") = "true" then exit to top
Re: Making Buttons Solid
This is the sort of question you answer by trying it out.
Craig Newman
Craig Newman
-
- Posts: 81
- Joined: Mon Jan 09, 2012 4:48 pm
Re: Making Buttons Solid
yes your right and on that note, i feel i have no more questions to ask on this subject.
thanks again
thanks again
Re: Making Buttons Solid
That would be either great news or a pity. There is always more to ask and to know.
Craig Newman
Craig Newman
-
- Posts: 81
- Joined: Mon Jan 09, 2012 4:48 pm
Re: Making Buttons Solid
well i got loads of questions, i was just being polite lol
thanks
thanks