Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can a Constant "Get" Script Run?
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#1
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
Find
nemesis567 Offline
Posting Freak

Posts: 874
Threads: 65
Joined: May 2011
Reputation: 10
#2
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
Find
Obliviator27 Offline
Posting Freak

Posts: 792
Threads: 10
Joined: Jul 2011
Reputation: 66
#3
RE: Can a Constant "Get" Script Run?

Would something along the lines of
PHP Code: (Select All)
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
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#4
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.

Tutorials: From Noob to Pro
11-09-2011, 01:26 AM
Website Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#5
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
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#6
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.

Tutorials: From Noob to Pro
11-09-2011, 02:54 AM
Website Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#7
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
PHP Code: (Select All)
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...
PHP Code: (Select All)
// 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
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#8
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
PHP Code: (Select All)
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...
PHP Code: (Select All)
// 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
Find
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#9
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
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#10
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
Find




Users browsing this thread: 2 Guest(s)