
-----------------------------------
blankout
Sat Apr 04, 2009 7:36 pm

program won't restart
-----------------------------------
even with the procedure, i can't seem to get the program to restart after one cycle, please help
the program works fine, it's just that it doesn't repeat
var name:string
var letters:int
var counter:int:=0
put "What is your name?"
get name:*
cls
put "How many letters are there in ", name
get letters
cls
procedure restart
loop
put name (1..letters-counter)
delay (250)
cls
exit when counter=-1
counter:=counter+1
restart
end loop
end restart
restart


-----------------------------------
Dusk Eagle
Sat Apr 04, 2009 8:22 pm

Re: program won't restart
-----------------------------------
There's quite a few problems with your code. First of all, there is no need to be asking the user for the length of name. Instead, look up the 
put counter

we see that counter is continually increasing, not decreasing. So instead of exiting when the counter = -1, when would it make more sense to exit? I'll let you figure that part out yourself.

Now, once you have done all the above, to make the effect occur over and over again, simply add a loop around your "restart" line, and you'll witness the effect over and over again.

-----------------------------------
blankout
Sat Apr 04, 2009 8:49 pm

Re: program won't restart
-----------------------------------
ok well i tried to do what you said, and what i got is that the name still fades away, however i still can't repeat it, and i'm not entirely sure if i've gotten the exit when part correct

this is what i've managed to do
var name:string
put "What is your name?"
get name:*
var counter:int:=0
procedure restart
cls
loop
put name (1..length (name)-counter)
put counter
delay (250)
cls
exit when counter=length (name)
counter:=counter+1
restart
end loop
end restart
restart


-----------------------------------
Dusk Eagle
Sat Apr 04, 2009 10:53 pm

Re: program won't restart
-----------------------------------
You're very close to having your program working, only two things left to do. The first is to take out the line within your restart procedure that says nothing except "restart". What you have done is known as "recursion", which although not a bad thing, it is definitely not something you wanted to do here. The second thing you need to do is declare your counter variable inside your 'restart' procedure, rather than outside, like so:

procedure restart()
    var counter : int := 0
    %blah blah blah
end restart

The final thing to do is to loop calling the procedure, like so:

loop
    restart
end loop


Do these three things and you'll have your program working. However, if you want to take a bonus step, look at the following code:


procedure restart(word:string)
    var counter : int := 0
    cls
    loop
        put word (1 .. length (word) - counter)

        delay (250)
        cls
        exit when counter = length (word)
        counter := counter + 1
    end loop
end restart

var name : string
put "What is your name?"
get name : *
loop
    restart(name)
end loop


Notice the "procedure restart(word:string)" and the "restart(name)"? The restart(name) line "passes" the value of name into the procedure restart, which then stores a copy of that value known as word. One of the many advantages to doing it this way is demonstrated below:

var name1, name2 : string
get name1 :*
get name2 :*
loop
    restart (name1)
    restart (name2)
end loop

Notice how we could use more than one variable with restart()? This will prove to be immensely useful to you later on, and so is a good practice to start now.

-----------------------------------
blankout
Mon Apr 06, 2009 2:56 pm

Re: program won't restart
-----------------------------------
wow that fixed every problem i had thank you so much!
