Computer Science Canada

Resetting Time.Elapsed

Author:  landfarm [ Sat Dec 05, 2009 3:34 pm ]
Post subject:  Resetting Time.Elapsed

What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>


What is the problem you are having?
<Answer Here>


Describe what you have tried to solve this problem
<Answer Here>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


<Add your code here>



Please specify what version of Turing you are using
<Answer Here>

Author:  Insectoid [ Sat Dec 05, 2009 3:59 pm ]
Post subject:  RE:Resetting Time.Elapsed

It would be great if you, I dunno, put a question in here?

Author:  cool1143 [ Sat Dec 05, 2009 4:04 pm ]
Post subject:  Re: Resetting Time.Elapsed

yea, this almost happened to me. if you say... attach a new attachment or when you preview, everything you previously typed is gone...

Author:  Tony [ Sat Dec 05, 2009 4:22 pm ]
Post subject:  RE:Resetting Time.Elapsed

Confirmed the bug, and it's been logged for... eventual fixing.

Author:  DtY [ Sat Dec 05, 2009 5:05 pm ]
Post subject:  Re: RE:Resetting Time.Elapsed

Tony @ Sat Dec 05, 2009 4:22 pm wrote:
Confirmed the bug, and it's been logged for... eventual fixing.
I think at least a warning should be given in the default text to attach files before writing out your problem, and that if you preview make sure you have a local copy

Author:  TheGuardian001 [ Sat Dec 05, 2009 5:18 pm ]
Post subject:  Re: Resetting Time.Elapsed

Well, assuming that your problem is just resetting Time.Elapsed, I'm fairly certain you can't. You can however get two different values from Time.Elapsed and use them as a timer. For example, this waits for at least 10 seconds before exiting a loop.

Turing:

var start:int := Time.Elapsed %when we started
var current : int
put "starting" %output to create a window so we can tell it's running
loop
    current := Time.Elapsed %get the current running time
    exit when (current-start) > 10000
    %at least 10 second have passed since we set the starting time
end loop
put "end" %we're done.


This effectively acts as though you reset Time.Elapsed by using the value of start as your baseline, instead of when the program actually started.

Author:  landfarm [ Sat Dec 05, 2009 8:47 pm ]
Post subject:  Re: Resetting Time.Elapsed

Sorry for getting back so late. I didn't realize my previous post was empty. And thanks, I'm going to try that later. I hope it works. But just in case, I'll rewrite my question. I made an animation and a game. After that, I thought it would be cool to add buttons, so I followed the guide, GUI for Dummies. I got it all working but my animation was based on a few songs, so I used Time.Elapsed to make sure the right things happened at the right time. But heres the catch, while running the loop in the GUI, it still counts as Time.Elapsed cause it started, so that is my problem. I'll see if the previous post works, and I think it would but I have to go to sleep now, to tomorrow. If there are any other ways, please advise. Thanks.

Author:  landfarm [ Sat Dec 05, 2009 10:14 pm ]
Post subject:  Re: Resetting Time.Elapsed

Here is my code that has trouble. I'm only copying certain parts of it. My time still will not work. I kinda of understand it but it doesn't seem to work.
Turing:

procedure Animation
    setscreen ("offscreenonly")
    c := 1
    fork Play1     %Starts music
    loop         %Begins animation, redbox standing in middle, followed by other boxes coming in
        if c = 1 then
            ay3 := 800
            drum := 15
            inc := 1
        end if
        if (current - timepassed) < 12000 then
            if drum > 20 then
                inc *= -1
            elsif drum < 15 then
                inc *= -1
            end if
            drum += inc
        end if
        colourback (red)
        drawfillbox (0, 140, 100, 340, 8)      %Speakers in background and outline. This is speaker #1
        Draw.ThickLine (0, 140, 0, 340, 5, black)        %2D Outline part
        Draw.ThickLine (0, 340, 100, 340, 5, black)
end Animation
        %Another part, the GUI part
procedure Play
    Instructions
    Game
end Play
procedure Replay
    Intro
    Animation
end Replay
var button1:int:=GUI.CreateButton(20, 100, 0, "Play Game", Play)
var button2:int:=GUI.CreateButton(20, 70, 0, "Play Animation", Replay)
loop
    timepassed := Time.Elapsed
    Font.Draw ("ISU : Animation with Special 'FX'", 20, 350, fontdefault, black)
    exit when GUI.ProcessEvent
end loop

Author:  B-Man 31 [ Sat Dec 05, 2009 10:18 pm ]
Post subject:  Re: Resetting Time.Elapsed

TheGuardian001 @ Sat Dec 05, 2009 5:18 pm wrote:
Well, assuming that your problem is just resetting Time.Elapsed, I'm fairly certain you can't. You can however get two different values from Time.Elapsed and use them as a timer. For example, this waits for at least 10 seconds before exiting a loop.

Turing:

var start:int := Time.Elapsed %when we started
var current : int
put "starting" %output to create a window so we can tell it's running
loop
    current := Time.Elapsed %get the current running time
    exit when (current-start) > 10000
    %at least 10 second have passed since we set the starting time
end loop
put "end" %we're done.


This effectively acts as though you reset Time.Elapsed by using the value of start as your baseline, instead of when the program actually started.


To reset it, couldnt you just like do this:

Turing:

var time1 : int := 0 %declare my variable

loop
    time1 := 0 %this will reset the time to zero
    loop
        time1 := Time.Elapsed %start the timer
        exit when time1 >= 10000 %exit this loop to go around and reset the timer
    end loop
end loop

Author:  landfarm [ Sat Dec 05, 2009 10:33 pm ]
Post subject:  RE:Resetting Time.Elapsed

Um, I'm not sure but I got it working now.

Author:  B-Man 31 [ Sat Dec 05, 2009 10:39 pm ]
Post subject:  RE:Resetting Time.Elapsed

alright. thats good.


: