Issue with stopwatch
Author |
Message |
darkage43
|
Posted: Mon May 30, 2011 6:38 pm Post subject: Issue with stopwatch |
|
|
What is it you are trying to achieve?
I'm trying to add a stopwatch which acts as the score to my pong game.
What is the problem you are having?
Whenever I place my stopwatch code into my program, it either freezes the program or the stopwatch doesn't appear.
Describe what you have tried to solve this problem
I tried placing the code into different areas of my program but it doesn't seem to do anything.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
View.Set ("offscreenonly")
var ballx, bally : int := 200
var x, y : int := 1
var box : int := 170
var chars : array char of boolean
var count : int := 0
loop
Input.KeyDown (chars)
Draw.FillBox (0, 0, maxx, maxy, black)
drawfillbox (10, box, 20, box + 95, red)
drawfilloval (ballx, bally, 6, 6, white)
delay (2)
View.Update
if chars (KEY_UP_ARROW) then
box += 2
elsif chars (KEY_DOWN_ARROW) then
box -= 2
end if
ballx := ballx + x
bally := bally + y
if bally > 390 then
y := -1
elsif bally < 10 then
y := 1
elsif ballx > 635 then
x := -3
end if
if box > 320 then
box := 320
elsif box < 0 then
box := 0
end if
if ballx < 30 and bally > box and bally < box + 95 then
x := 1
end if
if ballx < 0 then
ballx := 600
bally := 250
delay (3000)
end if
%%%TIMER%%%
%put count
%exit when count = 100000
%count += 1
%delay (1000)
%cls
end loop
Please specify what version of Turing you are using
4.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
goroyoshi
|
Posted: Mon May 30, 2011 6:41 pm Post subject: RE:Issue with stopwatch |
|
|
look into Time.Elapsed |
|
|
|
|
|
darkage43
|
Posted: Mon May 30, 2011 6:43 pm Post subject: RE:Issue with stopwatch |
|
|
I already tried Time.Elapsed and the same problem still occurs. I'm thinking that the problem has to do with my Draw.FillBox line. Sorry that I didn't use syntax tags, I forgot. |
|
|
|
|
|
goroyoshi
|
Posted: Mon May 30, 2011 6:55 pm Post subject: RE:Issue with stopwatch |
|
|
well i got it to work with time.elapsed, colorback and color without lag
just remember that in graphics the computer priroritizes the line that is the farthest down ()
would output ho |
|
|
|
|
|
darkage43
|
Posted: Mon May 30, 2011 7:21 pm Post subject: RE:Issue with stopwatch |
|
|
Okay I changed it to Time. Elapsed, added colour, and added location but it still won't appear. This is what I got so far.
Turing: |
View.Set ("offscreenonly")
var ballx, bally : int := 200
var x, y : int := 1
var box : int := 170
var chars : array char of boolean
var sec : int := 0
loop
if round (Time.Elapsed / 1000) > sec then
cls
sec + = 1
locate (1, 1)
colour (yellow)
put sec
end if
Input.KeyDown (chars )
Draw.FillBox (0, 0, maxx, maxy, black)
drawfillbox (10, box, 20, box + 95, red)
drawfilloval (ballx, bally, 6, 6, white)
delay (2)
View.Update
|
|
|
|
|
|
|
goroyoshi
|
Posted: Mon May 30, 2011 7:25 pm Post subject: RE:Issue with stopwatch |
|
|
1. your forgetting the prioritization
2. just use put Time.Elapsed div 1000
3. your forgetting colorback (whatever colour your using for the background)
4. you dont need a locate that was to use text in prioritization in the same spot
5. Time.Elapsed returns as an int no need for round |
|
|
|
|
|
darkage43
|
Posted: Mon May 30, 2011 7:52 pm Post subject: RE:Issue with stopwatch |
|
|
So as in prioritization, you mean to put my Time.Elapsed after the Draw.FillBox. Ok this is what I got now.
Turing: |
View.Set ("offscreenonly")
var ballx, bally : int := 200
var x, y : int := 1
var box : int := 170
var chars : array char of boolean
loop
Input.KeyDown (chars )
Draw.FillBox (0, 0, maxx, maxy, black)
drawfillbox (10, box, 20, box + 95, red)
drawfilloval (ballx, bally, 6, 6, white)
delay (2)
View.Update
locate (1, 1)
colourback (black)
colour (yellow)
put Time.Elapsed div 1000
|
|
|
|
|
|
|
darkage43
|
Posted: Mon May 30, 2011 7:54 pm Post subject: RE:Issue with stopwatch |
|
|
Wait never mind I solved it now. I just had to put that part directly after Draw.FillBox. I greatly appreciate the help goroyoshi, thank you. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
goroyoshi
|
Posted: Tue May 31, 2011 6:53 pm Post subject: RE:Issue with stopwatch |
|
|
your post before just needed the put statement before the View.Update |
|
|
|
|
|
darkage43
|
Posted: Tue May 31, 2011 9:18 pm Post subject: RE:Issue with stopwatch |
|
|
Oh I understand now. The View.Update has been messing my program up. I placed the View.Update to early which caused so much problems for me. Now I placed it near the end, now my program works fine. =D |
|
|
|
|
|
|
|