
-----------------------------------
SeeknDestroy
Sun Jan 11, 2004 11:49 am

Timer won't work for some reason
-----------------------------------
well, here's my code for a level of my shooter, and when i run it, the people dont stay, they just flash for a half a second then disappear, but i put a timer on them  :( , well, here's my code, i don't want u guys to write me a code, just tell me whats wrong and how can i fix it, plz, im so new to turing, and well, plz help me  :( 
var winID : int
winID := Window.Open ("position:top;center,graphics:640;480")
var win, win1 := 0
var x, y, button, number, enemies, btn, updown : int
var got_hit : boolean := false
var timer : int

process bg1
    Pic.ScreenLoad ("level1.bmp", 0, 0, picCopy)
end bg1

procedure enemy1
    fork bg1
    mousewhere (x, y, button)
    Pic.ScreenLoad ("level1enemy1.bmp", 300, 345, picCopy)
    win1 := win1 + 1
    if x > 300 and x < 556 and y > 345 and y < 480 and button = 1 then
        win := win + 1
    else
        timer := 10000
    end if
end enemy1

procedure enemy2
    fork bg1     % The level background
    mousewhere (x, y, button)
    Pic.ScreenLoad ("level1enemy2.bmp", 0, 280, picCopy)
    win1 := win1 + 1
    if x > 0 and x < 196 and y > 280 and y < 415 and button = 1 then
        win := win + 1
    else
        timer := 10000
    end if
end enemy2

proc enemy3
    fork bg1
    Mouse.Where (x, y, button)
    Pic.ScreenLoad ("level1enemy3.bmp", 163, 100, picCopy)     %The third enemy
    win1 := win1 + 1
    if x > 163 and x < 359 and y > 100 and y < 331 and button = 1 then
        win := win + 1
    else
        timer := 10000
    end if
end enemy3

Pic.ScreenLoad ("level1.bmp", 0, 0, picCopy)
Pic.ScreenLoad ("beginbutton.bmp", 220, 205, picCopy)
buttonwait ("down", x, y, btn, updown)
if (220  300 and x < 556 and y > 345 and y < 480 and button = 1 then
        fork gun
            win := win + 1
            exit
        end if
       exit when timer >= 1000
    end loop
end enemy1

-----------------------------------
SeeknDestroy
Sun Jan 11, 2004 6:17 pm


-----------------------------------
well, i figured out a lot of the code thnx to all ur help. but now i can't get the timer to work. i declared a variable in every procedure where the enemies appear, and put in  an exit when timer >= 1500 . and it just flashes reallly fast, and i know for a fact that its not the time 1500 cuz the first guy stays for that long, then the rest just flashes by. and here's my code
% Enemy number 1 of level one
procedure enemy1
    fork bg1
    count := count + 1
    loop
        var timer := 0
        clock (timer)
        mousewhere (x, y, button)
        Pic.ScreenLoad ("level1enemy1.bmp", 300, 345, picCopy)
        fork crosshair
        fork bg1
        if x > 300 and x < 556 and y > 345 and y < 480 and button = 1 then
            fork gun
            win := win + 1
            exit
        end if
        exit when timer >= 1500
    end loop
end enemy1

% Enemy number 2 of level 1
procedure enemy2
    fork bg1
    count := count + 1
    loop
        var timer := 0
        clock (timer)
        mousewhere (x, y, button)
        Pic.ScreenLoad ("level1enemy2.bmp", 0, 280, picCopy)
        fork crosshair
        fork bg1
        if x > 0 and x < 196 and y > 280 and y < 415 and button = 1 then
            fork gun
            win := win + 1
            exit
        end if
        exit when timer >= 1500
    end loop
end enemy2

% Enemy number 3 of level 1
proc enemy3
    fork bg1
    count := count + 1
    loop
        var timer := 0
        clock (timer)
        mousewhere (x, y, button)
        Pic.ScreenLoad ("level1enemy3.bmp", 163, 100, picCopy)
        fork crosshair
        fork bg1
        if x > 163 and x < 359 and y > 100 and y < 331 and button = 1 then
            fork gun
            win := win + 1
            exit
        end if
       exit when timer >= 1500
    end loop
end enemy3


-----------------------------------
Dan
Sun Jan 11, 2004 11:55 pm


-----------------------------------
well one thing was  that var timer:= 0 was in the loop, that was probly a bad thing. the other is that i dont think the clock fucttion is wroking the way you whont it to.

i whould use the Time.Sec fuction b/c it is in Secondes not millseconeds and it wroked for this proagme when i tested it.

should look stoming like this:


% Enemy number 3 of level 1 
proc enemy3 
    fork bg1 
    count := count + 1 
    
    var startTime:int := Time.Sec
    var timer:int
    
    loop 
         
        timer := Time.Sec - startTime 
        mousewhere (x, y, button) 
        Pic.ScreenLoad ("level1enemy3.bmp", 163, 100, picCopy) 
   
        fork bg1 
        if x > 163 and x < 359 and y > 100 and y < 331 and button = 1 then 
         
            win := win + 1 
            exit 
        end if 
       exit when timer >= 3 
    end loop 
end enemy3 


Time.Sec returns how many secnonds since 1970.  so what you have to do is take the reading of it b4 the loop then subtrated Time.Sec from  it to get how many seconds have pasted.

NOTES: 1. it is now in seconds not  millsceonds, so you will whont a value like 1-3 not 1500

2. i did not have the code for some of your fuctions so i left them out  of my sample code there

-----------------------------------
SeeknDestroy
Mon Jan 12, 2004 4:20 pm


-----------------------------------
o man, thanks soo much, i really appreciate it, this timer is awesome! thnx!
