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

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




PostPosted: Sun Jun 01, 2003 4:17 pm   Post subject: Delays

Quick question- is there a way to delay only ONE PART of a program, not the whole thing? for example delaying a target which is popping up for one second, which then delays for 5 seconds before popping up again at a different location. i want this to happen (its in a procedure) WHILE the mousewhere is working, not being delayed.
Sponsor
Sponsor
Sponsor
sponsor
Asok




PostPosted: Sun Jun 01, 2003 6:39 pm   Post subject: (No subject)

you could have the two parts of the programs in seperate processes and run them simeltaneously via fork, then u can delay one without it effecting the other.
PaddyLong




PostPosted: Sun Jun 01, 2003 7:16 pm   Post subject: (No subject)

or just have a short delay of like 100 or something in your main loop where you're doing your mouse.where and stuff and just have a counter to see how long the target has been up.. so five seconds is delay 5000 so just divide that by whatever delay you use in your main loop and every clock of the loop at one to your counter and when the counter is at 50 make the target go away and pop up somewhere else...
ex
var counter:int:=0
var mx,my,mb:int
loop
Mouse.Where (mx,my,mb)
counter += 1
delay (100)
if counter = 50 then
...move target to new location ...
end if
end loop

of course the process idea that Asok posted would be much cleaner and efficient so I would recommend that one Razz
naoki




PostPosted: Mon Jun 02, 2003 5:48 pm   Post subject: (No subject)

unless you don't want your stuff to be running at the same time, otherwise using a process instead of a proc makes the delays independent
Homer_simpson




PostPosted: Mon Jun 02, 2003 5:59 pm   Post subject: (No subject)

lol i already have a procedure made for that... just gimme a sec i'll find it on the site...
Homer_simpson




PostPosted: Mon Jun 02, 2003 6:06 pm   Post subject: (No subject)

there we go:
code:
function timedelay (var r : int, t : int) : boolean
    var tt : int
    if r = 0 then
        clock (r)
        result false
    end if
    clock (tt)
    if tt - r >= t then
        r := tt
        result true
    else
        result false
    end if
end timedelay



%this is how it is used :
var time1, i1, i2 := 0
locate (2, 1)
put "this one only changes every 2 seconds : ", i1
loop
    if timedelay (time1, 2000) then
        locate (2, 1)
        i1 += 1
        put "this one only changes every 2 seconds : ", i1
    end if
    i2 += 1
    locate (1, 1)
    put "this one always changes with the program being delayed or anything : ", i2
end loop
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  [ 6 Posts ]
Jump to:   


Style:  
Search: