Author |
Message |
Graeme
|
Posted: Fri Mar 10, 2006 8:43 am Post subject: Need Help wth Time.Elapsed |
|
|
Hello, I am currently working on a program
and i need it so that after every 2 minutes
"health" is decreased by 15%
I know I will need to use Time.Elapsed, But I am unsure how I would get
the health to decrease every 2 minutes
thanks for your help |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Albrecd
|
Posted: Fri Mar 10, 2006 9:14 am Post subject: (No subject) |
|
|
Time.Elapsed gives the number of milliseconds that have passed so far in your program. To use it, you have to have a variable (:int) which must then be given the value of Time.Elapsed. Then when your variable is at the number of milliseconds you want, decrease health. |
|
|
|
|
 |
do_pete

|
Posted: Fri Mar 10, 2006 12:42 pm Post subject: (No subject) |
|
|
Something like this will work:
code: | var startTime := Time.Elapsed
loop
% do stuff
if Time.Elapsed - startTime >= 120000 then
% decrease health
end if
end loop
|
|
|
|
|
|
 |
Graeme
|
Posted: Fri Mar 10, 2006 5:03 pm Post subject: (No subject) |
|
|
Thanks alot for the help
Yeah I previously had a varibale declared
I have
var health : string := "100"
var startTime := Time.Elapsed
loop
if Time.Elapsed - startTime >= 120000 then
put health
end if
end loop
I have that, but now I want to get it so that every 2 minutes, it goes down 25% , so 100,75,50,25,0 etc etc ...i just dont know how i would get it to decrease each 2 mins, i have an idea, but i can't seem to get it to work.
thanks for the help |
|
|
|
|
 |
Cervantes

|
Posted: Fri Mar 10, 2006 6:07 pm Post subject: (No subject) |
|
|
Keep a variable, health_decrease_time that represents the last time the health was decreased.
Turing: |
var health_decrease_time := 0
loop
if Time.Elapsed - health_decrease_time > 120000 then
health_decrease_time := Time.Elapsed
health - = 25
end if
end loop
|
|
|
|
|
|
 |
[Gandalf]

|
Posted: Fri Mar 10, 2006 7:36 pm Post subject: (No subject) |
|
|
Graeme wrote: code: | var health : string := "100"
var startTime := Time.Elapsed
loop
if Time.Elapsed - startTime >= 120000 then
put health
end if
end loop |
Care to tell me why the variable health is a string? It should be an int. |
|
|
|
|
 |
|