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

Username:   Password: 
 RegisterRegister   
 timer to call procedure
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
kythoon




PostPosted: Wed May 21, 2003 5:21 pm   Post subject: timer to call procedure

Is there a way to make a timer, that isn't show, that when it hits zero it calls a certain procedure?
Sponsor
Sponsor
Sponsor
sponsor
Solo




PostPosted: Wed May 21, 2003 5:29 pm   Post subject: Timer

code:

process Timer (tim : int) %Time in seconds you want to delay
    loop
        delay (tim * 1000)
        %Put the proc you wanna run in here
        %Also prolly wanna stick an exit condition in here
    end loop
end Timer


fork Timer (50) %Runs the procedure every 50 seconds



Remember, if you use this method, you need to make a different time for every procedure you want to use a timer with.
nate




PostPosted: Wed May 21, 2003 5:29 pm   Post subject: (No subject)

code:
procedure done
put "Done"
end done

for i:1..10
       delay (1000)
            if i = 10 then
                  done
             end if
end for

*This is the same as timing for 10 seconds
When it reaches 10 or basically 0 if you counted down

it runs the procedure!

-Nate
Solo




PostPosted: Wed May 21, 2003 5:37 pm   Post subject: Timer again

Yes, that technically does a timer function, but also that stops the program at that place, usually a timer needs to be running simotaniusly with the rest of the program, i suggest using the process so you can have it running in the background.
kythoon




PostPosted: Wed May 21, 2003 5:55 pm   Post subject: (No subject)

ic what you mean but how would you use it with it were in a loop, this is for if a character was moving around, and say after 5 seconds a monster poped up, using the procedure. How would you do that?

with fork?
Catalyst




PostPosted: Wed May 21, 2003 5:56 pm   Post subject: (No subject)

dont use processes
cant stress that enough
Solo




PostPosted: Wed May 21, 2003 6:08 pm   Post subject: Why not?

If you want to make a monster pop up every 5 seconds, you would do something like this :

code:
process Timer (tim : int) %Time in seconds you want to delay
    loop
        delay (tim * 1000)
        monsterePop
        exit when gamequit
    end loop
end Timer


fork Timer (50)

loop %mainloop
     All your stuff in here
end loop



And why not use processes? as long as you have a good understanding of how they work, even in turing they can be put to good use. Especially in graphics applications.
kythoon




PostPosted: Wed May 21, 2003 6:09 pm   Post subject: (No subject)

why not?

then how? Question
Sponsor
Sponsor
Sponsor
sponsor
Solo




PostPosted: Wed May 21, 2003 6:14 pm   Post subject: Hehehe :)

Sometimes i think faster than i type, hehe. I meant to ask Catalyst why not to use processes, but then i just answered your question first Smile
Tony




PostPosted: Wed May 21, 2003 6:27 pm   Post subject: (No subject)

well we had a discussion about that already... more then once I think...

basically processes dont run parallel to the program... its more like a random choice between which procedure to run in what order... if you look in the help file, they actually make a process racing game where they run 10 identical processes at same time and whichever comes to a sertain count first wins... you'll be surpriced at the difference in results Shocked

it will also mess up your global values and potentially can cause the program to crash or not run properly
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
kythoon




PostPosted: Wed May 21, 2003 6:28 pm   Post subject: (No subject)

ok thanks
Solo




PostPosted: Wed May 21, 2003 6:30 pm   Post subject: Never had a problem.

I have actually not had much problem with them, I dont think Mazer has either, infact his game (Evasive manuvers) is basically completely processes.

When I get to school tommorrow i will post my Matrix program that draws pictures in different coloured matrix symbols, it is completly done in processes.
Catalyst




PostPosted: Wed May 21, 2003 6:35 pm   Post subject: (No subject)

bottom line processes are messy and anything that you can do with them, you can do without them
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  [ 13 Posts ]
Jump to:   


Style:  
Search: