Menu with procedures, syncing procedures with other procedures
Author |
Message |
vertozia
|
Posted: Wed Jan 17, 2007 9:39 pm Post subject: Menu with procedures, syncing procedures with other procedures |
|
|
hey there, here goes my problem "procedures's may only be declared at the program, module, or monitor level." I do not know how to correct this error due to my insufficient knowledge.lol. I attached a file (zip) with all the pictures and the .t file. i want to attach a calculator as my animation. but i get the above problem. Here it is:I do not wish to use my clculator for several reasons, but i chose to use someone elses for the example (credit goes to Paul Bian(from forum) for the calculator)
Here is his code, whcih im trying to merge with my menu.t file under the Animation section.
code: | %The simple calculator program
%By: Paul Bian
setscreen ("graphics:690;650")
var move, addx, count, addy, add, counter, counter2, counter3 : int := 0
var buttons : array 1 .. 9 of int := init (7, 8, 9, 4, 5, 6, 1, 2, 3)
var font := Font.New ("serif:18")
var numbers : array 1 .. 9 of int
var func, num : string := ""
var x, y, mouse : int := 0
var num1, num2 : real := 0
%****************Procedures and Crap***************************%
proc button
for a : 1 .. 9
drawbox (50 + addx, 344 - addy, 87 + addx, 381 - addy, black)
drawfillbox (51 + addx, 345 - addy, 86 + addx, 380 - addy, grey)
Draw.Text (intstr (buttons (a)), 56 + addx, 350 - addy, font, red)
addx += 40
counter += 1
if counter = 3 then
counter := 0
addy += 40
addx := 0
end if
end for
end button
proc calc
drawbox (46, 475, 256, 250, black)
drawbox (36, 485, 266, 240, black)
drawfill (41, 480, green, black)
drawfill (48, 473, blue, black)
drawfillbox (56, 435, 245, 400, grey)
Draw.Text ("Paul's Calculator", 56 + addx, 440, font, green)
end calc
proc box
drawbox (50 + addx, 344 - addy, 87 + addx, 381 - addy, black)
drawfillbox (51 + addx, 345 - addy, 86 + addx, 380 - addy, grey)
end box
proc funct
addx := 120
addy := 0
box
Draw.Text ("C", 56 + addx, 350 - addy, font, red)
addx += 40
box
Draw.Text ("=", 56 + addx, 350 - addy, font, red)
addx := 120
addy += 40
box
Draw.Text ("+", 56 + addx, 350 - addy, font, red)
addx += 40
box
Draw.Text ("-", 56 + addx, 350 - addy, font, red)
addx := 120
addy += 40
box
Draw.Text ("*", 56 + addx, 350 - addy, font, red)
addx += 40
box
Draw.Text ("/", 56 + addx, 350 - addy, font, red)
end funct
proc click
loop
Mouse.Where (x, y, mouse)
if x >= 50 and y >= 344 and x <= 87 and y <= 381 and mouse = 1 and
count = 0 then
num := "7"
count += 1
exit
elsif x >= 50 and y >= 344 and x <= 87 and y <= 381 and mouse = 1 and
count = 1 then
num += "7"
exit
elsif x >= 90 and y >= 344 and x <= 127 and y <= 381 and mouse = 1 and
count = 0 then
num := "8"
count += 1
exit
elsif x >= 90 and y >= 344 and x <= 127 and y <= 381 and mouse = 1 and
count = 1 then
num += "8"
exit
elsif x >= 130 and y >= 344 and x <= 167 and y <= 381 and mouse = 1 and
count = 0 then
num := "9"
count += 1
exit
elsif x >= 130 and y >= 344 and x <= 167 and y <= 381 and mouse = 1 and
count = 1 then
num += "9"
exit
elsif x >= 50 and y >= 304 and x <= 87 and y <= 341 and mouse = 1 and
count = 0 then
num := "4"
count += 1
exit
elsif x >= 50 and y >= 304 and x <= 87 and y <= 341 and mouse = 1 and
count = 1 then
num += "4"
exit
elsif x >= 90 and y >= 304 and x <= 127 and y <= 341 and mouse = 1 and
count = 0 then
num := "5"
count += 1
exit
elsif x >= 90 and y >= 304 and x <= 127 and y <= 341 and mouse = 1 and
count = 1 then
num += "5"
exit
elsif x >= 130 and y >= 304 and x <= 167 and y <= 341 and mouse = 1 and
count = 0 then
num := "6"
count += 1
exit
elsif x >= 130 and y >= 304 and x <= 167 and y <= 341 and mouse = 1 and
count = 1 then
num += "6"
exit
elsif x >= 50 and y >= 264 and x <= 87 and y <= 341 and mouse = 1 and
count = 0 then
num := "1"
count += 1
exit
elsif x >= 50 and y >= 264 and x <= 87 and y <= 341 and mouse = 1 and
count = 1 then
num += "1"
exit
elsif x >= 90 and y >= 264 and x <= 127 and y <= 341 and mouse = 1 and
count = 0 then
num := "2"
count += 1
exit
elsif x >= 90 and y >= 264 and x <= 127 and y <= 341 and mouse = 1 and
count = 1 then
num += "2"
exit
elsif x >= 130 and y >= 264 and x <= 167 and y <= 341 and mouse = 1 and
count = 0 then
num := "3"
count += 1
exit
elsif x >= 130 and y >= 264 and x <= 167 and y <= 341 and mouse = 1 and
count = 1 then
num += "3"
exit
elsif x >= 170 and y >= 344 and x <= 207 and y <= 381 and mouse = 1 and
counter3 = 1 then
func := "C"
counter2 := 1
count := 0
exit
elsif x >= 210 and y >= 344 and x <= 247 and y <= 381 and mouse = 1 and
count = 1 then
func := "="
counter2 := 1
count := 0
exit
elsif x >= 170 and y >= 304 and x <= 207 and y <= 341 and mouse = 1 and
count = 1 then
func := "+"
counter2 := 1
count := 0
exit
elsif x >= 210 and y >= 304 and x <= 247 and y <= 341 and mouse = 1 and
count = 1 then
func := "-"
counter2 := 1
count := 0
exit
elsif x >= 170 and y >= 264 and x <= 207 and y <= 301 and mouse = 1 and
count = 1 then
func := "*"
counter2 := 1
count := 0
exit
elsif x >= 210 and y >= 264 and x <= 247 and y <= 301 and mouse = 1 and
count = 1 then
func := "/"
counter2 := 1
count := 0
exit
end if
end loop
end click
proc reset
addx := 0
addy := 0
end reset
proc change
if counter2 = 0 then
num1 := strreal (num)
elsif counter2 = 1 and count = 1 then
num2 := strreal (num)
end if
end change
proc numb
Draw.Text (num, 56, 410, font, red)
end numb
proc math
if func not= "" and counter2 = 1 and count = 1 then
if func = "+" then
num1 := num1 + num2
counter3 := 1
elsif func = "-" then
num1 := num1 - num2
counter3 := 1
elsif func = "/" then
num1 := num1 div num2
counter3 := 1
elsif func = "*" then
num1 := num1 * num2
counter3 := 1
end if
end if
end math
proc equals
if func = "=" then
num := realstr (num1, 0)
end if
end equals
proc cl
if func = "C" and counter3 = 1 then
addx := 0
count := 0
addy := 0
counter := 0
counter2 := 0
counter3 := 0
func := ""
num := ""
num1 := 0
num2 := 0
cls
end if
end cl
%***********END of the Procedures and Stuff*************************%
%*****************MAIN PROGRAM********************%
loop
calc
button
funct
numb
click
delay (20)
change
reset
math
equals
cl
end loop
%*****************END MAIN PROGRAM*******************% |
AND THIS IS WHAT MY CODE LOOKS LIKE AFTER MERGED WITH THE CALCULATOR
code: | setscreen ("graphics:690,650")
var winID, picID : int %creates variables for windows and picture
var welcome, yeah, funny : string % creates variable for welcome page
var option : string %creates variable able to hold both numbers and letters
var mouse_x, mouse_y, button : int %creates variables able to control mouse
var font1, font2 : int %creates variables able to hold rounded number
var sel1, sel2, sel3, sel4, sel5, sel6, sel7, sel8, sel9, sel10 : int
var menuPic, tutPic, playPic, mpPic, quitPic, resultsPic : int
var cubePic, spherePic : int
cubePic := Pic.FileNew ("cube.jpg")
spherePic := Pic.FileNew ("sphere.jpg")
playPic := Pic.FileNew ("play.jpg")
mpPic := Pic.FileNew ("mp.jpg")
quitPic := Pic.FileNew ("quit.jpg")
resultsPic := Pic.FileNew ("results.jpg")
tutPic := Pic.FileNew ("tut.jpg")
% sets the welcome
welcome := "Hey, my name's Cindy!"
yeah := "Oooooh..you like my name dont you~~"
funny := "No....I'm not kidding...Cindy"
% create a new piture
% assigns the variable 'font' a font style to use
font1 := Font.New ("Palatino:24:bold,italic")
font2 := Font.New ("Comic Sans MS:12:bold")
%%%%%%%%%%%%%% Storing the Picture%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure animation
cls %clears screen
%The simple calculator program
%By: Paul Bian
setscreen ("graphics:690;650")
var move, addx, count, addy, add, counter, counter2, counter3 : int := 0
var buttons : array 1 .. 9 of int := init (7, 8, 9, 4, 5, 6, 1, 2, 3)
var font := Font.New ("serif:18")
var numbers : array 1 .. 9 of int
var func, num : string := ""
var x, y, mouse : int := 0
var num1, num2 : real := 0
%****************Procedures and Crap***************************%
proc button
for a : 1 .. 9
drawbox (50 + addx, 344 - addy, 87 + addx, 381 - addy, black)
drawfillbox (51 + addx, 345 - addy, 86 + addx, 380 - addy, grey)
Draw.Text (intstr (buttons (a)), 56 + addx, 350 - addy, font, red)
addx += 40
counter += 1
if counter = 3 then
counter := 0
addy += 40
addx := 0
end if
end for
end button
proc calc
drawbox (46, 475, 256, 250, black)
drawbox (36, 485, 266, 240, black)
drawfill (41, 480, green, black)
drawfill (48, 473, blue, black)
drawfillbox (56, 435, 245, 400, grey)
Draw.Text ("Paul's Calculator", 56 + addx, 440, font, green)
end calc
proc box
drawbox (50 + addx, 344 - addy, 87 + addx, 381 - addy, black)
drawfillbox (51 + addx, 345 - addy, 86 + addx, 380 - addy, grey)
end box
proc funct
addx := 120
addy := 0
box
Draw.Text ("C", 56 + addx, 350 - addy, font, red)
addx += 40
box
Draw.Text ("=", 56 + addx, 350 - addy, font, red)
addx := 120
addy += 40
box
Draw.Text ("+", 56 + addx, 350 - addy, font, red)
addx += 40
box
Draw.Text ("-", 56 + addx, 350 - addy, font, red)
addx := 120
addy += 40
box
Draw.Text ("*", 56 + addx, 350 - addy, font, red)
addx += 40
box
Draw.Text ("/", 56 + addx, 350 - addy, font, red)
end funct
proc click
loop
Mouse.Where (x, y, mouse)
if x >= 50 and y >= 344 and x <= 87 and y <= 381 and mouse = 1 and
count = 0 then
num := "7"
count += 1
exit
elsif x >= 50 and y >= 344 and x <= 87 and y <= 381 and mouse = 1 and
count = 1 then
num += "7"
exit
elsif x >= 90 and y >= 344 and x <= 127 and y <= 381 and mouse = 1 and
count = 0 then
num := "8"
count += 1
exit
elsif x >= 90 and y >= 344 and x <= 127 and y <= 381 and mouse = 1 and
count = 1 then
num += "8"
exit
elsif x >= 130 and y >= 344 and x <= 167 and y <= 381 and mouse = 1 and
count = 0 then
num := "9"
count += 1
exit
elsif x >= 130 and y >= 344 and x <= 167 and y <= 381 and mouse = 1 and
count = 1 then
num += "9"
exit
elsif x >= 50 and y >= 304 and x <= 87 and y <= 341 and mouse = 1 and
count = 0 then
num := "4"
count += 1
exit
elsif x >= 50 and y >= 304 and x <= 87 and y <= 341 and mouse = 1 and
count = 1 then
num += "4"
exit
elsif x >= 90 and y >= 304 and x <= 127 and y <= 341 and mouse = 1 and
count = 0 then
num := "5"
count += 1
exit
elsif x >= 90 and y >= 304 and x <= 127 and y <= 341 and mouse = 1 and
count = 1 then
num += "5"
exit
elsif x >= 130 and y >= 304 and x <= 167 and y <= 341 and mouse = 1 and
count = 0 then
num := "6"
count += 1
exit
elsif x >= 130 and y >= 304 and x <= 167 and y <= 341 and mouse = 1 and
count = 1 then
num += "6"
exit
elsif x >= 50 and y >= 264 and x <= 87 and y <= 341 and mouse = 1 and
count = 0 then
num := "1"
count += 1
exit
elsif x >= 50 and y >= 264 and x <= 87 and y <= 341 and mouse = 1 and
count = 1 then
num += "1"
exit
elsif x >= 90 and y >= 264 and x <= 127 and y <= 341 and mouse = 1 and
count = 0 then
num := "2"
count += 1
exit
elsif x >= 90 and y >= 264 and x <= 127 and y <= 341 and mouse = 1 and
count = 1 then
num += "2"
exit
elsif x >= 130 and y >= 264 and x <= 167 and y <= 341 and mouse = 1 and
count = 0 then
num := "3"
count += 1
exit
elsif x >= 130 and y >= 264 and x <= 167 and y <= 341 and mouse = 1 and
count = 1 then
num += "3"
exit
elsif x >= 170 and y >= 344 and x <= 207 and y <= 381 and mouse = 1 and
counter3 = 1 then
func := "C"
counter2 := 1
count := 0
exit
elsif x >= 210 and y >= 344 and x <= 247 and y <= 381 and mouse = 1 and
count = 1 then
func := "="
counter2 := 1
count := 0
exit
elsif x >= 170 and y >= 304 and x <= 207 and y <= 341 and mouse = 1 and
count = 1 then
func := "+"
counter2 := 1
count := 0
exit
elsif x >= 210 and y >= 304 and x <= 247 and y <= 341 and mouse = 1 and
count = 1 then
func := "-"
counter2 := 1
count := 0
exit
elsif x >= 170 and y >= 264 and x <= 207 and y <= 301 and mouse = 1 and
count = 1 then
func := "*"
counter2 := 1
count := 0
exit
elsif x >= 210 and y >= 264 and x <= 247 and y <= 301 and mouse = 1 and
count = 1 then
func := "/"
counter2 := 1
count := 0
exit
end if
end loop
end click
proc reset
addx := 0
addy := 0
end reset
proc change
if counter2 = 0 then
num1 := strreal (num)
elsif counter2 = 1 and count = 1 then
num2 := strreal (num)
end if
end change
proc numb
Draw.Text (num, 56, 410, font, red)
end numb
proc math
if func not= "" and counter2 = 1 and count = 1 then
if func = "+" then
num1 := num1 + num2
counter3 := 1
elsif func = "-" then
num1 := num1 - num2
counter3 := 1
elsif func = "/" then
num1 := num1 div num2
counter3 := 1
elsif func = "*" then
num1 := num1 * num2
counter3 := 1
end if
end if
end math
proc equals
if func = "=" then
num := realstr (num1, 0)
end if
end equals
proc cl
if func = "C" and counter3 = 1 then
addx := 0
count := 0
addy := 0
counter := 0
counter2 := 0
counter3 := 0
func := ""
num := ""
num1 := 0
num2 := 0
cls
end if
end cl
%***********END of the Procedures and Stuff*************************%
%*****************MAIN PROGRAM********************%
loop
calc
button
funct
numb
click
delay (20)
change
reset
math
equals
cl
end loop
%*****************END MAIN PROGRAM*******************%
loop
% Displays a Menu button
drawbox (570, 10, 620, 30, white)
Font.Draw ("Menu", 575, 15, font2, brightgreen)
mousewhere (mouse_x, mouse_y, button)
% Checks if Menu is selected
if (button = 1) and (mouse_x > 570) and (mouse_x < 620) and (mouse_y > 10) and (mouse_y < 30) then
exit % Returns to menu
end if
end loop
end animation
procedure lesson2
cls
Font.Draw ("Welcome to Lesson 2", 85, 350, font1, brightgreen)
loop
% Displays a Menu button
drawbox (570, 10, 620, 30, white)
Font.Draw ("Menu", 575, 15, font2, white)
mousewhere (mouse_x, mouse_y, button)
% Checks if Menu is selected
if (button = 1) and (mouse_x > 570) and (mouse_x < 620) and (mouse_y > 10) and (mouse_y < 30) then
exit % Returns to menu
end if
end loop
end lesson2
procedure lesson
cls %clear screen
%BASICS
colorback (black)
cls
color (yellow)
put "AREA"
put skip
color (brightred)
put "INTRODUCTION"
color (brightgreen)
put "This tutorial will teach you how to calculate the area of any shape or object"
put "Everysingle object or shape has an area regarldess if it it 3d, 2d, circular,"
put "oval, triangular, of its shape or size. This tutorial will also cover math "
put "simple math tricks that will help you with your math experiences. "
put skip
color (brightred)
put "BASICS "
color (brightgreen)
put "Among the many shapes and objects, it is easiest to find an area or a rectangle "
put "or a triangle"
put skip
color (brightred)
put "RECTANGLES"
color (brightgreen)
put "To find the area of a rectangle, a very simple forumla is required: LxW."
put "It specifies (length x width)."
put skip
color (brightred)
put "TRIANGLES"
color (brightgreen)
put "This shape once again requires a very simple forumla. Once agian you will need the"
put "lenght of the side, and the width of the triangle. Then you will multiply the two"
put "numbers just as if you were calculating the area of a rectangle (length x width), "
put "but this time divide it by two, so the final formula will look like this: LxW /2"
loop
% Displays Lesson 2
drawbox (340, 10, 440, 30, white)
Font.Draw ("Next Lesson", 345, 15, font2, white)
mousewhere (mouse_x, mouse_y, button)
% Checks if Menu is selected
if (button = 1) and (mouse_x > 340) and (mouse_x < 420) and (mouse_y > 10) and (mouse_y < 30) then
lesson2 % Continue with lesson 2
end if
% Displays a Menu button
drawbox (570, 10, 620, 30, white)
Font.Draw ("Menu", 575, 15, font2, white)
mousewhere (mouse_x, mouse_y, button)
% Checks if Menu is selected
if (button = 1) and (mouse_x > 570) and (mouse_x < 620) and (mouse_y > 10) and (mouse_y < 30) then
exit % Returns to menu
end if
end loop
end lesson
procedure test
cls
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%TEST AREA%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%QUESTION 1%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
cls
color (yellow)
put " MULTIPLE CHOICES "
put skip
color (brightgreen)
put " Question 1 - What is the area"
put " of a square with a lenght of 4 cm"
put " 7cm and a width of 4cm?"
put skip
Draw.Box (350, 600, 543, 550, white)
put " 7 cm"
color (brightred)
put " 1) 28cm"
put " 2) 56m "
put " 3) 17cm"
put " 4) 17m"
put skip
color (brightpurple)
put "Answer:" ..
color (77)
get sel1
if sel1 = 1 then
put "YOU ARE CORRECT!"
delay (500)
elsif sel1 = 2 or sel1 = 3 or sel1 = 4 then
put "YOU ARE INCORRECT!"
delay (500)
else
put "PLEASE MAKE A CHOICE"
delay (500)
end if
exit when sel1 = 1
end loop
delay (300)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%QUESTION 2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
cls
color (yellow)
put " MULTIPLE CHOICES "
put skip
color (brightgreen)
put " Question 2 - What is the area"
put " of a square with a lenght of 7dm"
put " 12dm and a width of 7dm?"
put skip
color (brightred)
put " 1) 99km"
put " 2) 75mm "
put " 3) 84dm"
put " 4) 5nm"
color (brightgreen)
put skip
Draw.Box (370, 600, 600, 450, white)
put " 12dm"
color (brightpurple)
put "Answer:" ..
color (77)
get sel2
if sel2 = 3 then
put "YOU ARE CORRECT!"
delay (500)
elsif sel1 = 1 or sel2 = 2 or sel2 = 4 then
put "YOU ARE INCORRECT!"
delay (500)
else
put "PLEASE MAKE A CHOICE"
delay (500)
end if
exit when sel2 = 3
end loop
delay (300)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%QUESTION 3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
cls
color (yellow)
put " MULTIPLE CHOICES "
put skip
color (brightgreen)
put " Question 3 - What is the area"
put " of a triangle with a lenght of"
put " 7km and a width of 5km?"
put skip
color (brightred)
put " 1) 99km"
put " 2) 75mm "
put " 3) 84dm"
put " 4) 35km"
color (brightgreen)
put " 7km"
put skip
put skip
Draw.Line (300, 400, 400, 515, white)
Draw.Line (400, 515, 400, 400, white)
Draw.Line (399, 400, 300, 400, white)
put " 5km"
color (brightpurple)
put "Answer:" ..
color (77)
get sel3
if sel3 = 4 then
put "YOU ARE CORRECT!"
delay (500)
elsif sel3 = 2 or sel3 = 1 or sel3 = 3 then
put "YOU ARE INCORRECT!"
delay (500)
else
put "PLEASE MAKE A CHOICE"
delay (500)
end if
exit when sel3 = 4
end loop
delay (300)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%QUESTION 4%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
cls
color (yellow)
put " MULTIPLE CHOICES "
put skip
color (brightgreen)
put " Question 4 - What is the area"
put " of a square with a lenght of"
put " 1km and a width of 7000m?"
put " 1km"
color (brightred)
put " 1) 7km"
put " 2) 70km "
put " 3) 7000m"
put " 4) both 1) and 2)"
color (brightgreen)
put skip
Draw.Box (370, 600, 600, 450, white)
put " 7000m"
color (brightpurple)
put "Answer:" ..
color (77)
get sel4
if sel4 = 4 then
put "YOU ARE CORRECT!"
delay (500)
elsif sel4 = 2 or sel4 = 1 or sel4 = 3 then
put "YOU ARE INCORRECT!"
delay (500)
else
put "PLEASE MAKE A CHOICE"
delay (500)
end if
exit when sel4 = 4
end loop
delay (300)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%QUESTION 5%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
cls
color (yellow)
put " MULTIPLE CHOICES "
put skip
color (brightgreen)
put " Question 5 - What is the volume"
put " of a cube with a side of 10cm?"
put skip
put ""
color (brightred)
put " 1) 1000cm cubed"
put " 2) 100m squared"
put " 3) 10m cubed"
put " 4) both 1) and 3)"
color (brightgreen)
put ""
put " 10cm"
put ""
put ""
Pic.Draw (cubePic, 450, 400, picCopy)
color (brightpurple)
put "Answer:" ..
color (77)
get sel5
if sel5 = 4 then
put "YOU ARE CORRECT!"
delay (500)
elsif sel5 = 2 or sel5 = 1 or sel5 = 3 then
put "YOU ARE INCORRECT!"
delay (500)
else
put "PLEASE MAKE A CHOICE"
delay (500)
end if
exit when sel5 = 4
end loop
delay (300)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%QUESTION 6%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
cls
color (yellow)
put " MULTIPLE CHOICES "
put skip
color (brightgreen)
put " Question 6 - What is the volume"
put " of a box with side.1 2cm, side.2 "
put " with 5cm and side.3 with 9cm ? 9cm"
put skip
put ""
color (brightred)
put " 1) 90cm cubed"
put " 2) 87mm squared"
put " 3) 765m cubed"
put " 4) None of the above"
color (brightgreen)
put " 2cm"
put " "
put " "
put " 5cm"
Pic.Draw (cubePic, 450, 390, picCopy)
put ""
color (brightpurple)
put "Answer:" ..
color (77)
get sel6
if sel6 = 1 then
put "YOU ARE CORRECT!"
delay (500)
elsif sel6 = 2 or sel6 = 4 or sel6 = 3 then
put "YOU ARE INCORRECT!"
delay (500)
else
put "PLEASE MAKE A CHOICE"
delay (500)
end if
exit when sel6 = 1
end loop
delay (300)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%QUESTION 7%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
cls
color (yellow)
put " MULTIPLE CHOICES "
put skip
color (brightgreen)
put " Question 6 - What is the volume"
put " of a sphere with a radius of 13dm?"
put " Hint: V= 4/3x(pie)x r-squared"
put skip
put ""
color (brightred)
put " 1) 130dm cubed"
put " 2) 130cm squared"
put " 3) 130cm cubed"
put " 4) 130dm squared"
color (brightgreen)
put " 13dm"
put ""
Pic.Draw (spherePic, 450, 410, picCopy)
color (brightpurple)
put "Answer:" ..
color (77)
get sel7
if sel7 = 2 then
put "YOU ARE CORRECT!"
delay (500)
elsif sel7 = 4 or sel7 = 1 or sel7 = 3 then
put "YOU ARE INCORRECT!"
delay (500)
else
put "PLEASE MAKE A CHOICE"
delay (500)
end if
exit when sel7 = 2
end loop
delay (300)
loop
% Displays a Menu button
drawbox (570, 10, 620, 30, white)
Font.Draw ("Menu", 575, 15, font2, white)
mousewhere (mouse_x, mouse_y, button)
% Checks if Menu is selected
if (button = 1) and (mouse_x > 570) and (mouse_x < 620) and (mouse_y > 10) and (mouse_y < 30) then
exit % Returns to menu
end if
end loop
end test
procedure score
cls %clears screen
Font.Draw ("You got a score of ", 85, 350, font1, white)
loop
% Displays a Menu button
drawbox (570, 10, 620, 30, white)
Font.Draw ("Menu", 575, 15, font2, brightgreen)
mousewhere (mouse_x, mouse_y, button)
% Checks if Menu is selected
if (button = 1) and (mouse_x > 570) and (mouse_x < 620) and (mouse_y > 10) and (mouse_y < 30) then
exit % Returns to menu
end if
end loop
end score
procedure leave
cls
Font.Draw ("Thank you and Goodbye!!!", 85, 350, font1, brightgreen)
delay (3000)
cls %clear screen
Window.Close (winID) % Close the window
end leave
%%%%%%%%%%%%%%%% determines if the button is clicked %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5%%
colorback (black)
%The Welcoming Beginning (fade - like)
for i : 16 .. 31
color (i)
Font.Draw (welcome, 200, 200, font1, i)
delay (50)
cls
exit when welcome = ""
end for
for decreasing i : 31 .. 16
color (i)
Font.Draw (welcome, 200, 200, font1, i)
delay (50)
cls
exit when welcome = ""
end for
for i : 16 .. 31
color (i)
Font.Draw (yeah, 50, 200, font1, i)
delay (50)
cls
exit when yeah = ""
end for
for decreasing i : 31 .. 16
color (i)
Font.Draw (yeah, 50, 200, font1, i)
delay (50)
cls
exit when yeah = ""
end for
for i : 16 .. 31
color (i)
Font.Draw (funny, 200, 200, font1, i)
delay (50)
cls
exit when funny = ""
end for
for decreasing i : 31 .. 16
color (i)
Font.Draw (funny, 200, 200, font1, i)
delay (50)
cls
exit when funny = ""
end for
%main program begins here.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function click () : string
var mousex, mousey, button : int
loop
mousewhere (mousex, mousey, button)
if (button = 1) and (mousex > 499) and (mousex < 650) and (mousey >
274) and (mousey < 305) then % if first button is clicked
result "animation" % processes the first choice
elsif (button = 1) and (mousex > 399) and (mousex < 550) and (mousey
> 224) and (mousey < 255) then % if second button is clicked
result "lesson" % processes the second choice
elsif (button = 1) and (mousex > 299) and (mousex < 450) and (mousey
> 174) and (mousey < 205) then % if third button is clicked
result "test" % processes the third choice
elsif (button = 1) and (mousex > 199) and (mousex < 350) and (mousey
> 125) and (mousey < 200) then % if fourth button is clicked
result "score" % processes the fourth choice
elsif (button = 1) and (mousex > 99) and (mousex < 70) and (mousey
> 65) and (mousey < 85) then % if fifth button is clicked
result "leave" % processes the fifth choice
elsif (button = 1) then
result "invalid"
end if
end loop
end click
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
cls %clears screen
Font.Draw ("Select something.....", 100, 380, font2, white)
Draw.Box (499, 305, 650, 274, white)
Pic.Draw (playPic, 500, 275, picCopy)
Draw.Box (399, 255, 550, 224, white)
Pic.Draw (tutPic, 400, 225, picCopy)
Draw.Box (299, 205, 450, 174, white)
Pic.Draw (mpPic, 300, 175, picCopy)
Draw.Box (199, 155, 350, 124, white)
Pic.Draw (resultsPic, 200, 125, picCopy)
option := click () % Menu button clicking choice
if option = "animation" then
cls
animation
elsif option = "lesson" then
cls
lesson
elsif option = "test" then
cls
test
elsif option = "score" then
cls
score
elsif option = "leave" then
leave
exit
else %if choice is invalid
cls
Font.Draw ("It is an invalid input, please try again.", 370, 70, font2, white) %tells user its invalid
end if
delay (100) %delays 3 seconds
end loop %goes back to the top of the menu part
Font.Free (font1)
Font.Free (font2)
Pic.Free (picID)
|
Description: |
|
![](http://compsci.ca/v3/pafiledb/images/icons/clip.gif) Download |
Filename: |
math project..rar |
Filesize: |
21.44 KB |
Downloaded: |
72 Time(s) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Expirant
|
Posted: Wed Jan 17, 2007 10:54 pm Post subject: Re: Menu with procedures, syncing procedures with other procedures |
|
|
Hey,
From what I can see (didn't download the .zip), at least one of the reasons you're having the problem is you're declaring a procedure inside a procedure. That's illegal in Turing. The procedure 'animation' for some reason has other procedures declared inside it, and that's causing the program not to work.
If you really need to declare procedures inside a procedure, it sounds like you need to look at Classes (don't have link, sorry. Check out the Turing Walkthrough and read Cervantes great tutorial on 'em).
So, instead of saying:
code: | procedure animation
procedure foo
end foo
end animation
|
You have to do:
code: | procedure animation
--execute animation
end animation
procedure foo
--execute foo
end foo
|
There's really no reason or need for declaring a procedure inside a procedure. Check out classes though if you really think you need to do something like that.
Hope that helps somewhat,
Expirant
|
|
|
|
|
![](images/spacer.gif) |
vertozia
|
Posted: Wed Jan 17, 2007 11:29 pm Post subject: RE:Menu with procedures, syncing procedures with other procedures |
|
|
it did clear thing up for me, but right now, and of previous tries, i cannot execture a procedure before its ended.
|
|
|
|
|
![](images/spacer.gif) |
Expirant
|
Posted: Thu Jan 18, 2007 11:06 am Post subject: Re: Menu with procedures, syncing procedures with other procedures |
|
|
Sorry, when I said '--execute procedure' I meant the contents of that procedure.
So:
code: |
procedure animation
contents of animation
end animation
procedure foo
contents of foo
end foo
animation
foo
|
You can only call a procedure after it had ended, that's right.
|
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Thu Jan 18, 2007 12:37 pm Post subject: Re: Menu with procedures, syncing procedures with other procedures |
|
|
I'm not too sure what's going on here, so I'll state several facts, and I think that will clearr up the issue.
In Turing, you cannot declare a procedure within another prcoedure. The same goes for declaring functions within functions. It's actually rather bad that this sort of behaviour isn't allowed, because ideally declaring a procedure within a procedure would mean that the inner procedure is local to the outer procedure--it doesn't exist outside the outer procedure. But, alas, we can't do this in Turing.
Expirant wrote: You can only call a procedure after it had ended, that's right.
On the contrary, a procedure can call itself. This is known as recursion. Check the Turing Walkthrough for a link to the recursion tutorial. Here's a basic example--a recursive function that computes the factorial of a number:
code: |
function factorial (n : int) : int
if n = 0 or n = 1 then
result 1
else
result n * factorial (n - 1)
end if
end factorial
|
So factorial (5) would produce 120, which is 5 * 4 * 3 * 2 * 1.
procedures can be mutually recursive. That is, procedure A calls procedure B, and then B calls A. To do this, we need to forward declare them.
code: |
forward procedure A
forward procedure B
procedure A
put "I'm running A"
B
end A
procedure B
put "I'm running B"
A
end B
A
|
output wrote:
I'm running A
I'm running B
I'm running A
I'm running B
I'm running A
I'm running B
I'm running A
I'm running B
... et cetera
|
|
|
|
|
![](images/spacer.gif) |
vertozia
|
Posted: Thu Jan 18, 2007 3:26 pm Post subject: Re: Menu with procedures, syncing procedures with other procedures |
|
|
Indeed it did clear things up for me, and you cleared up recursion for me, i did fix the problem by using code order. There fore i defined the procedures outside of the procedures, then i executed them within the procedures.
|
|
|
|
|
![](images/spacer.gif) |
Expirant
|
Posted: Thu Jan 18, 2007 10:14 pm Post subject: Re: Menu with procedures, syncing procedures with other procedures |
|
|
Wow, recursion completely slipped my mind. Thanks for mentioning that Cervantes. Good luck with your program Vertozia.
|
|
|
|
|
![](images/spacer.gif) |
vertozia
|
Posted: Fri Jan 19, 2007 2:11 pm Post subject: RE:Menu with procedures, syncing procedures with other procedures |
|
|
thanks a lot, i have other issues, but my basic math program is done, i want to add effects, make my own calculator, and make a rotating 3d cube or so.
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
lord
|
Posted: Sun Jan 21, 2007 2:44 pm Post subject: Re: Menu with procedures, syncing procedures with other procedures |
|
|
insteed of useing recursion y dont u just declear all the proc and funt at the top and the call upon them in ur main program?
|
|
|
|
|
![](images/spacer.gif) |
Clayton
![](http://compsci.ca/v3/uploads/user_avatars/1718239683472e5c8d7e617.jpg)
|
Posted: Sun Jan 21, 2007 3:42 pm Post subject: Re: Menu with procedures, syncing procedures with other procedures |
|
|
he does, but he has to have a procedure call another procedure, and that other procedure calls the procedure that called it (mutual recursion).
|
|
|
|
|
![](images/spacer.gif) |
vertozia
|
Posted: Sun Jan 21, 2007 8:54 pm Post subject: RE:Menu with procedures, syncing procedures with other procedures |
|
|
thats what i said, i had them defined, then i executed them in my main program
|
|
|
|
|
![](images/spacer.gif) |
|
|