Random numbers in buttons.
Author |
Message |
Space!!!
|
Posted: Tue Dec 28, 2010 11:33 pm Post subject: Random numbers in buttons. |
|
|
What is it you are trying to achieve?
i want to have 4 buttons that will display random numbers every time a user runs the program.
What is the problem you are having?
i have no idea how to do this.
Describe what you have tried to solve this problem
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
<Add your code here>
|
Please specify what version of Turing you are using
4.11
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
|
|
|
|
TokenHerbz
|
Posted: Wed Dec 29, 2010 2:03 am Post subject: RE:Random numbers in buttons. |
|
|
BAM tony damn you fast....
but yes,
draw your boxes, if click inside those boses, display random number. end done awesome marks. BAM. |
|
|
|
|
|
Space!!!
|
Posted: Wed Dec 29, 2010 12:26 pm Post subject: RE:Random numbers in buttons. |
|
|
mhm but i have to make buttons that already display random numbers; then the user clicks it. |
|
|
|
|
|
TokenHerbz
|
Posted: Wed Dec 29, 2010 2:35 pm Post subject: RE:Random numbers in buttons. |
|
|
then do the random generation first. doesn't matter when the user clicks it, your program!. |
|
|
|
|
|
ProgrammingFun
|
Posted: Wed Dec 29, 2010 2:59 pm Post subject: RE:Random numbers in buttons. |
|
|
Generate a random number, draw a box, and then use font.draw to write the number inside the box...and use buttonwait or mouse.where to make the "button" clickable....all of this will execute so fast that the user will only see the four buttons
You can do all of the above in a counted loop to create four buttons (with the locations of the drawings incrementing each time)... |
|
|
|
|
|
Space!!!
|
Posted: Sun Jan 02, 2011 11:23 am Post subject: RE:Random numbers in buttons. |
|
|
var finished : boolean := false
var X, Y, button : int
proc randNumber
colorback (brightred)
locate (5, 16)
put Rand.Int (0, 100)
locate (5, 28)
put Rand.Int (0, 100)
locate (5, 41)
put Rand.Int (0, 100)
locate (5, 53)
put Rand.Int (0, 100)
end randNumber
proc input
locate (10, 1)
mousewhere (X, Y, button)
if button = 1 then
if (X >= 100 and X <= 150) and (Y >= 300 and Y <= 350) then
locate (10, 30)
put "1"
elsif (X >= 200 and X <= 250) and (Y >= 300 and Y <= 350) then
locate (20, 30)
put "2"
elsif (X >= 300 and X <= 350) and (Y >= 300 and Y <= 350) then
locate (10, 30)
put "3"
elsif (X >= 400 and X <= 450) and (Y >= 300 and Y <= 350) then
locate (10, 30)
put "4"
end if
end if
end input
%Buttons
drawfillbox (100, 300, 150, 350, brightred)
drawfillbox (200, 300, 250, 350, brightred)
drawfillbox (300, 300, 350, 350, brightred)
drawfillbox (400, 300, 450, 350, brightred)
%Blank boxes
drawbox (100, 200, 150, 250, brightred)
drawbox (200, 200, 250, 250, brightred)
drawbox (300, 200, 350, 250, brightred)
drawbox (400, 200, 450, 250, brightred)
randNumber
loop
input
exit when finished
end loop
This is what I did. Is there any way to drag or move the buttons into the blank boxes? |
|
|
|
|
|
Tony
|
Posted: Sun Jan 02, 2011 2:50 pm Post subject: RE:Random numbers in buttons. |
|
|
Mouse.Where tells you where user's mouse is and if it's clicked; from there, you can figure out if something is being dragged, and where to.
You'd want to draw the box under the mouse. For that, you will find Font.Draw to be more useful than figuring out row/column of text.
Keep in mind that you'd need to figure out all the different states that a box can be in (original position, dragged, dropped) and all the transitions (picked up, still dragging, let go), to make this work. If you remember what state the mouse used to be during the _last_ frame, then together with the current reading, you get a total of 4 different click configurations. This will be enough to figure out how to drag things. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
Space!!!
|
Posted: Sun Jan 02, 2011 6:43 pm Post subject: RE:Random numbers in buttons. |
|
|
A bit more specific will be helpful..i m not a pro in turing |
|
|
|
|
|
Tony
|
|
|
|
|
Space!!!
|
Posted: Sun Jan 02, 2011 9:58 pm Post subject: RE:Random numbers in buttons. |
|
|
I get the Mouse.Where part but then How can you pick up the box?! |
|
|
|
|
|
ProgrammingFun
|
Posted: Sun Jan 02, 2011 10:35 pm Post subject: Re: RE:Random numbers in buttons. |
|
|
Tony @ Sun Jan 02, 2011 2:50 pm wrote: Mouse.Where tells you where user's mouse is and if it's clicked
You question has already been answered: Mouse.Where will tell you if the mouse is clicked. You can then use this information to create a drag function (when mouse is pressed, drag is enabled).
You can always refer to the Turing Documentation where Mouse.Where is described as follows:
Turing: |
%mousewhere
%Syntax mousewhere (var x, y, button : int)
%Description The mousewhere procedure is used to get current information about the status of the mouse. The parameters x and y are set to the current location of the mouse cursor. If the program is running on a system using windows, the %cursor may be outside the window. This means that x and y may be set to values outside of the bounds of 0 to maxx and 0 to maxy.
%The parameter button is set depending on the current mode. In "single-button mode" (where the mouse is treated like a one-button mouse), button is set to 0 if all the mouse buttons are up, and 1 if any of the mouse buttons are down. In %"multi-button mode", button is assigned the sum of 1 if the left button is down, 10 if the middle button is down, and 100 if the right button is down. Thus if button has the value of 101, then it means that the left and right mouse buttons were %depressed.
%Example A program that displays the status of the mouse at the top left corner of the screen.
var x, y, button : int
loop
mousewhere (x, y, button )
locate (1, 1)
if button = 0 then
put x : 4, " ", y : 4, " button up"
else
put x : 4, " ", y : 4, " button down"
end if
end loop
%See also buttonmoved and buttonwait to get mouse events saved in a queue. See also buttonchoose to switch between "single-button mode" and "multi-button mode".
|
|
|
|
|
|
|
|
|