Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Grade 10 Student Needs Help!!!
Index -> Programming, Turing -> Turing Help
Goto page 1, 2, 3  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
BangBangMario




PostPosted: Sat Dec 28, 2013 11:59 am   Post subject: Grade 10 Student Needs Help!!!

What is it you are trying to achieve?
I don't know what a string is and how to make a procedure


What is the problem you are having?
I want to learn what a string is and how to make a procedure


Describe what you have tried to solve this problem
Tried looking through forums and reading the online textbook but still don't get it


I need to learn this for my final project for the grade 10 computer studies course please help!





Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Sat Dec 28, 2013 1:23 pm   Post subject: RE:Grade 10 Student Needs Help!!!

The Turing Walkthrough

A string is like a word. You can make a variable a word. This is different from an int or real, those variables can only be numbers. Like so:

Turing:

var s : string := "This is a string"
var n : int := 126


Noticehow I put quotes around the string. This encapsulates what I want to be in the word.
A procedure is a block of code that you can call using it's name. Like so:

Turing:

procedure print_hello
    put "Hello!"
end print_hello

print_hello


Whenever I cann print_hello, it will do whatever code is inside the procedure. Mostly it saves a lot of time and stops you from repeating code. They can also have things called parameters, which makes the procedure do certain things depending on what is inside them:

Turing:

procedure greet (name : string)
    put "Hello, " name
end greet

greet ("BangBangMario")
BangBangMario




PostPosted: Sat Dec 28, 2013 2:25 pm   Post subject: Re: Grade 10 Student Needs Help!!!

oh ok thank you... but what about the more complex procedures and also could also teach me how to do simple animations like move a car? thank you soo much
Raknarg




PostPosted: Sat Dec 28, 2013 4:19 pm   Post subject: RE:Grade 10 Student Needs Help!!!

You definitely should have studied more. Have you payed attention in all your classes?

Define more complex.

Animations are pretty simple. Usually you just have something to keep track of position, and then you draw it accordingly. For instance, you can draw a circle going across the screen.

Turing:

for i : 0 .. maxx
    Draw.FillOval (i, maxy div 2, 10, 10, 12) % Draws a red circle across the screen
    cls % This clears the screen so we can start fresh. Otherwise, it will leave a red streak on the screen. Try it without it.
end for

%Alternatively:
var x : int := 0
loop
    exit when x > maxx %Same thing as the for loop, goes from 0 to maxx
    Draw.FillOval (x, maxy div 2, 10, 10, 12) %Same as before, but now we're using a variable that we keep rack of ourselves
    cls
    x := x + 1
end loop
BangBangMario




PostPosted: Sat Dec 28, 2013 6:07 pm   Post subject: Re: Grade 10 Student Needs Help!!!

just like the one you posted, could you explain to me every part of it. And i have paid attention just forgot things after we started HTML
Raknarg




PostPosted: Sat Dec 28, 2013 8:25 pm   Post subject: RE:Grade 10 Student Needs Help!!!

Alright, sure.

So with a procedure, you define code that will be attached to a specific name. It's kindof like a variable, but instead of attaching a name to a certain value, it's a block of code.

Let's take greet, for example.

Turing:

procedure greet (name : string)
    put "Hello, " name
end greet

greet ("BangBangMario")


First, we put the word procedure. This is like saying var. We're telling the computer that we want the next thing to be a procedure.

Next, we have the procedure name. This tells the computer that whenever you call that name, it will activate the code block attached to that name. If you put greet in the middle of our program, it will do whatever is inside greet.

The next part are parameters. You do not necessarily need any. When you call the procedure, if there's any parameters attached to the name, you need to call that as well. If we look at greet, it has a parameter called name. In the procedure greet, it will have a temporary variable called name that is whatever we assigned it as when we called it.

Then, we put any code we want. Doesn't really matter what it is.

Then we end the procedure with it's name. This says we're done defining what greet is.

Now look what happens when we call greet. It has one parameter in it, so we have to give it one in the program. In this case, the procedure greet will be called and the variable name will be "BangBangMario". Then, according to the procedure, it will put name on the screen.


Any questions?
BangBangMario




PostPosted: Sun Dec 29, 2013 5:44 pm   Post subject: Re: Grade 10 Student Needs Help!!!

You are an amazing teacher sir... i understand procedure now and one last thing is if you could explain the animations part... and also there is one part the teacher didnt teach which is how to make a clickable menu and also use the keyboard to make selections.
Raknarg




PostPosted: Sun Dec 29, 2013 11:08 pm   Post subject: RE:Grade 10 Student Needs Help!!!

I've spent a lot of time teaching teenagers, I'd hope I'm at least somewhat decent :p thanks.

Think about your animation in terms of frames. Let's look at our ball animation:

Turing:


for i : 0 .. maxx
    Draw.FillOval (i, maxy div 2, 10, 10, 12) % Draws a red circle across the screen
    cls % This clears the screen so we can start fresh. Otherwise, it will leave a red streak on the screen. Try it without it.
end for

%Alternatively:
var x : int := 0
loop
    exit when x > maxx %Same thing as the for loop, goes from 0 to maxx
    Draw.FillOval (x, maxy div 2, 10, 10, 12) %Same as before, but now we're using a variable that we keep rack of ourselves
    cls
    x := x + 1
end loop


Now, what's going on here? To make the illusion that the circle is going across the screen, we have to draw it multiple times at different spots. Remember you can draw things anywhere on the screen.

How do we determine what numbers to put in as the coordinates? Well, for my program, I wanted to make it go from the left side to the right side, through the middle. This means that I will always draw it on the middle of the y axis, (maxy div 2) and then I just have to find some way to move it across the x axis like I want.

This is achieved by theexamples I have up there. In the first case, I have a variable in the for loop that keeps track of the x position. I draw it maxx times, and each time the number gets bigger and bigger. This is how I make it appear to move across.

The second example is actually what you should do. The reason for this is because you may have multiple objects which will animate through different amounts of frames, like this:

Turing:

var x, y : int := 0
loop
    exit when x > maxx
    Draw.FillOval (x, maxy div 2, 10, 10, 12)
    Draw.FillOval (maxx div 2, y, 10, 10, 7)
    delay(5) % note I forgot this before. If it's not included, your program may run too quickly
    cls
    x := x + 1
    y := y + 1
end loop


Clickable menus may be a little more challenging. The simplest thing to do would be to use Turing's GUI module, which I have no idea how to use. You can look it up on the Turing Walkthrough I think
Sponsor
Sponsor
Sponsor
sponsor
BangBangMario




PostPosted: Tue Dec 31, 2013 11:32 am   Post subject: Re: Grade 10 Student Needs Help!!!

Thanks so much... but another problem.....

when i make the button for credits i need anoter page to pop up and then press a letter on the keyboard to go back to the original page... any ideas?
Raknarg




PostPosted: Tue Dec 31, 2013 12:46 pm   Post subject: RE:Grade 10 Student Needs Help!!!

You could use states

Turing:

var state : string := "MENU"
loop
    if state = "MENU" then
        do_menu_stuff()
        if startGame.is_clicked() then
            state := "GAME"
        end if
    elsif state = "GAME" then
        do_game_stuff()
        if gameOver() then
            state = "CREDITS"
        end if
    elsif state = "CREDITS" then
        do_credit_stuff()
        if keyboard.is_pressed() then
            state = "MENU"
        end if
    end if
end loop


This just shows logic, it's not real code
BangBangMario




PostPosted: Thu Jan 02, 2014 1:06 pm   Post subject: Re: Grade 10 Student Needs Help!!!

drawfillbox (0, 50, 100, 50, 15)
drawfillbox (0, 100, 150, 100, 15)
drawfillbox (0, 150, 200, 150, 15)
drawfillbox (0, 200, 250, 200, 15)
drawfillbox (0, 250, 300, 250, 15)
Draw.ThickLine (50, 0, 50, 50, 10, 7)
Draw.ThickLine (50, 50, 100, 50, 10, 7)
Draw.ThickLine (100, 50, 100, 100, 10, 7)
Draw.ThickLine (100, 100, 150, 100, 10, 7)
Draw.ThickLine (150, 150, 150, 100, 10, 7)
Draw.ThickLine (200, 150, 150, 150, 10, 7)
Draw.ThickLine (200, 200, 200, 150, 10, 7)
Draw.ThickLine (200, 200, 250, 200, 10, 7)
Draw.ThickLine (250, 200, 250, 250, 10, 7)
Draw.ThickLine (250, 250, 300, 250, 10, 7)



the boxes arent appearing on my stairs... any ideas??
Raknarg




PostPosted: Thu Jan 02, 2014 1:15 pm   Post subject: RE:Grade 10 Student Needs Help!!!

First of all, remember order matters.

Second: drawfillbox (0, 50, 100, 50, 15)
You realize this just draws a line, right?
BangBangMario




PostPosted: Thu Jan 02, 2014 3:18 pm   Post subject: Re: Grade 10 Student Needs Help!!!

myy badd, i switched the x and y values
BangBangMario




PostPosted: Fri Jan 03, 2014 7:30 pm   Post subject: Re: Grade 10 Student Needs Help!!!

proc background
%%night sky%%
drawfillbox (0, 0, maxx, maxy, 177)
drawfilloval (100, 575, 75, 75, 92)
drawfilloval (125, 600, 75, 75, 177)

%%Stairs%%
drawfillbox (50, 0, 100, 50, 15)
drawfillbox (100, 0, 150, 100, 15)
drawfillbox (150, 0, 200, 150, 15)
drawfillbox (200, 0, 250, 200, 15)
drawfillbox (250, 0, 300, 250, 15)
drawfillbox (300, 0, 350, 300, 15)
Draw.ThickLine (50, 0, 50, 50, 10, 7)
Draw.ThickLine (50, 50, 100, 50, 10, 7)
Draw.ThickLine (100, 50, 100, 100, 10, 7)
Draw.ThickLine (100, 100, 150, 100, 10, 7)
Draw.ThickLine (150, 150, 150, 100, 10, 7)
Draw.ThickLine (200, 150, 150, 150, 10, 7)
Draw.ThickLine (200, 200, 200, 150, 10, 7)
Draw.ThickLine (200, 200, 250, 200, 10, 7)
Draw.ThickLine (250, 200, 250, 250, 10, 7)
Draw.ThickLine (250, 250, 300, 250, 10, 7)
Draw.ThickLine (300, 250, 300, 300, 10, 7)
Draw.ThickLine (300, 300, 350, 300, 10, 7)
%%house%%
drawfillbox (350, 0, maxx, maxy, 186) %draws the bricks of the house
drawfillbox (500, 300, 700, 500, 20) %the glass of the window
Draw.ThickLine (600, 300, 600, 500, 10, 7) %frame of the window
Draw.ThickLine (500, 400, 700, 400, 10, 7) %frame of the window
drawfillbox (400, 0, 475, 125, 1) %recycling bin
Font.Draw ("RECYCLE", 415, 75, font1, red) %writes recycle on the bin
drawfillbox (525, 0, 600, 125, 21) %garbage bin
Font.Draw ("GARBAGE", 540, 75, font1, red) %write garbage on the garbage bin
drawfilloval (465, 15, 15, 15, 7) %the wheel of the recycling bin
drawfilloval (590, 15, 15, 15, 7) % draws the wheel of the garbage bin
end background

background
setscreen ("offscreenonly")
for y : 350 .. 250 by 2
background
drawfilloval (325, y, 25, 25, 4)
View.Update
delay (25)
end for




nothings animating with the red text[/quote]
Raknarg




PostPosted: Fri Jan 03, 2014 10:45 pm   Post subject: RE:Grade 10 Student Needs Help!!!

Turing:

%This goes forward:
for i : 1 .. 5
end for

%this goes backwards:
for decreasing i : 1 .. 5
end for
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 3  [ 36 Posts ]
Goto page 1, 2, 3  Next
Jump to:   


Style:  
Search: