
-----------------------------------
Wajih
Tue Jan 11, 2011 5:30 pm

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

drawbox (100, 100, 500, 475, red)
drawbox (128, 305, 470, 350, black)

locate (2, 32)
put "CALCULATOR" ..
locate (16, 19)
put "1" ..
locate (16, 26)
put "2" ..
locate (16, 33)
put "3" ..
locate (13, 19)
put "4" ..
locate (13, 26)
put "5" ..
locate (13, 33)
put "6" ..
locate (10, 19)
put "7" ..
locate (10, 26)
put "8" ..
locate (10, 33)
put "9" ..
locate (10, 40)
put "=" ..
locate (16, 40)
put "-" ..
locate (13, 40)
put "+" ..
locate (13, 45)
put "/" ..
locate (13, 50)
put "*" ..


drawoval (148, 151, 12, 12, black)
drawoval (205, 151, 12, 12, black)
drawoval (262, 151, 12, 12, black)
drawoval (148, 200, 12, 12, black)
drawoval (205, 200, 12, 12, black)
drawoval (262, 200, 12, 12, black)
drawoval (148, 249, 12, 12, black)
drawoval (205, 249, 12, 12, black)
drawoval (262, 249, 12, 12, black)
drawoval (316, 249, 20, 20, black)
drawoval (316, 200, 13, 13, black)
drawoval (316, 151, 13, 13, black)
drawoval (356, 200, 13, 13, black)
drawoval (396, 200, 13, 13, black)
drawfillbox (280, 100, 290, 300, black)


    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







Please specify what version of Turing you are using
4.1.1

-----------------------------------
TerranceN
Tue Jan 11, 2011 6:05 pm

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
Tue Jan 11, 2011 6:15 pm

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
Tue Jan 11, 2011 8:07 pm

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
Tue Jan 11, 2011 8:46 pm

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
Tue Jan 11, 2011 9:09 pm

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.

-----------------------------------
Wajih
Tue Jan 11, 2011 9:37 pm

RE:Urgent Turing Calculator Help
-----------------------------------
but do i need to create new variables to use mousewhere command? or can i use the ones that i already have?

-----------------------------------
Tony
Tue Jan 11, 2011 9:40 pm

RE:Urgent Turing Calculator Help
-----------------------------------
What kind of variables does the documentation say that you need? And what kind of variables do you already have?

-----------------------------------
Wajih
Tue Jan 11, 2011 9:42 pm

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
Tue Jan 11, 2011 9:59 pm

RE:Urgent Turing Calculator Help
-----------------------------------
I think you might need those variables then. If you read 
The parameters x and y are set to the current location of the mouse cursor.


button is set to 0 if all the mouse buttons are up, and 1 if any of the mouse buttons are down.


-----------------------------------
Wajih
Tue Jan 11, 2011 10:07 pm

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
Tue Jan 11, 2011 10:14 pm

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
Tue Jan 11, 2011 10:14 pm

RE:Urgent Turing Calculator Help
-----------------------------------
Please just read the linked docs.

-----------------------------------
Wajih
Tue Jan 11, 2011 10:54 pm

RE:Urgent Turing Calculator Help
-----------------------------------
i used the code. but it deleted the picture of my calculator. any reasons why?

-----------------------------------
TerranceN
Tue Jan 11, 2011 11:14 pm

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.

-----------------------------------
Wajih
Tue Jan 11, 2011 11:26 pm

RE:Urgent Turing Calculator Help
-----------------------------------
i read it and somewhat understand it now. i amstill trying to comprehend it some parts. i put my code inside the loop with the mousewhere and got the desired effect. the only thing now is how do you make the make the turing machine recognize what kind of number the mouse is at. and how to display it on the screen.

 

  if (x >= 196) and (x < 210) and (y > 237) and (y < 259)  then
    put "8"
   
    end if

i tried that. but it still does not show the answer in the box at the top. also how do i store the number. like for example say if the user enters a number, i want the number to be stored. do i have to put the num after the "8" or something like that

-----------------------------------
Tony
Tue Jan 11, 2011 11:33 pm

RE:Urgent Turing Calculator Help
-----------------------------------
You would probably want to put that number into some kind of a variable; then you could work with the values in your variables.

-----------------------------------
Wajih
Tue Jan 11, 2011 11:50 pm

RE:Urgent Turing Calculator Help
-----------------------------------
see i did that. i put it into the num variable which is a real. 

but it still says "8 false"

  if (button = 1) and( x >= 196) and (x < 210) and (y > 237) and (y < 259)  then
    locate ( 5, 19)
    put "", 8, (num = 8) 
    end if

do you have any idea why it says false

-----------------------------------
Tony
Tue Jan 11, 2011 11:55 pm

RE:Urgent Turing Calculator Help
-----------------------------------
what is the value of num at that point?
[code]
put "", 8, (num = 8), " num is: ", num
[/code]

What is the difference between real and int?

-----------------------------------
Wajih
Wed Jan 12, 2011 5:34 pm

RE:Urgent Turing Calculator Help
-----------------------------------
isnt int any whole number? 
and real is any number, either a whole number or decimal

-----------------------------------
2goto1
Wed Jan 12, 2011 5:53 pm

RE:Urgent Turing Calculator Help
-----------------------------------
An integer can be either positive or negative, whereas a whole number is 0 or greater.

-----------------------------------
Wajih
Wed Jan 12, 2011 6:26 pm

RE:Urgent Turing Calculator Help
-----------------------------------
i made the necessary corrections to the code. now the thing is how do i make the numbers for num 2 appear because every time i hit a number it only goes to num. does anyone know why?


var num : real 
var num2 : real := 0
var symbol : string
var x , y , button : int := 0




loop
    Mouse.Where (x, y, button)
    Text.Locate (22, 1)
    if button = 0 then
        put x : 0, "  ", y : 0, "  button up"
    else
        put x : 0, "  ", y : 0, "  button down"
    end if
    


if (button = 1) and ( x >= 137) and ( x = 142) and  ( y = 194) and (x = 142) and ( y = 251) and (x = 142) and ( y = 137) and (x = 190) and ( y = 194) and (x = 190) and ( y = 251) and (x = 190) and ( y = 137) and (x = 241) and ( y = 196) and (x < 210) and (y > 237) and (y < 259)  then
    locate (5, 19)
    num := 8
    put "", num
end if
 
 
  if ( button = 1 ) and ( x >= 251) and (x = 241) and ( y = 298) and (x < 333) and (y > 234) and (y < 266)  then
    locate (5, 30)
    symbol := "="
    put "", symbol
end if
 
if (button = 1) and( x >= 387) and (x < 405) and (y > 190) and (y < 210)  then
    locate (5, 22)
    symbol := "*"
    put "", symbol
end if

if (button = 1) and( x >= 345) and (x < 367) and (y > 188) and (y < 210)  then
    locate (5, 22)
    symbol := "/"
    put "", symbol
end if
 
if (button = 1) and( x >= 305) and (x < 325) and (y > 142) and (y < 163)  then
    locate (5, 22)
    symbol := "-"
    put "", symbol
end if

if (button = 1) and( x >= 305) and (x < 325) and (y > 190) and (y < 210)  then
    locate (5, 22)
    symbol := "+"
    put "", symbol
end if




   
    
    drawbox (100, 100, 500, 475, red)
    drawbox (128, 305, 470, 350, black)

    locate (2, 32)
    put "CALCULATOR" ..
    locate (16, 19)
    put "1" ..
    locate (16, 26)
    put "2" ..
    locate (16, 33)
    put "3" ..
    locate (13, 19)
    put "4" ..
    locate (13, 26)
    put "5" ..
    locate (13, 33)
    put "6" ..
    locate (10, 19)
    put "7" ..
    locate (10, 26)
    put "8" ..
    locate (10, 33)
    put "9" ..
    locate (10, 40)
    put "=" ..
    locate (16, 40)
    put "-" ..
    locate (13, 40)
    put "+" ..
    locate (13, 45)
    put "/" ..
    locate (13, 50)
    put "*" ..



    drawoval (148, 151, 12, 12, black)
    drawoval (205, 151, 12, 12, black)
    drawoval (262, 151, 12, 12, black)
    drawoval (148, 200, 12, 12, black)
    drawoval (205, 200, 12, 12, black)
    drawoval (262, 200, 12, 12, black)
    drawoval (148, 249, 12, 12, black)
    drawoval (205, 249, 12, 12, black)
    drawoval (262, 249, 12, 12, black)
    drawoval (316, 249, 20, 20, black)
    drawoval (316, 200, 13, 13, black)
    drawoval (316, 151, 13, 13, black)
    drawoval (356, 200, 13, 13, black)
    drawoval (396, 200, 13, 13, black)
    drawfillbox (285, 100, 286, 300, black)



 Mouse.Where (x, y, button)
    Text.Locate (22, 1)
    if button = 0 then
        put x : 0, "  ", y : 0, "  button up"
    else
        put x : 0, "  ", y : 0, "  button down"
    end if

if (button = 1) and ( x >= 137) and ( x = 142) and  ( y = 194) and (x = 142) and ( y = 251) and (x = 142) and ( y = 137) and (x = 190) and ( y = 194) and (x = 190) and ( y = 251) and (x = 190) and ( y = 137) and (x = 241) and ( y = 196) and (x < 210) and (y > 237) and (y < 259)  then
    locate (5, 25)
    num2 := 8
    put "", num2
end if
 
 
  if ( button = 1 ) and ( x >= 251) and (x = 241) and ( y 