Jump to content

timer stops after interval


testgenord1
 Share

You are about to reply to a thread that has been inactive for 946 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi!
I've got a script that works as follows:

- When the object is touched,
a timer event is started.

- After a certain time span ("interval") the script is supposed to implement an action.

- After a longer time span ("playingtime") the script is supposed to reset.

- When the object is touched for a second time, a different action is supposed to be implemented.
The timer is supposed to continue throughout.

 

What happens is the following:

When the object is touched twice in a row, everything works the way it is supposed to.

However, when the object is touched just once, the timer keeps running until "interval", then performs the action associated with it,
but then stops running afterwards, although "playingtime" has not been reached yet.
The touch_start event is not responding any more, either.

The problem seems to lie in the "interval" part, but I just can't figure it out.


Maybe you have an idea of how to solve this issue?
Thank you very much in advance!


Here is the script:

integer on;
integer seconds;
integer interval = 10;
integer ttime;
integer playingtime = 30;

touch_start(integer number)
{
	if(on == FALSE)
	{
     	llSetTimerEvent(1.0);
		'do something'
		on = TRUE;
	}
	else
	{
		'do something else'
		on = FALSE;
	}
}
timer()//is only started when on == FALSE
{
	++seconds;
    ttime = playingtime - seconds;
    llSetText("time left (in seconds):\n \n " + (string)ttime, <1.0, 1.0, 1.0>, 1.0);
    if(seconds == interval)
    { 
       	'do something else again'//This action is still implemented. But then the timer stops and touch_start does no longer respond.
      	on = FALSE;
    }
    else if(ttime == 0)
    {
        llResetScript();
    }
}

 

Link to comment
Share on other sites

It's easier to create a global variable "timerAction" and use it to determine what should be done. 

In your case, the touch events would change timerAction so let's assume it is first set to "start"

If the timer counter reaches a certain value and timerAction == "start"you know there wasn't a touch and act accordingly.

But if a touch occurs when timerAction == "start" you then set timerAction = "touched" and maybe adjust another value of next seconds. The next time that timer  occurs it sees there has been a touch, and acts accordingly.

 

You can find an example of using such a variable together with different length timerevent settings in the region monitoring scripts for keyframedmotion and motetotarget I have posted in the scripts library forum

 

Edited by Profaitchikenz Haiku
  • Like 1
Link to comment
Share on other sites

20 minutes ago, Profaitchikenz Haiku said:

It's easier to create a global variable "timerAction" and use it to determine what should be done. 

In your case, the touch events would change timerAction so let's assume it is first set to "start"

If the timer counter reaches a certain value and timerAction == "start"you know there wasn't a touch and act accordingly.

But if a touch occurs when timerAction == "start" you then set timerAction = "touched" and maybe adjust another value of next seconds. The next time that timer  occurs it sees there has been a touch, and acts accordingly.

 

You can find an example of using such a variable together with different length timerevent settings in the region monitoring scripts for keyframedmotion and motetotarget I have posted in the scripts library forum

 

Thank you very much for your quick reply.
I couldn't find the scripts you mentioned through search terms here.
Do you maybe remember the approximate topic / title of the threat?
Thank you!

Link to comment
Share on other sites

  • testgenord1 changed the title to timer stops after interval
On 12/18/2021 at 8:51 PM, testgenord1 said:

What happens is the following:

When the object is touched twice in a row, everything works the way it is supposed to.

However, when the object is touched just once, the timer keeps running until "interval", then performs the action associated with it,
but then stops running afterwards, although "playingtime" has not been reached yet.
The touch_start event is not responding any more, either.

The problem seems to lie in the "interval" part, but I just can't figure it out.

 

I used the portion of your script to replicate the issue, but it seemed to work as expected, so I am inclined to believe that your issue is in the "Do something else" part of your script. Does the "do something else" do anything with the timer, or, more likely, is it in a different state in the script that does not have a touch_start event?

  • Like 1
Link to comment
Share on other sites

I"m with Bugs on this.  in in the timer at "interval" you have "do something else again".  If you are hitting that, doing that, and then things stop working as expected, my first instinct is that 'doing something else again' is where your fault lies.   Nothing in the logic of the code block shared would cause the script to fail as you describe.

  • Like 2
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 946 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...