time.elapsed not working well
Author |
Message |
poolshark1691
|
Posted: Mon Apr 30, 2007 9:43 pm Post subject: time.elapsed not working well |
|
|
Hello, this is my first time posting!
currently i have a time.elapsed function where if it finds that 30 seconds have passed, it goes to a procedure to start a new level of my game. and then what happens is, after 45 seconds, it restarts again, then after 60 seconds, it restarts again... the good thing is, after 30 seconds, it works all fine and dandy, but for the 45+ second stuff, it stops working.
I have two variables:
Turing: |
var time1: int := Time.Elapsed
var time2 : int
restartprocedure %start with restart procedure
time2 : Time.Elapsed
loop
%do my stuff here
%calculate
if time2 - time1 >= 30000 then
%restart
elsif time2 - time1 >= 45000 then
%restart
elsif time2-time1 >= 60000 then
%restart
%and so on
end if
end loop
|
Edited by Clayton: Please remember to use code tags |
|
|
|
|
|
Sponsor Sponsor
|
|
|
rollerdude
|
Posted: Tue May 01, 2007 2:02 pm Post subject: Re: time.elapsed not working well |
|
|
i see your problem and fortunately, i have an answer
now first of all, i'd like to say, before clayton edits your post, that when you submit code, you put in the code tages (when you write your post, click on "more tags" then on "code")
this way, it makes it easier to distiguish from your post
second, i have noticed that you use elsif, thats fine, but the way you have it set up, is that the first part of your if statment (the part that says if time2-time1>=30000 then...)
will always return true, and then skip the rest of the statment. for this to work, you will have to write the time in reverse, like so:
code: |
if time2-time1>=60000 then
%enter proc here
elsif time2-time1>=45000 then
%enter proc here
elsif time2-time1 >=30000 then
%and so on
end if
|
P.S. see what i mean about code tags? |
|
|
|
|
|
rollerdude
|
Posted: Tue May 01, 2007 2:04 pm Post subject: Re: time.elapsed not working well |
|
|
sorry, but by the way... time2:=Time.Elapsed has to be in loop
keep on working! |
|
|
|
|
|
poolshark1691
|
Posted: Tue May 01, 2007 7:41 pm Post subject: Re: time.elapsed not working well |
|
|
Thank you very much for your response
I made an error with time2, it should go before restartprocedure. Because i want it to count it once that procedure has started.
Could you please tell me what is wrong with "elsif"? should i jus be using standalone "if" statements?
And i will remember to use the code tag next time!!! Sorry for the mistake!
Alright, i now have a level system, where after each time interval (so 30 seconds, 45 seconds, etc.) the level increases and it evaluates the timelimit based on the level.
So:
code: |
var time2 : int
var time1 : int
var level : int
%the game occurs here
%now, the following could be in a procedure, or just part of the mainline program.
time2 : Time.Elapsed
loop
time1 : Time.Elapsed
if level = 1 and time2-time1 >= 30000 then
level += 1
%and restart the game with the new level
elsif level = 2 and time2 - time1 >= 45000 then
level += 2
%and restart the game with the new level
end if
end loop
|
and the level increase and evaluation of timelimit go for 10 levels, with the 10th level evaluating for 165 seconds.
and i am still having the problem. |
|
|
|
|
|
rollerdude
|
Posted: Wed May 02, 2007 9:51 am Post subject: Re: time.elapsed not working well |
|
|
elsifs are fine, but maybe i'l' have to explain again...
code: |
if time2 - time1 >= 30000 then
%restart
elsif time2 - time1 >= 45000 then
%restart
elsif time2-time1 >= 60000 then
%restart
%and so on
end if
|
after 30 seconds the line "if time2 - time1 >= 30000 then"
will always return true, regarless of what time it is, because 46000 is greater than 30000..
so...
for this to work, you will have to write your times in reverse, meaning that instead of 30000 then 45000 then 60000, you will have to have 6000 THEN 45000 THEN 30000 like so...
code: |
if time2 - time1 >= 60000 then %this will check if 60 seconds has past b4 30
%restart
elsif time2 - time1 >= 45000 then
%restart
elsif time2-time1 >= 30000 then %see what i mean?
%restart
%and so on
end if
|
i hope this will help... |
|
|
|
|
|
poolshark1691
|
Posted: Fri May 04, 2007 7:14 pm Post subject: Re: time.elapsed not working well |
|
|
I wanna apologize for not replying sooner. I want to let you know that your help worked.
Thank you very much! |
|
|
|
|
|
|
|