Computer Science Canada

How to turn back?

Author:  jasonlin6868 [ 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?

Author:  TheGuardian001 [ 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.

Author:  jasonlin6868 [ 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!

Author:  Sean [ 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
 end if
end Example2

%Main Program
Example
Example2


Works like this.

Author:  jasonlin6868 [ 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?

Author:  jasonlin6868 [ 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"

Author:  richcash [ 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

Author:  jasonlin6868 [ 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

Author:  richcash [ Sun May 25, 2008 4:40 pm ]
Post subject:  Re: How to turn back?

You have to assign values to your array of procedures.
code:
var page : array 1 .. 3 of procedure page
page (1) := page1
page (2) := page2
page (3) := page3

Author:  jasonlin6868 [ 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
-------------------------------------------------------

Author:  Sean [ Sun May 25, 2008 5:25 pm ]
Post subject:  Re: How to turn back?

Use a cls before you switch back.


Turing:

if mx >= 310 and mx <= 600 and my >= 240 and my <= 420 and mb = 1 then
     cls
     page1
end if

Author:  jasonlin6868 [ 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.

Author:  Sean [ 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.

Author:  jasonlin6868 [ 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

Author:  Sean [ 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.

Author:  jasonlin6868 [ Sun May 25, 2008 6:00 pm ]
Post subject:  RE:How to turn back?

I had change the procedure part. But still doesn't work. Please, I am a noob. Help! I need an adult! I need an adult!

-------------------------------------------------------
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
pages (1)
elsif mx >= 550 and mx <= maxx and my >= 0 and my <= 90 and mb = 1 then
cls
pages (page_num + 1)
elsif mx >= 450 and mx <= maxx - 105 and my >= 0 and my <= 90 and mb = 1 then
cls
pages (page_num - 1)

end if
end loop
-------------------------------------------------------

Author:  Sean [ Sun May 25, 2008 6:01 pm ]
Post subject:  Re: How to turn back?

No I mean this:

Turing:

var pages : array 1 .. 3 of procedure page
pages (1) := page1
pages (2) := page2
pages (3) := page3


This is where you declared your procedures as arrays. My question, is why?

Author:  jasonlin6868 [ Sun May 25, 2008 6:06 pm ]
Post subject:  RE:How to turn back?

richcash told me to use it, that's why. Because he said that since all of my procedures have the same parameters (which is no parameters). I only have forwardbuttons and backwardbuttons., which I have to use more than 2 times. So I click back and fore like a book.

Author:  Sean [ Sun May 25, 2008 6:09 pm ]
Post subject:  RE:How to turn back?

Well, using your code. You have set your page number to 0. When they click forward, make a calculation to count it + 1. Backwards - 1.

Turing:

if mx >= 310 and mx <= 600 and my >= 240 and my <= 420 and mb = 1 then
pages (page_num)
elsif mx >= 550 and mx <= maxx and my >= 0 and my <= 90 and mb = 1 then
cls
pages (page_num + 1)
elsif mx >= 450 and mx <= maxx - 105 and my >= 0 and my <= 90 and mb = 1 then
cls
pages (page_num - 1)


Change the page_num variable to 1 instead of 0.

I'll bring up it on my other computer and take a further look into your matter.

Author:  jasonlin6868 [ Sun May 25, 2008 6:14 pm ]
Post subject:  RE:How to turn back?

Well, there is no difference when I change it to 1

Author:  jasonlin6868 [ Sun May 25, 2008 6:18 pm ]
Post subject:  RE:How to turn back?

Menue
var pages : array 1 .. 3 of procedure page
pages (1) := page1
pages (2) := page2
pages (3) := page3
var page_num := 1
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
pages (page_num)
elsif mx >= 550 and mx <= maxx and my >= 0 and my <= 90 and mb = 1 then
cls
pages (page_num + 1)
elsif mx >= 450 and mx <= maxx - 105 and my >= 0 and my <= 90 and mb = 1 then
cls
pages (page_num - 1)
cls
end if
end loop

Author:  Sean [ Sun May 25, 2008 6:20 pm ]
Post subject:  Re: How to turn back?

Well, you have arrays. 1 to 3.

When you have it set to 1 it calls your first procedure. When you click the next one it adds one. However if you hit back before going forward it goes to 0 which is not a number in it.

Author:  jasonlin6868 [ Sun May 25, 2008 6:22 pm ]
Post subject:  RE:How to turn back?

But I had tried. It's not working. 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 := 1
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
pages (page_num)
elsif mx >= 550 and mx <= maxx and my >= 0 and my <= 90 and mb = 1 then
cls
pages (page_num + 1)
elsif mx >= 450 and mx <= maxx - 105 and my >= 0 and my <= 90 and mb = 1 then
cls
pages (page_num - 1)
end if
end loop
-------------------------------------------------------

Author:  jasonlin6868 [ Sun May 25, 2008 6:30 pm ]
Post subject:  RE:How to turn back?

Even though it didn't work, but thanks for ur help Sean, you are the best.

Author:  Sean [ Sun May 25, 2008 6:31 pm ]
Post subject:  RE:How to turn back?

Heh. I tried to figure it out for you. It's because you are going out of the range of your array value.

If you linked me with the pictures, I might be able to help more.

Author:  jasonlin6868 [ Sun May 25, 2008 6:34 pm ]
Post subject:  Re: How to turn back?

Here Sean, the file is all my work.

Author:  Sean [ Sun May 25, 2008 6:35 pm ]
Post subject:  Re: How to turn back?

I'll see what I can do. Linking it here allows others to look at it as well. The latest I can have a 100% answer by is tomorrow.

Author:  jasonlin6868 [ Sun May 25, 2008 6:37 pm ]
Post subject:  RE:How to turn back?

You can even add my msn:
jason68@sympatico.ca

Author:  richcash [ Sun May 25, 2008 6:46 pm ]
Post subject:  Re: How to turn back?

I can't test your program, but what is the problem with it?

Does it say the array subscript is out of range?

Instead of :
code:
pages (page_num)

do this:
code:
pages (page_num mod 3 + 1)


Now does it work? And you should be clearing the screen between each page. And relax, you have enough time.

Author:  jasonlin6868 [ Sun May 25, 2008 7:01 pm ]
Post subject:  RE:How to turn back?

Doesn't work richcash

Author:  richcash [ Sun May 25, 2008 7:18 pm ]
Post subject:  Re: How to turn back?

code:
proc p1
    put "this is page 1"
end p1
proc p2
    put "this is page 2"
end p2
proc p3
    put "this is page 3"
end p3
var pages : array 1 .. 3 of proc p
var x, y, b, page_num := 0
pages (1) := p1
pages (2) := p2
pages (3) := p3
pages (1)
var clicked := false
loop
    Draw.FillBox (200, 10, 250, 22, red)
    Draw.FillBox (270, 10, 320, 22, green)
    Mouse.Where (x, y, b)
    if b = 0 and clicked then
        clicked := false
    end if
    if b not= 0 then
        if x > 200 and x < 250 and y > 10 and y < 22 and not clicked then
            page_num -= 1
            cls
            pages (page_num mod 3 + 1)
        elsif x > 270 and x < 320 and y > 10 and y < 22 and not clicked then
            page_num += 1
            cls
            pages (page_num mod 3 + 1)
        end if
        clicked := true
    end if
end loop


Is that the effect you're looking for?


: