Computer Science Canada

What does procedure TextDelay do??

Author:  Neja [ Wed Jun 18, 2003 9:10 pm ]
Post subject:  What does procedure TextDelay do??

Huh?
I have an interview where I have to define
code:
procedure Delay (strtext : string)
    for i : 1 .. length (strtext)
        put strtext (i) ..
        delay (20)
    end for
end Delay

Can anyone give me an extremly detailed description of it? I don't understand particularly why it's a procedure used as a variable....

Author:  Mephi [ Wed Jun 18, 2003 9:33 pm ]
Post subject: 

code:
procedure Delay (strtext : string)
    for i : 1 .. length (strtext)
        put strtext (i) ..
        delay (20)
    end for
end Delay


the procedure obviously declares it as a procedure
Delay is the procedures name
(strtext : string) is called a parameter in this case, it is the word/sentence that you want text delayed
for i : 1 .. length (strtext) is a counted loop this loop runs as many times as the length of strtext, the input
put strtext (i) the i changes as the loop progresses, thus this displays the letter that youre on, eg if its the first time, i = 1 thus the first letter of strtext is displayed
.. makes it so that all other letters will be placed on the same line
delay (20) is the time (in milliseconds) in between the display of each letter
end for ends the counted loop
end Delay closes the procedure

To use this, you would do:
code:
Delay ("Hello")

this would display the word Hello letter by letter with 20 milliseconds in between each letter

Author:  Blade [ Wed Jun 18, 2003 9:34 pm ]
Post subject: 

its used as a procedure so if you want to use it more than once in your program you can call it instead of rewriting the code.... and the variable is used because if you want to use a different word, or different speeds in the delay you can change it... otherwise you cant

Author:  Neja [ Wed Jun 18, 2003 10:06 pm ]
Post subject: 

Ah. Thank you. I've been using the code for my game alot, sad that I don't know what it is, eh?

Author:  Tony [ Wed Jun 18, 2003 11:11 pm ]
Post subject: 

yeah, it might also be a good idea to give some credit for code you take from others Confused

Author:  PaddyLong [ Wed Jun 18, 2003 11:45 pm ]
Post subject: 

Neja wrote:
Ah. Thank you. I've been using the code for my game alot, sad that I don't know what it is, eh?


very. this is really basic code...

Author:  Blade [ Thu Jun 19, 2003 11:35 am ]
Post subject: 

tony wrote:
yeah, it might also be a good idea to give some credit for code you take from others Confused


since it is very basic... i wouldnt call it stealing, but in this case he did cuz he didnt know what it did... like if i went and wrote one like this really quickly using Font.Draw i know other people have and it would probably look the same... but it doesnt mean i took it... but understand where yer coming from since he did tell us he took it


: