problem with a condition

Posted By: JazzDude

problem with a condition - 12/25/07 02:34

My game uses this method to keep track of the year.



Code:
var week = -60; //60 seconds make a week
var_nsave count_time = 1815; //starting year number

function Year_startup() //calculates year
{
while(count_time >= 0)
{
wait(week);
wait(week);
wait(week);
wait(week);
count_time += 1;
wait(1);
}
}



That works as it is supposed to. The year number changes after the set amount of time.

But when I use count_time in a condition like this:

Code:
if(count_time > 1816)
{
wait(-5);
bronze_pan.visible = on;
set_mouse(2);
}



nothing happens. What am I missing?
Posted By: Moerk

Re: problem with a condition - 12/25/07 03:59

I´m not sure but i think the while loop is endless!

"while count_time is higher or equal 0 add 1 to count_time"

After count_time get the value "1816" its still over 0. The While loop again waits 240 seconds and then adds 1 to count_time.

maybe you can write your code like that

Code:

var week = -60; //60 seconds make a week
var_nsave count_time = 1815; //starting year number

function Year_startup() //calculates year
{
while(count_time >= 0 && count_time <= 1816)
{
wait(week);
wait(week);
wait(week);
wait(week);
count_time += 1;
wait(1);
}

wait(-5);
bronze_pan.visible = on;
set_mouse(2);
}



Another possibility is that:

Code:

var week = -60; //60 seconds make a week
var_nsave count_time = 1815; //starting year number

function Year_startup() //calculates year
{
while(count_time >= 0)
{
wait(week);
wait(week);
wait(week);
wait(week);
count_time += 1;
if (count_time > 1816)
{
wait(-5);
bronze_pan.visible = on;
set_mouse(2);
// proc_kill(1);
}
wait(1);
{
}


Posted By: JazzDude

Re: problem with a condition - 12/25/07 05:06

Thank you, Moerk. Neither suggestion worked, but I suspect you are right about the endless loop being the culprit. I can't see anything else to suspect.
Posted By: JazzDude

Re: problem with a condition - 12/25/07 05:07

I think I'll give it a rest and go watch for Santa Claus.
Posted By: vlau

Re: problem with a condition - 12/25/07 09:22

The count_time won't update when you put all the codes
in a single loop, it just keep waiting....

It should work if you put the if statement to another function
since the engine can handle multiple processes at the same time.

Code:

function check_count_time()
{
if(count_time > 1816)
{
wait(-5);
bronze_pan.visible = on;
set_mouse(2);
}
}

function Year_startup() //calculates year
{
while(count_time >= 0)
{
wait(week);
wait(week);
wait(week);
wait(week);
// bTW, why not write : wait(week*4);

count_time += 1;

check_count_time();
wait(1);
}
}


Posted By: Moerk

Re: problem with a condition - 12/25/07 10:12

Alright... it was late tonight and these ideas were my only ones.

I think "vlau" has the answer. Try it!

Merry Christmas!
Posted By: JazzDude

Re: problem with a condition - 12/25/07 16:31

Vlau: Once again you have solved my problem. Thanks. That works.

But I have about a hundred instances where the year is a condition in my strategy codes. I hope I can find a way to avoid adding every function to the Year_startup function.

As to your other suggestion, there is something screwy with the engine when it comes to time. Try this function and you'll see what I mean.

Code:

var week = -60;
fps_max = 60;
function time_check()
{

wait(week);
wait(week);
wait(week);
wait(week); //4 minutes elapse
beep();

wait(week*4); // 65 seconds elapse
beep();
}



I had to use this workaround in the Lost Dutchman with A5 and it wasn't cured in A6. I don't know about A7.
Posted By: vlau

Re: problem with a condition - 12/26/07 08:16

If you're checking with the same year, just put all
the if statements in check_count_time(), should work.

Yeah, wait(week*4) doesn't work correctly, but it
works with smaller value such as week = 1.
© 2024 lite-C Forums