Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Time.Elapsed at x time +5000..
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Geostigma




PostPosted: Sat May 05, 2007 9:07 am   Post subject: Time.Elapsed at x time +5000..

I'm having issues trying to get my time elapse to work properly. I know that time elapse calculates the time the program starts until the program ends. Well how do I get my Time.Elapse do something like. If I hit a certain object at any time then after 5 seconds go by then it does what I want. I seriously can't get it to work. I saw another thread but it doesn't seem to answer my question

I tried a few renditions of

Turing:
time1 := Time.Elapsed
if state:=2 then
if time1>time1+5000 then
state:=1
else
%RunProcedure
end if
end if


or

Turing:
time1 := Time.Elapsed
if state:=2 then
if time1>time1 - time1 + 5000 then%ends up doing nothing.
state:=1
else
%RunProcedure
end if
end if
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sat May 05, 2007 1:11 pm   Post subject: RE:Time.Elapsed at x time +5000..

code:
if state:=2 then

This should be a syntax error in Turing, I think, since Turing doesn't really like to use expressions, but rather statements. You should use = for comparison. := is for assignment.

try something like this:
code:

var timer := 0
var do_delayed_event := false
loop
  if event_happens then
     timer := Time.Elapsed
     do_delayed_event := true
  end if
  if do_delayed_event and Time.Elapsed >= timer + 5000 then
     call_delayed_event
  end if
end loop
Geostigma




PostPosted: Sat May 05, 2007 9:20 pm   Post subject: RE:Time.Elapsed at x time +5000..

Yeah sorry I wrote that on the top of my head I didn't copy it from Turing because I left my file on my Flash Drive. Ill take a look and try what you posted. Any errors in my code syntax wise is totally due to the lack of having the file on me lol.
Geostigma




PostPosted: Sun May 06, 2007 10:01 pm   Post subject: RE:Time.Elapsed at x time +5000..

still not working.

Turing:
    var timer := 0
    if g1state = 2 then
        Pic.Draw (g1pic, g1xpos, g1ypos, picMerge)

        timer := Time.Elapsed
        if timer >= Time.Elapsed + 5000 then

            g1state := 1
        end if
    end if

ghost just permanently freezes
Cervantes




PostPosted: Sun May 06, 2007 10:50 pm   Post subject: RE:Time.Elapsed at x time +5000..

No, that wouldn't work. Do you know why? It's because you set timer := Time.Elapsed, then on the next line (which happens almost instantly, so 0 milliseconds have passed) you're asking if timer >= Time.Elapsed + 5000. Well, of course it won't be, because timer = Time.Elapsed. So that's asking if Time.Elapsed >= Time.Elapsed + 5000, which is essentially asking if 0 >= 5000. Certainly not.
Geostigma




PostPosted: Mon May 07, 2007 11:26 am   Post subject: Re: Time.Elapsed at x time +5000..

Well I don't know why your getting all pissed off when your method doesn't work either. I did both the one i just posed and copied and pasted your code and subbed what I needed to be done after 5 seconds.

Mine makes the object stand still.
Yours makes the object continue on.

Turing:
var timer := 0
var do_delayed_event := false
loop
  if g1state=2 then
     timer := Time.Elapsed
     do_delayed_event := true
  end if
  if do_delayed_event and Time.Elapsed >= timer + 5000 then
     g1state=1
  end if
end loop
program_x




PostPosted: Mon May 07, 2007 1:11 pm   Post subject: Re: Time.Elapsed at x time +5000..

what if you had something like two vars, one for the first time, and one to compare angainst like:
code:

var time1:int:=Time.Elapsed
var time2:int
loop
   %yadda yadda
   time2:=Time.Elapsed
   if time2-time1=5000 then %for 5 seconds
      %procedure to exec
   end if
end loop


i din't really look at your code, but it sounds like an issue involving how long until to execute somthing

help this helps


note to clayton: i added code tags already
program_x




PostPosted: Mon May 07, 2007 1:15 pm   Post subject: Re: Time.Elapsed at x time +5000..

sorry, i ment to say "hope this helps"
Sponsor
Sponsor
Sponsor
sponsor
Geostigma




PostPosted: Mon May 07, 2007 2:12 pm   Post subject: RE:Time.Elapsed at x time +5000..

Yeah i tried that one at the bigging and also again just now. I don't know whats wrong with this.
Cervantes




PostPosted: Mon May 07, 2007 6:03 pm   Post subject: Re: Time.Elapsed at x time +5000..

Geostigma @ Mon May 07, 2007 11:26 am wrote:
Well I don't know why your getting all pissed off when your method doesn't work either.

I was not getting pissed off. I'm sorry if that's how I came across. I was actually rather mellow when I wrote that. The fact that I did not offer a solution in that post does not mean I was getting frustrated with you. I was merely trying to get you to think about what's going on. We learn best by thinking ourselves, not by being told the answers.

However, you are correct. I made a mistake in my code. I meant to give this:

Turing:

var timer := 0
var do_delayed_event := false
loop
  if event_happens then
     timer := Time.Elapsed
     do_delayed_event := true
  end if
  if do_delayed_event and Time.Elapsed >= timer + 5000 then
     do_delayed_event := false %% INSERTED THIS LINE
     call_delayed_event
  end if
end loop

I think that should work.


program_x: introducing a second variable, time2, does nothing for us. See, you assigned time2 to be Time.Elapsed, and then in the very next line used time2. We could have just used Time.Elapsed there.
Also, you used = for comparison. This is risky. Because we are working with time, if our main loop is big and honking, it might take, say, 4 milliseconds to execute once. Then there is a 1 in 4 chance that the equality will be true. 3/4 of the time, time2-time1 will skip right over the number 5000: it might be 4993, then 4997, then 5001, then 5005, ... and we never entered the if statement that we wanted to. Using >= avoids this problem, but you probably have to introduce a second variable (boolean, in this case) as I did in my code.
Geostigma




PostPosted: Mon May 07, 2007 9:39 pm   Post subject: RE:Time.Elapsed at x time +5000..

Yeah that doesn't work either lol. I added your set your do_delayed_event to false after it because I noticed that you never had it before hand. I'm not just using answers I'm trying to play with it. if you want I can PM my whole file to you because I rather not give it out to the public. Its not hush hush I just don't want some people stealing certain procedures in it.


EDIT: okay wtf... Now if I run over the space where the object sits idle.. it starts up again when I have just the timer set to delay. Hokay... wtf...

and this is before I added the true statement. I dont know if telling you its in a procedure changes anything

Turing:

procedure g1
    if g1state = 1 then
        if g1dir = 2 then
            g1xpos := g1xpos + 1
        elsif
                g1dir = 4 then
            g1xpos := g1xpos - 1
        elsif
                g1dir = 1 then
            g1ypos := g1ypos + 1

        elsif
                g1dir = 3 then
            g1ypos := g1ypos - 1
        end if


        %collision
        if g1dir = 1 then
            %detect wall
            if whatdotcolor (g1xpos + 10, g1ypos + 21) = 9 then
                %find a whole
                if whatdotcolor (g1xpos + 25, g1ypos + 10) = black then
                    g1dir := 2
                elsif whatdotcolor (g1xpos - 5, g1ypos + 10) = black then
                    g1dir := 4
                end if

            end if
            if whatdotcolor (g1xpos + 25, g1ypos + 10) = black and time2 > time1 then
                randint (g1ran, 1, 2)
                if g1ran = 1 then
                    g1dir := 2
                end if
            end if



            if whatdotcolor (g1xpos - 5, g1ypos + 10) = black and time2 > time1 then
                randint (g1ran, 1, 2)
                if g1ran = 1 then
                    g1dir := 4
                end if
            end if

        elsif g1dir = 2 then
            if whatdotcolor (g1xpos + 21, g1ypos + 5) = 9 then
                if whatdotcolor (g1xpos + 10, g1ypos + 25) = black then
                    g1dir := 1
                elsif whatdotcolor (g1xpos + 10, g1ypos - 5) = black then
                    g1dir := 3
                end if
            end if

        elsif g1dir = 3 then
            if whatdotcolor (g1xpos + 10, g1ypos - 1) = 9 then
                if whatdotcolor (g1xpos + 25, g1ypos + 10) = black then
                    g1dir := 2
                elsif whatdotcolor (g1xpos - 5, g1ypos + 10) = black then
                    g1dir := 4
                end if
            end if

        elsif g1dir = 4 then
            if whatdotcolor (g1xpos - 1, g1ypos + 10) = 9 then
                if whatdotcolor (g1xpos + 10, g1ypos + 25) = black then
                    g1dir := 1
                elsif whatdotcolor (g1xpos + 10, g1ypos - 5) = black then
                    g1dir := 3
                end if
            end if
        end if
        Pic.Draw (g1pic, g1xpos, g1ypos, picMerge)


    end if

    %second state
    %In this state the ghost is killable
    %In this state, after 5 seconds of time goes by the ghost switches back to normalstate



  if g1state =2 then
     timer := Time.Elapsed
     do_delayed_event := true
             Pic.Draw (g1pic, g1xpos, g1ypos, picMerge)

  end if
  if do_delayed_event = true and Time.Elapsed >= timer + 10 and g1state not= 0 then
     do_delayed_event := false %% INSERTED THIS LINE
     g1state:=1
  end if
end g1

loop
%program
g1
%program
end loop
splik




PostPosted: Sun May 13, 2007 6:45 pm   Post subject: RE:Time.Elapsed at x time +5000..

try this

var timer : int := 0
var g1state_just_became_2 : boolean := true

if g1state_just_became_2 = true then
g1state_just_became_2 := false
timer := Time.Elapsed
end if
if Time.Elapsed - 5000 >= timer then
g1state := 1
end if
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: