
-----------------------------------
landfarm
Sat Dec 05, 2009 3:34 pm

Resetting Time.Elapsed
-----------------------------------
What is it you are trying to achieve?



What is the problem you are having?



Describe what you have tried to solve this problem



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)








Please specify what version of Turing you are using


-----------------------------------
Insectoid
Sat Dec 05, 2009 3:59 pm

RE:Resetting Time.Elapsed
-----------------------------------
It would be great if you, I dunno, put a question in here?

-----------------------------------
cool1143
Sat Dec 05, 2009 4:04 pm

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...

-----------------------------------
Tony
Sat Dec 05, 2009 4:22 pm

RE:Resetting Time.Elapsed
-----------------------------------
Confirmed the bug, and it's been logged for... eventual fixing.

-----------------------------------
DtY
Sat Dec 05, 2009 5:05 pm

Re: RE:Resetting Time.Elapsed
-----------------------------------
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

-----------------------------------
TheGuardian001
Sat Dec 05, 2009 5:18 pm

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.


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.

-----------------------------------
landfarm
Sat Dec 05, 2009 8:47 pm

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.

-----------------------------------
landfarm
Sat Dec 05, 2009 10:14 pm

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.  

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


-----------------------------------
B-Man 31
Sat Dec 05, 2009 10:18 pm

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.


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:


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


-----------------------------------
landfarm
Sat Dec 05, 2009 10:33 pm

RE:Resetting Time.Elapsed
-----------------------------------
Um, I'm not sure but I got it working now.

-----------------------------------
B-Man 31
Sat Dec 05, 2009 10:39 pm

RE:Resetting Time.Elapsed
-----------------------------------
alright. thats good.
