Hi all,
I need to run a script in my module every five minuets. I know this should be simple but I am not really sure how to go about doing it.
Any ideas?
A really easy problem for the scripting gurus
Débuté par
niapet
, avril 09 2011 06:25
#1
Posté 09 avril 2011 - 06:25
#2
Posté 09 avril 2011 - 07:41
As the last line of your code, you need to use:
DelayCommand(300.0, ExecuteScript("name of this script", oObjectToRunOn));
This is what is known as a "pseudo-heartbeat" - a script that executes itself after a determined amount of time.
DelayCommand(300.0, ExecuteScript("name of this script", oObjectToRunOn));
This is what is known as a "pseudo-heartbeat" - a script that executes itself after a determined amount of time.
Modifié par _Knightmare_, 09 avril 2011 - 07:42 .
#3
Posté 09 avril 2011 - 11:41
I thought of that but what I need is for it to run EVERY 5 minuets.
It is a really simple script I just need to execute the ExportAllCharacters function (I made a separate script called "_save_characters" for that so i can call it from another script with the ExecuteScript function). I want the module to do that every 5 min. If I just put:
void main()
}
DelayCommand(300.0, ExecuteScript("_save_characters", GetModule));
{
Then it looks like that would simply wait 5 min and then run the script and end. Is there perhaps a way to tell the scipt to go back to the begining and start over again after it executes the delayed script? like this:
void main()
}
DelayCommand(300.0, ExecuteScript("_save_characters", oObjectToRunOn));
<Some Function That Starts This Script Over Again Here>
{
It is a really simple script I just need to execute the ExportAllCharacters function (I made a separate script called "_save_characters" for that so i can call it from another script with the ExecuteScript function). I want the module to do that every 5 min. If I just put:
void main()
}
DelayCommand(300.0, ExecuteScript("_save_characters", GetModule));
{
Then it looks like that would simply wait 5 min and then run the script and end. Is there perhaps a way to tell the scipt to go back to the begining and start over again after it executes the delayed script? like this:
void main()
}
DelayCommand(300.0, ExecuteScript("_save_characters", oObjectToRunOn));
<Some Function That Starts This Script Over Again Here>
{
Modifié par niapet, 09 avril 2011 - 11:42 .
#4
Posté 09 avril 2011 - 11:50
In order to loop the script, the script calls itself again, and again, and again. So, if the script in question is called, "_save_characters", then at the end of "_save_characters" itself, you run an ExecuteScript("_save_characters", GetModule()) or whatever. And you delay that command by the appropriate interval.
This means that the script gets to the last line, calls itself again, and finishes. When that time interval ends, a new copy of the script starts again.
This means that the script gets to the last line, calls itself again, and finishes. When that time interval ends, a new copy of the script starts again.
#5
Posté 10 avril 2011 - 03:14
Ah, it sounds so simple now, why didn't I think of that? Should I put that in the user defined event handler? Will the fact that it it looping hurt the PW performance or will it be ok since it is delayed for 5min before re-executing?
#6
Posté 11 avril 2011 - 06:18
I haven't noticed any significant performance hits from having the module run a delayed command (other than the overhead of actually running the command).
Are you going to call this from the module's On Module Load Script slot so that it will restart whenever the game is launched?
Are you going to call this from the module's On Module Load Script slot so that it will restart whenever the game is launched?





Retour en haut






