Delaying or Waiting Before Checking a Local Variable

I’m hoping I’m asking this clearly enough. Is it possible to delay or wait before checking a local variable, say for example, when entering an area?
Example situation: A PC enters an area and a local Int is set. Is it possible to delay as to when that same local Int is checked for in that same area, say 60 seconds later?

Thanks guys!

Update: I played with the LS Script Generator and found an ActionWait( ) That might work.
With the variable set on the PC, I’m guessing AssignCommand(oPC, ActionWait (60.0));
will wait the 60 sec before checking the following if statement?

That’s not what you want. You can’t slow the execution of a script that way. ActionWait is to control the timing of actions by an NPC for example. Move to location foo, wait 60 seconds, move to location bar, say something…

If I’m understanding what you are asking, what you want is to call DelayCommand(60.0, DoSomething()); in your script where DoSomething() would be a function that checks the variable and does what you want to do if set. This will let the current script (e.g. the area enter script) finish and schedule the DoSomething function to be run 60 seconds later. You can pass it arguments (like the PC maybe in this case).

Thanks for replying. And yes, I eliminated ActionWait. Basically I want a variable set when entering the area. Now, I’ve delayed an action to happen if that variable is the same value. (60 sec.). However, if the variable value changes within the 60 sec. in that same area, I want nothing to happen. What I’m going for is a timed task so if the variable’s value isn’t changed within the 60 sec, the PC will teleport to another area.
Here’s what I have so far:

void Jump(object owaypoint)
{
ClearAllActions();
JumpToObject(owaypoint);
}

void main()
{

// Get the creature who triggered this event.
object oPC = GetEnteringObject();
object owaypoint = GetObjectByTag("wp_someplace");
// Only fire for (real) PCs.
if ( !GetIsPC(oPC)  ||  GetIsDMPossessed(oPC) )
    return;

// Only fire once.
if ( GetLocalInt(GetModule(), "DO_ONCE__" + GetTag(OBJECT_SELF)) )
    return;
SetLocalInt(GetModule(), "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE);

// Set a local integer.

SetLocalInt(oPC, “save_cat”, 0);

// Have the PC perform a sequence of actions.


// If the local int is exactly 0.
if ( GetLocalInt(oPC, "save_cat") == 0 )
{

DelayCommand(60.0,
AssignCommand(oPC,Jump(owaypoint)));
}
else if ( GetLocalInt(oPC, “save_cat”) > 0 )
{
// Do nothing
}
}
I realize the on enter area is only recognizing the first variable value. I hoping to find away to check for that same variable value within the 60 sec.

Checking the variable should be in the Jump() function not in the main part.

void main() {
     // all the other stuff you have before here then
 
     SetLocalInt(oPC, "save_cat", 0);  // or delete it since zero is the same as not set
     DelayCommand(60.0, Jump(oPC, owaypoint));
}

where Jump is now something like

void Jump(object oPC, object owaypoint)
{
       // Check and do nothing 
       if ( GetLocalInt(oPC, "save_cat") > 0 ) return;

       // or do the jump if save_cat is <= 0
       AssignCommand(oPC, ClearAllActions());
       AssignCommand(oPC, JumpToObject(owaypoint));
}

And might be better named checkAndJump or something.

Edit: Fixed quotes around save_cat in jump function

Thanks for trying to help.Really appreciate it. Unfortunately, I couldn’t
get your example to compile. Got an error message on the if(GetLocal… as variable defined
without type.

You need to declare the function Jump before the main section.

I’m lost Pro…I took too many ‘dummy pills’ this morning. Any more help would be greatly appreciated.
You and meaglyn obviously understand what I’m trying to do yet, I’m the dim bulb in the room.

What Proleric said, although I was assuming you already had it before main as in your example. Also, did you change its signature to include the oPC object parameter? You can post your script again and we can take a look.

https://nwnlexicon.com/index.php?title=Void_main

The reason for the errors in @meaglyn’s script are because neither oPC or owaypoint are defined in main() before they are used. Also, in your code as posted here you need in future to put the [code] before the very first line of code and the [/code] after the very last line of code when you post code in here. This has two benefits -

  1. All of your code will be properly highlighted
  2. People will be able to copy the whole of your code using the copy button in the top right of the code box. Makes it easier for people to help you.

Doing so will make your code (with minor edits) look like this -

void Jump(object owaypoint)
{
    ClearAllActions();
    JumpToObject(owaypoint);
}

void main()
{

    // Get the creature who triggered this event.

    object oPC = GetEnteringObject();
    object owaypoint = GetObjectByTag("wp_someplace");

    // Only fire for (real) PCs.

    if(GetIsPC(oPC) && !GetIsDMPossessed(oPC))
    {

        // Only fire once.
        
        if(!GetLocalInt(GetModule(), "DO_ONCE__" + GetTag(OBJECT_SELF)))
        {
            SetLocalInt(GetModule(), "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE);

            // Set a local integer.
            
            SetLocalInt(oPC, “save_cat”, 0);

            // Have the PC perform a sequence of actions.


            // If the local int is exactly 0.
            
            if(GetLocalInt(oPC, "save_cat") == 0)
                DelayCommand(60.0, AssignCommand(oPC, Jump(owaypoint)));
            else if(GetLocalInt(oPC, “save_cat”) > 0)
                // Do nothing
        }
    }
}

Having read what you are trying to do, it should only take a few more minor edits to get it to do that. Try this -

void Jump(object owaypoint)
{
    ClearAllActions();
    JumpToObject(owaypoint);
}

void KittyNotSaved(object oPC, object owaypoint)
{
    if(GetLocalInt(oPC, "save_cat") == 0)
        AssignCommand(oPC, Jump(owaypoint));
}

void main()
{

    // Get the creature who triggered this event.

    object oPC = GetEnteringObject();
    object owaypoint = GetObjectByTag("wp_someplace");

    // Only fire for (real) PCs.

    if(GetIsPC(oPC) && !GetIsDMPossessed(oPC))
    {

        // Only fire once.
        
        if(!GetLocalInt(GetModule(), "DO_ONCE__" + GetTag(OBJECT_SELF)))
        {
            SetLocalInt(GetModule(), "DO_ONCE__" + GetTag(OBJECT_SELF), TRUE);

            // Set a local integer.
            
            SetLocalInt(oPC, “save_cat”, 0);

            // Have the PC perform a sequence of actions.

            DelayCommand(60.0, KittyNotSaved(oPC, owaypoint));
            
        }
    }
}

TR

My script was just a snippet as I mentioned in the comment that says:

// all the other stuff you have before here then

What that means is put in all the other stuff you had before this part from the script you posted. I try not to write full scripts for people as they tend to not learn anything that way.

And no, that’s not the reason for the error he got, which he said was in the “if (GetLocalInt” line in the jump function :slight_smile:

Also TR, you dropped the owaypoint parameter. What you’ve got won’t work…

Looking at what I have there, if you cut and pasted it the quotes around save_cat in the if(GetLocalInt line are wrong. Retype those as normal double quotes and it should compile. I’ll fix my post. (Sorry about that. I thought the triple ` tag would prevent that.)

@meaglyn Sorry about that - my bad. I wasn’t making my post to you but the op and should have made that clearer. Thanks for catching that missing parameter, now fixed.

@Decedion What @meaglyn says about double quotes is another reason to be careful with your [code][/code] positioning. The software that powers these forums will convert ordinary double quotes to the fancy pants 66/99 style unless you use the [code][/code] in the right place.

TR

What about just implementing a simple counter using the area’s OnHeartbeat?

No worries. You do still need to add the owaypoint argument to the call in the DelayCommand though :wink:

Fwiw, the darn quotes were because I copy/pasted that part (being lazy and a bad typist) from OPs original and didn’t notice the string did not get highlighted right…

@verilazic, sure , there are probably dozens of different ways to do this. The one I suggested was to fit in with the direction @Decedion was already going. One of many… :slight_smile:

1 Like

Thanks TR, very much for your response and help!

Thanks meaglyn for your responses and help!

Thanks Proleric for your responses and help!