Aller au contenu

Photo

A really easy problem for the scripting gurus


  • Veuillez vous connecter pour répondre
5 réponses à ce sujet

#1
niapet

niapet
  • Members
  • 41 messages
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?

#2
_Knightmare_

_Knightmare_
  • Members
  • 643 messages
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.

Modifié par _Knightmare_, 09 avril 2011 - 07:42 .


#3
niapet

niapet
  • Members
  • 41 messages
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>
{

Modifié par niapet, 09 avril 2011 - 11:42 .


#4
MasterChanger

MasterChanger
  • Members
  • 686 messages
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.

#5
niapet

niapet
  • Members
  • 41 messages
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
rjshae

rjshae
  • Members
  • 4 507 messages
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?