Posted: Sat May 24, 2008 11:38 pm Post subject: How to turn back?
I am doing a encyclepedia project and got a problem. I write the first page, and when I turn to second page I don't know how to turn back to the first page. Do I have to copy the whole procedure at first page or you guys have a better way to da that?
Sponsor Sponsor
TheGuardian001
Posted: Sat May 24, 2008 11:41 pm Post subject: Re: How to turn back?
it depends on how you're writing the code for each page. If you're just putting everything in nested loops (not recommended if its gonna be big) then just exit until you're back in the first page.
the easiest way to do it would be to make each page a procedure. then you just need to call the procedure, instead of copy pasting tons of lines of code.
jasonlin6868
Posted: Sun May 25, 2008 1:31 pm Post subject: RE:How to turn back?
so how do I do that? var the whole procedure? I am really fustrated. It's due Tuesday! Man is my summative! I am doom!
Sean
Posted: Sun May 25, 2008 1:35 pm Post subject: Re: How to turn back?
Turing:
procedure Example
%Your Code end Example
procedure Example2
%Your Code if return_answer ="Y"then cls
Example
endif end Example2
%Main Program
Example
Example2
Works like this.
jasonlin6868
Posted: Sun May 25, 2008 2:37 pm Post subject: RE:How to turn back?
I am using mousewhere button. So when I click the back button will turn back and forward button will turn forware, So how can I put the procedure within the loop?
jasonlin6868
Posted: Sun May 25, 2008 3:14 pm Post subject: RE:How to turn back?
var yesNo : string (1)
var font := Font.New ("TimesNewRoman:36")
var text := "Shark!"
var width := Font.Width (text, font)
var x, y, b : int
var mx, my, mb : int
var lesson := "Lesson"
procedure Menue
%shark screen
setscreen ("graphics:909;663")
Pic.ScreenLoad ("shark.BMP", 0, 0, picCopy)
%Button
drawbox (310, 240, 600, 420, black)
locate (33, 16)
Font.Draw (text, round (maxx / 2 - width / 2), maxy div 2, font, black)
colour (black)
colourback (white)
locate (maxrow, 1)
put "Press Shark button to do lesson"
put "Press QUiz button to do quiz"
end Menue
%Lesson 1
procedure Lesson
setscreen ("graphics:642;402")
colourback (white)
colour (black)
Pic.ScreenLoad ("rightarrow.BMP", 560, 0, picCopy)
Font.Draw (lesson, 1, 360, font, red)
locate (4, 1)
colour (blue)
put " Defination: Sharks (superorder Selachimorpha) are a type of fish with a full"
put "cartilaginous skeleton and a streamlined body." ..
put ""
put " They respire with the use of five to seven gill slits. Sharks have a covering of dermal denticles that protect their skin from damage and parasites and"
put "improve fluid dynamics; they also have replaceable teeth." ..
Pic.ScreenLoad ("Sharks part.BMP", 80, 25, picCopy)
Font.Draw ("Page 1/3", 0, 0, font, red)
Pic.ScreenLoad ("rightarrow.BMP", 560, 0, picCopy)
end Lesson
procedure Lesson2
colourback (red)
cls
Font.Draw ("Shark's Teeth", 1, 360, font, blue)
locate (4, 1)
put " The teeth of carnivorous sharks are not attached to the jaw, but embedded in "
put "the flesh, and in many species are constantly replaced throughout the " ..
put " shark's life; some sharks can lose 30,000 teeth in a lifetime." ..
Pic.ScreenLoad ("rightarrow.BMP", 560, 0, picCopy)
Pic.ScreenLoad ("leftarrow.BMP", 450, 0, picCopy)
Font.Draw ("Page 2/3", 0, 0, font, blue)
Pic.ScreenLoad ("shark_teeth.JPG", 220, 60, picCopy)
%arrow
end Lesson2
procedure Lesson3
Font.Draw ("Page 3/3", 0, 0, font, blue)
Pic.ScreenLoad ("rightarrow.BMP", 560, 0, picCopy)
Pic.ScreenLoad ("leftarrow.BMP", 450, 0, picCopy)
Font.Draw ("Lifespan", 1, 360, font, yellow)
put
"Maximum shark ages vary by species. Most sharks live for 20 to 30 years, while the spiny dogfish lives a record lifespan of more than 100 years. [12] Whale sharks (Rhincodon typus) have been hypothesized to also live over 100 years."
end Lesson3
Menue
loop
Mouse.Where (mx, my, mb)
if mx >= 310 and mx <= 600 and my >= 240 and my <= 420 and mb = 1 then
Lesson
elsif mx >= 550 and mx <= maxx and my >= 0 and my <= 90 and mb = 1 then
cls
Lesson2
elsif mx >= 450 and mx <= maxx - 105 and my >= 0 and my <= 90 and mb = 1 then
cls
Lesson
elsif mx >= 550 and mx <= maxx and my >= 0 and my <= 90 and mb = 1 then
cls
Lesson3
elsif mx >= 450 and mx <= maxx - 105 and my >= 0 and my <= 90 and mb = 1 then
cls
Lesson2
end if
end loop
"Can't do lesson 3 and turn back to lesson 2"
richcash
Posted: Sun May 25, 2008 3:40 pm Post subject: Re: How to turn back?
One way is to put all your procedures in an array of procedures. Then keep track of which page you're on with a counter and use it to select the appropriate procedure from the array. It will work since all of your procedures have the same parameters (which is no parameters).
code:
proc page1
end page1
proc page2
end page2
var pages : array 1 .. 2 of proc p
var page_num := 0
loop
if forward button is clicked then
page_num += 1
pages(page_num)
elsif back button is clicked then
page_num -= 1
pages(page_num)
end if
end loop
jasonlin6868
Posted: Sun May 25, 2008 4:25 pm Post subject: RE:How to turn back?
It's not working. I change the mousewhere part, but when I click forward button, it didn't go forward. Said the varible has no value. What to do???!!!
Menue
var page : array 1 .. 3 of procedure page
var page_num := 0
loop
Mouse.Where (mx, my, mb)
if mx >= 310 and mx <= 600 and my >= 240 and my <= 420 and mb = 1 then
page1
elsif mx >= 550 and mx <= maxx and my >= 0 and my <= 90 and mb = 1 then
page_num += 1
pages (page_num)
elsif mx >= 450 and mx <= maxx - 105 and my >= 0 and my <= 90 and mb = 1 then
page_num -= 1
pages (page_num)
end if
end loop
Sponsor Sponsor
richcash
Posted: Sun May 25, 2008 4:40 pm Post subject: Re: How to turn back?
You have to assign values to your array of procedures.
Posted: Sun May 25, 2008 5:23 pm Post subject: RE:How to turn back?
It works, but didn't get a very good result. You can try it yourself.
-------------------------------------------------------
var yesNo : string (1)
var font := Font.New ("TimesNewRoman:36")
var text := "Shark!"
var width := Font.Width (text, font)
var x, y, b : int
var mx, my, mb : int
var lesson := "Lesson"
procedure Menue
%shark screen
setscreen ("graphics:909;663")
Pic.ScreenLoad ("shark.BMP", 0, 0, picCopy)
%Button
drawbox (310, 240, 600, 420, black)
locate (33, 16)
Font.Draw (text, round (maxx / 2 - width / 2), maxy div 2, font, black)
colour (black)
colourback (white)
locate (maxrow, 1)
put "Press Shark button to do lesson"
put "Press QUiz button to do quiz"
end Menue
%Lesson 1
proc page1
setscreen ("graphics:642;402")
colourback (white)
colour (black)
Pic.ScreenLoad ("rightarrow.BMP", 560, 0, picCopy)
Font.Draw (lesson, 1, 360, font, red)
locate (4, 1)
colour (blue)
put " Defination: Sharks (superorder Selachimorpha) are a type of fish with a full"
put "cartilaginous skeleton and a streamlined body." ..
put ""
put " They respire with the use of five to seven gill slits. Sharks have a covering of dermal denticles that protect their skin from damage and parasites and"
put "improve fluid dynamics; they also have replaceable teeth." ..
Pic.ScreenLoad ("Sharks part.BMP", 80, 25, picCopy)
Font.Draw ("Page 1/3", 0, 0, font, red)
Pic.ScreenLoad ("rightarrow.BMP", 560, 0, picCopy)
end page1
procedure page2
colourback (red)
cls
Font.Draw ("Shark's Teeth", 1, 360, font, blue)
locate (4, 1)
put " The teeth of carnivorous sharks are not attached to the jaw, but embedded in "
put "the flesh, and in many species are constantly replaced throughout the " ..
put " shark's life; some sharks can lose 30,000 teeth in a lifetime." ..
Pic.ScreenLoad ("rightarrow.BMP", 560, 0, picCopy)
Pic.ScreenLoad ("leftarrow.BMP", 450, 0, picCopy)
Font.Draw ("Page 2/3", 0, 0, font, blue)
Pic.ScreenLoad ("shark_teeth.JPG", 220, 60, picCopy)
end page2
procedure page3
Font.Draw ("Page 3/3", 0, 0, font, blue)
Pic.ScreenLoad ("rightarrow.BMP", 560, 0, picCopy)
Pic.ScreenLoad ("leftarrow.BMP", 450, 0, picCopy)
Font.Draw ("Lifespan", 1, 360, font, yellow)
put
"Maximum shark ages vary by species. Most sharks live for 20 to 30 years, while the spiny dogfish lives a record lifespan of more than 100 years. [12] Whale sharks (Rhincodon typus) have been hypothesized to also live over 100 years."
end page3
Menue
var pages : array 1 .. 3 of procedure page
pages (1) := page1
pages (2) := page2
pages (3) := page3
var page_num := 0
loop
Mouse.Where (mx, my, mb)
var forward_button := mx >= 550 and mx <= maxx and my >= 0 and my <= 90 and mb = 1
if mx >= 310 and mx <= 600 and my >= 240 and my <= 420 and mb = 1 then
page1
elsif mx >= 550 and mx <= maxx and my >= 0 and my <= 90 and mb = 1 then
page_num += 1
pages (page_num)
elsif mx >= 450 and mx <= maxx - 105 and my >= 0 and my <= 90 and mb = 1 then
page_num -= 1
pages (page_num)
end if
end loop
-------------------------------------------------------
Sean
Posted: Sun May 25, 2008 5:25 pm Post subject: Re: How to turn back?
Use a cls before you switch back.
Turing:
if mx >= 310and mx <= 600and my >= 240and my <= 420and mb =1then cls
page1
endif
jasonlin6868
Posted: Sun May 25, 2008 5:29 pm Post subject: RE:How to turn back?
It's not so much the cls problem, but the array problem, when I click the forward button it said the subscribe is out of range.
Sean
Posted: Sun May 25, 2008 5:43 pm Post subject: Re: How to turn back?
You need to go to:
Turing:
page (1)
And so forth.
jasonlin6868
Posted: Sun May 25, 2008 5:47 pm Post subject: RE:How to turn back?
what do u mean? Man I feel so frustrating! What to do? It's due next Tue. I am doom
Sean
Posted: Sun May 25, 2008 5:49 pm Post subject: Re: How to turn back?
Well, your array is pages. The possible choices are from 1 to 3.
These arrays would look like this:
Turing:
pages (1)
pages (2)
pages (3)
You have to select the array number to call up the procedure that you stored it to.