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
Posted: 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
Posted: 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, maxydiv2, 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. endfor
%Alternatively: var x :int:=0 loop exitwhen x > maxx%Same thing as the for loop, goes from 0 to maxx Draw.FillOval(x, maxydiv2, 10, 10, 12)%Same as before, but now we're using a variable that we keep rack of ourselves cls
x := x + 1 endloop
BangBangMario
Posted: 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
Posted: 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
Posted: 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
Posted: 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, maxydiv2, 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. endfor
%Alternatively: var x :int:=0 loop exitwhen x > maxx%Same thing as the for loop, goes from 0 to maxx Draw.FillOval(x, maxydiv2, 10, 10, 12)%Same as before, but now we're using a variable that we keep rack of ourselves cls
x := x + 1 endloop
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 exitwhen x > maxx Draw.FillOval(x, maxydiv2, 10, 10, 12) Draw.FillOval(maxxdiv2, 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 endloop
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
BangBangMario
Posted: 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
Posted: 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" endif elsif state ="GAME"then
do_game_stuff() if gameOver()then
state ="CREDITS" endif elsif state ="CREDITS"then
do_credit_stuff() if keyboard.is_pressed()then
state ="MENU" endif endif endloop
This just shows logic, it's not real code
BangBangMario
Posted: Thu Jan 02, 2014 1:06 pm Post subject: Re: Grade 10 Student Needs Help!!!