Posted: Tue Jan 11, 2011 5:30 pm Post subject: Urgent Turing Calculator Help
What is it you are trying to achieve?
i am trying to make a visual calculator that if a person clicks a number, the number should go to the screen and display the number. the same thing with the second number and the symbol.
but i cannot do it.
What is the problem you are having?
i do not know how to make the mouse recognize i clicked the number/symbol
Describe what you have tried to solve this problem
i have tried looping it. making new variables, etc but it will still not work. the thing i want to find out is how will the mouse recognize if clicked the number and/ or symbol. and how to display it on the screen.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
var num : real
var num2 : real
var symbol : string
locate (20, 1)
put "please enter your first number : " ..
get num
locate (5, 20)
get num
locate (22, 1)
put "please enter your symbol"
get symbol
locate (5, 25)
get symbol
locate (24, 1)
put "please enter your second number"
get num2
locate (4, 30)
get num2
Turing:
<Add your code here>
Please specify what version of Turing you are using
4.1.1
Sponsor Sponsor
TerranceN
Posted: Tue Jan 11, 2011 6:05 pm Post subject: RE:Urgent Turing Calculator Help
Well you can get the mouse co-ordinates using Mouse.Where, and then detect if the mouse position is in each of the buttons. You can find out how to do that with a quick google search.
Wajih
Posted: Tue Jan 11, 2011 6:15 pm Post subject: RE:Urgent Turing Calculator Help
i still dont get how to do that thoug. do you have to use the variables that are already there or do you have to create new ones?
TokenHerbz
Posted: Tue Jan 11, 2011 8:07 pm Post subject: RE:Urgent Turing Calculator Help
you have to declare variable to use in turing, so...
var mx, my, mb: int for like mouse x,y button
inside your loop to use it,
Mouse.Where(mx,my,mb) to use these vars for mouse
then like, mx,my are chords of your mouse
mb would be your button, like
if mb = 1 then ***its clicked***
you can use more buttons to like middle/right but lets start wit hthis first
Wajih
Posted: Tue Jan 11, 2011 8:46 pm Post subject: RE:Urgent Turing Calculator Help
so how will that help the mouse trecognize thw number? can someone give me an example code so i can better understand this problem? help is appreciated
Tony
Posted: Tue Jan 11, 2011 9:09 pm Post subject: RE:Urgent Turing Calculator Help
That will just tell you that a mouse has been clicked... somewhere. You can use that location to figure out if it's been inside any of the button locations. If so, you get a value associated with that location.
Posted: Tue Jan 11, 2011 9:42 pm Post subject: RE:Urgent Turing Calculator Help
it says i need x and y and b, but i do not know what those are for. or how to use them in my physical code. the variables that i have so far are num, num2, symbol, and sum
Tony
Posted: Tue Jan 11, 2011 9:59 pm Post subject: RE:Urgent Turing Calculator Help
I think you might need those variables then. If you read Mouse.Where, it explains what all of them are for:
Quote:
The parameters x and y are set to the current location of the mouse cursor.
Quote:
button is set to 0 if all the mouse buttons are up, and 1 if any of the mouse buttons are down.
Posted: Tue Jan 11, 2011 10:07 pm Post subject: RE:Urgent Turing Calculator Help
but what do x and y control, like how do they affect the mouse cursor and what happens if the mouse cursor hits any of the numbers and/or symbols. also what is the button needed for and what does ot mean that it is set to 0 or 1?
TerranceN
Posted: Tue Jan 11, 2011 10:14 pm Post subject: RE:Urgent Turing Calculator Help
The whole point of Mouse.Where is to find the position of the mouse. When you call Mouse.Where, it changes the values of the variables you send it to be the current state of the mouse (the mouse's x, y, and button). Once we know the position of the mouse, we can check if the button is down with an if statement.
If it is down, we then need to check if it is inside a button. Since the buttons are circular, if the distance from the centre of the circle to the mouse is less then the radius of the circle (you set both of those when you drew the circle, so you know both of them), then the mouse is inside the circle. Since the button is down and the mouse is inside the circle, the button has been pressed.
Tony
Posted: Tue Jan 11, 2011 10:14 pm Post subject: RE:Urgent Turing Calculator Help
Posted: Tue Jan 11, 2011 10:54 pm Post subject: RE:Urgent Turing Calculator Help
i used the code. but it deleted the picture of my calculator. any reasons why?
TerranceN
Posted: Tue Jan 11, 2011 11:14 pm Post subject: RE:Urgent Turing Calculator Help
And how exactly did you use the code? Did you go through it and understand how and why it worked the way it does on its own, then apply the concepts it demonstrated to your own project? Or did you copy and paste it at the top of your own code? But considering the problem you are having, I am guessing the latter. If my guess is correct, the best advice I can give you is to actually learn Turing instead of copying and pasting code and hoping it will work. By the way, we have a nice Turing tutorial here.
Although if I am wrong, my apologies for raging about kids who refuse to actually do work and/or think.