Computer Science Canada Random numbers in buttons. |
Author: | Space!!! [ 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>
Please specify what version of Turing you are using 4.11 |
Author: | Tony [ Tue Dec 28, 2010 11:48 pm ] |
Post subject: | RE:Random numbers in buttons. |
Be more specific. Do you have no idea about: - Drawing? Draw.Box - Clicking? Mouse.Where - Random Numbers? Rand.Int |
Author: | TokenHerbz [ 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. |
Author: | Space!!! [ 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. |
Author: | TokenHerbz [ 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!. |
Author: | ProgrammingFun [ 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)... |
Author: | Space!!! [ 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? |
Author: | Tony [ 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. |
Author: | Space!!! [ 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 |
Author: | Tony [ Sun Jan 02, 2011 7:10 pm ] |
Post subject: | RE:Random numbers in buttons. |
What do you want to be more specific? |
Author: | Space!!! [ 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?! |
Author: | ProgrammingFun [ 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:
|