Statyk
Schrödinger's Mod
Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation:
241
|
Can a Constant "Get" Script Run?
Okay, I know that sounds funny... but simply, I want the game to check for something every 0.01f second if possible, and when it's not there anymore, another script will run. Is it possible to have a global timer CONSTANTLY run through the map?
|
|
11-09-2011, 12:37 AM |
|
nemesis567
Posting Freak
Posts: 874
Threads: 65
Joined: May 2011
Reputation:
10
|
RE: Can a Constant "Get" Script Run?
Depending on what it calls it may or may not affect performance.
Today I dreamt the life I could live forever. You only know that when you feel it for you know not what you like until you've experienced it.
|
|
11-09-2011, 12:49 AM |
|
Obliviator27
Posting Freak
Posts: 792
Threads: 10
Joined: Jul 2011
Reputation:
66
|
RE: Can a Constant "Get" Script Run?
Would something along the lines of
void OnStart() { AddTimer("timer_1", 0.01, "Check"); } void Check(string &in asTimer) { if([whatever you're looking for is there]) { AddTimer("timer_1", 0.01, "Check"); } else { Whatever else you want to happen }
}
work for you?
|
|
11-09-2011, 12:58 AM |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
RE: Can a Constant "Get" Script Run?
Though i'm not entirely sure of the workings of the global.hps, you could probably define your callback there and then add a timer wherever you need to check for something.
|
|
11-09-2011, 01:26 AM |
|
Statyk
Schrödinger's Mod
Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation:
241
|
RE: Can a Constant "Get" Script Run?
So what you two are saying is that setting a global timer will have it constantly run in that map?
|
|
11-09-2011, 02:00 AM |
|
Your Computer
SCAN ME!
Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation:
235
|
RE: Can a Constant "Get" Script Run?
What i'm saying is, your only chance for a "global" timer may be through global.hps (but i haven't done anything with a global.hps file for my story yet, so i wouldn't know for sure). Otherwise, you're stuck with "local" timers, having to specify the same callback and adding the same timer to all the maps you want check for something constantly.
|
|
11-09-2011, 02:54 AM |
|
palistov
Posting Freak
Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation:
57
|
RE: Can a Constant "Get" Script Run?
(11-09-2011, 02:54 AM)Your Computer Wrote: ...your only chance for a "global" timer may be through global.hps... I've actually tried writing out void functions in the global.hps script but they're not responsive, at least when I tried called them using local scripts. I haven't dug deep into that though, so I may be wrong. But the best way I can think of creating a "global" timer would be using global vars.
global.hps
void OnGameStart() { // how much time is left on the timer? SetGlobalVarInt("TIMERTIME", 100); // the duration of the global timer -- this value doesn't change SetGlobalVarInt("GLOBALTIMERdur", 100); }
map1.hps & map2.hps & map3.hps etc...
// may have to add a looping timer to constantly save the time left, just in case the player saves and exits the game, which does NOT count as OnLeave
void OnEnter() { AddTimer("GLOBALTIMER", GetGlobalVarInt("TIMERTIME"), "CATASTROPHE"); } void OnSaveLoad() // not sure if this even works, but it exists according to Apjjm! :D { AddTimer("GLOBALTIMER", GetGlobalVarInt("TIMERTIME"), "CATASTROPHE"); } void OnLeave() { SetGlobalVarInt("TIMERTIME", GetTimerTimeLeft("GLOBALTIMER")); RemoveTimer("GLOBALTIMER"); }
(This post was last modified: 11-09-2011, 07:23 PM by palistov.)
|
|
11-09-2011, 07:22 PM |
|
Statyk
Schrödinger's Mod
Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation:
241
|
RE: Can a Constant "Get" Script Run?
(11-09-2011, 07:22 PM)palistov Wrote: (11-09-2011, 02:54 AM)Your Computer Wrote: ...your only chance for a "global" timer may be through global.hps... I've actually tried writing out void functions in the global.hps script but they're not responsive, at least when I tried called them using local scripts. I haven't dug deep into that though, so I may be wrong. But the best way I can think of creating a "global" timer would be using global vars.
global.hps
void OnGameStart() { // how much time is left on the timer? SetGlobalVarInt("TIMERTIME", 100); // the duration of the global timer -- this value doesn't change SetGlobalVarInt("GLOBALTIMERdur", 100); }
map1.hps & map2.hps & map3.hps etc...
// may have to add a looping timer to constantly save the time left, just in case the player saves and exits the game, which does NOT count as OnLeave
void OnEnter() { AddTimer("GLOBALTIMER", GetGlobalVarInt("TIMERTIME"), "CATASTROPHE"); } void OnSaveLoad() // not sure if this even works, but it exists according to Apjjm! :D { AddTimer("GLOBALTIMER", GetGlobalVarInt("TIMERTIME"), "CATASTROPHE"); } void OnLeave() { SetGlobalVarInt("TIMERTIME", GetTimerTimeLeft("GLOBALTIMER")); RemoveTimer("GLOBALTIMER"); }
I'm sorry to have put you through all that, but are you saying a GLOBAL function is set for ALL maps? I only need it in one, and I thought LOCAL functions were only at the player. (like, if the player had a variable, say health or sanity). I just need it in one map.
|
|
11-09-2011, 09:52 PM |
|
Apjjm
Is easy to say
Posts: 496
Threads: 18
Joined: Apr 2011
Reputation:
52
|
RE: Can a Constant "Get" Script Run?
If you need it in one map, the following really simple loop will suffice:
const float TIMESTEP = 1.0f / 60.0f;
void OnStart()
{
AddTimer("tmrCheck",TIMESTEP,"cbCheck");
}
void cbCheck(string &in asTimer)
{
// Stuff Here\\
AddTimer(asTimer,TIMESTEP,"cbCheck");
}
Note: OnSaveLoad only exists if you add a timer and routine to check for it (see here if you are interested). This isn't necessary in this case as timers are preserved when the game is saved, and the user cannot save the game in the middle of executing a function. Therefore, in whatever map you want you can really just get away with 1 timer.
(This post was last modified: 11-10-2011, 01:59 AM by Apjjm.)
|
|
11-10-2011, 01:57 AM |
|
palistov
Posting Freak
Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation:
57
|
RE: Can a Constant "Get" Script Run?
Statyk, as far as I know, timers don't carry over between maps. The little script I put together is a possible way to keep track of a timer across multiple maps. A suggestion, if you will. But you'll above to do some testing and see if you can get something working.
|
|
11-10-2011, 10:25 AM |
|
|