Computer Science Canada Turing GUI help needed |
Author: | compnerd101 [ Thu Dec 29, 2011 9:32 pm ] |
Post subject: | Turing GUI help needed |
I am creating a program that makes rectangles on the page at random locations when a button labeled "Draw Rectangle is pressed" The following is my code _________________________________________________________________________________ import GUI procedure rectangle(startX:int, startY:int, endX:int, endY:int, color:int) put "Please enter how far to the right you wisk to start the rectangle:" .. get startX put "Please enter how far from the botttom you wish to start the rectangle:" .. get startY put "Please enter the width of the rectangle to draw:".. get endx put "Please enter the height of the rectangle to draw:".. get endY put "Please enter the color of the rectangle (0-255 are valid options):".. get color end rectangle put "Press the draw button to create a rectangle of your choice." GUI.CreateButton(30,15,5,"Draw Rectangle", rectangle) ___________________________________________________________________________ When i try to run the code i get the following errors: -In the procedure "rectangle", on each line when i ask for user input, i get the error, "illegal get item" I've tried for hours to fix, thinking that it was a matter of syntax, but to no avail. -In the last line of code where there is the GUI.Createbutton, i get the error, "Arguement is of wrong type", with the rectangle reference highlighted To try and solve this ive tried to make the switch around the variable types in the rectangle proc, but again, it didnt work |
Author: | Tony [ Thu Dec 29, 2011 9:38 pm ] |
Post subject: | RE:Turing GUI help needed |
A hint for you: you are calling procedure "rectangle", but the one declared (and thus expected) is "rectangle(int,int,int,int,int)" |
Author: | compnerd101 [ Thu Dec 29, 2011 11:35 pm ] |
Post subject: | Re: RE:Turing GUI help needed |
Tony @ Thu Dec 29, 2011 9:38 pm wrote: A hint for you:
you are calling procedure "rectangle", but the one declared (and thus expected) is "rectangle(int,int,int,int,int)" i tried fixing by adding the space, but again, to no avail.and even if that were the case, wouldn't there be an error at the end procedure line, since the compiler would expect the statement to be "end rectangle(int,int,int,int,int)", instead of just "end rectangle"? |
Author: | Tony [ Thu Dec 29, 2011 11:50 pm ] | ||
Post subject: | RE:Turing GUI help needed | ||
I was talking about
|
Author: | Dreadnought [ Fri Dec 30, 2011 12:07 am ] | ||||||
Post subject: | Re: Turing GUI help needed | ||||||
When we declare a procedure like this
We are creating a procedure that expects 4 parameters (integers in this case). Parameters are values that the procedure requires in order to run. If we wanted to call this procedure we would do so in this way:
We have given the procedure four arguments to satisfy the procedure's parameters. (These arguments must all be integers in this case) These arguments can now be used as constant values in the body of the procedure. Since they are constants we cannot change their value in any way. If we wanted to use them as variables we would declare our procedure like so:
But this is not what you want. To add to Tony's hint, remember that get changes the value of the variable it is given. Also, you can declare variables within a procedure in the same way that you would outside of a procedure, just remember that they will only exist within the procedure they were created in. |
Author: | compnerd101 [ Fri Dec 30, 2011 12:49 am ] |
Post subject: | RE:Turing GUI help needed |
i got most of the program working. dreadnought, thanks for telling me i could declare variables in proc's same as out of. thats what was messing me up. here is an updated version of my code: _____________________________________ import GUI procedure Rectangle var startX, startY, endX, endY, colors : int put "Please enter how far to the right you wish to start the rectangle:" get startX put "Please enter how far from the botttom you wish to start the rectangle:" get startY put "Please enter the width of the rectangle to draw:" get endX put "Please enter the height of the rectangle to draw:" get endY put "Please enter the color of the rectangle (0-255 are valid options):" get colors Draw.Box(startX,startY,endX,endY, colors) GUI.Refresh end Rectangle put "Press the draw button to create a rectangle of your choice." var drawRec : int := GUI.CreateButton (50, 15, 5, "Draw Rectangle", Rectangle) var Quit:int:= GUI.CreateButton (200, 15,5, "Quit", GUI.Quit) loop exit when GUI.ProcessEvent end loop _____________________________________ now, another question, if i may: what purpose does the last 3 lines of code serve? i just copy pasted it from the holtsoft doc because it says it is common to use it to get widgets working. |
Author: | Tony [ Fri Dec 30, 2011 1:25 am ] | ||
Post subject: | RE:Turing GUI help needed | ||
without it, the buttons are just drawings that do nothing (since no button code is running). You have only a single thread, so your program goes into that "infinite loop" (until quit), and control is given to the button code. Another interesting way to look at it, is if you replace it with
|
Author: | compnerd101 [ Fri Dec 30, 2011 1:55 am ] |
Post subject: | RE:Turing GUI help needed |
ok. i realize this is becoming more of a question thread then anything else, but is there a "cls when" type of command in turing, where statements dissapeer when a certain condition is met? |
Author: | Tony [ Fri Dec 30, 2011 2:06 am ] | ||
Post subject: | RE:Turing GUI help needed | ||
keep in mind that you can't just throw random pieces of "if-this-than-that" code into a pile, and expect anything to work. There's a linear control flow -- one statement at a time. |
Author: | compnerd101 [ Fri Dec 30, 2011 2:08 am ] |
Post subject: | RE:Turing GUI help needed |
ok thank you. |