Announcement

Collapse
No announcement yet.

How to Pause Code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to Pause Code

    Here's a fun question... how does one pause code execution in UT2K4 for a set interval? In my (very old school programming) classes we did it by having the program execute a highly numbered loop, but you'd think there'd be a better way in current stuff, right?

    Here's a sample of some code I'm playing with that targets an xPawn...

    Code:
    a.Skins[1] = Texture'LipSyncTextures.Sarah.SarahHead_A';
    //I'd like a 1 second pause here
    a.Skins[1] = Texture'LipSyncTextures.Sarah.SarahHead_E';
    Any suggestions on a good way to add that 1 second pause? (it's an arbitrary value for testing, not final... working on baby steps here).

    I've experimented with the SetTimer command but it either gives me a compile error or doesn't affect the xPawn/ScriptedController as I wish.

    #2
    Just tell them to go sleep
    Code:
    // Latent functions.
    native(256) final latent function Sleep( float Seconds );
    from actor.uc

    Comment


      #3
      Yeah, but doesnt the sleep function only actually work when called as part of a State?

      like
      Code:
      state myState
      {
        Begin:
        Sleep(.10);
      }
      Cause whenever I tried to call it out of state code, it would say that it was not allowed here...

      Comment


        #4
        Thanks both...

        Getting a few compiler errors and playing with it... good direction for moving forward though. I'm going to try having my xPawn go to a state of sleep from the function and see if that combo works...

        Comment


          #5
          yeap cknight has a point.
          latent code can only be called inside states

          Comment


            #6
            The problem I had with freezing pawns that way was that I never knew what state to put them back to when the "freeze" state was done.

            And hey, the reason SetTimer doesnt always work out is because there are different Timer functions that are called depending on what state your in.

            So if you override the Timer function in the "main body" of the code (not in a state), that function may never even be called.

            You MIGHT be able to use Tick with a counter, which is sort of like what you were talking about (the whole for x=0 to 100 thing from basic. If thats what you were talking bout).

            So you have a variable set to 0, then in the Tick function. Then wherever your setting the skin you say
            Code:
              if(myVariable > 1000) // or whatever
                a.skins[1]=blah
              else
                a.skins[1]=blahdyblah
            Not the most efficient, but it would prob work. And you wouldnt have to mess with states.

            Comment


              #7
              Couldn't you just use a timer? So when you want to cause this you could just use ..

              Code:
              SetTimer(1, false);
              then have

              Code:
              function timer()
              {   
                  a.Skins[1] = MyTextures[iTexture];
              
                   iTexture += 1;
                   if (iTexture < MyTextures.Length) SetTimer(1, false);
              }
              (in defaults)
              MyTextures[0] = Texture'LipSyncTextures.Sarah.SarahHead_A';
              MyTextures[1] = Texture'LipSyncTextures.Sarah.SarahHead_A';

              ian

              Comment


                #8
                Good points all around... just to throw out what I'm working with now...

                I've tried to basically combine the functions of the ACTION_WaitForTimer script and the Action_DESTROYTarget script.

                I created the script Action_TEXLipSync by expanding the LatentScriptedAction ACTION_WaitForTimer. I took the target pawn code from Action_DESTROYTARGET and modified it to change the skin of the targeted xPawn instead of destroying it.

                So far I have gotten the script to change a skin and then pause, (using the SetTimer method you'll find in ACTION_WaitForTimer) but I couldn't get it to do the second skin swap after the timer expired, which leads me to think I'm screwing up my use of booleans somewhere. I'll post the source after I play with it some more.

                Comment


                  #9
                  You MIGHT be able to use Tick with a counter, which is sort of like what you were talking about (the whole for x=0 to 100 thing from basic. If thats what you were talking bout).
                  Exactly what I was thinking... LOL, the days of BASIC...

                  So you have a variable set to 0, then in the Tick function. Then wherever your setting the skin you say


                  [code:]
                  if(myVariable > 1000) // or whatever
                  a.skins[1]=blah
                  else
                  a.skins[1]=blahdyblah
                  --------------------------------------------------------------------------------
                  [/code]

                  Not the most efficient, but it would prob work. And you wouldnt have to mess with states.
                  I may try that as a last resort, but it does sound like it would be inefficient (and the timing would probably vary based on the speed of the CPU). Thanks for the tips though, you've all been very helpful so far.

                  Comment


                    #10
                    When timing stuff in Tick, the paramter sent in is key. (deltaTime)

                    so each tick all you have to do is something like
                    Code:
                    function Tick(float DeltaTime)
                    {
                    timer += deltaTime;
                    if(timer > 1.0)
                    {
                    //do my stuff
                    timer -= 1.0; //or if after the change you need exactly 1 second
                    timer = 0.0; //use this instead of line above
                    }
                    }

                    Comment


                      #11
                      I've been playing with a number of options (including having my controller go to a state, setting timers a number of ways, and even some random very high loops), but nothing thus far has done the trick. I'm still working, but wanted to post the code so perhaps someone will have a better idea/method for implementing a pause.

                      Code:
                      //=============================================================================
                      
                      // AIScript action to implement texture based lipsyncing
                      
                      //=============================================================================
                      
                      class ACTION_TEXLipSync extends ScriptedAction;
                      
                      //Currently gotta load the texture file where the skins reside... eventually
                      //the texture file/directory will be set the same as the Skin1 (Head) on the
                      //xPawn being targeted, so this can then go away.
                      #exec OBJ LOAD FILE=LipSyncTextures.utx
                      
                      var(Action) float LipSyncTime; //Eventually this will set the pause value
                      var(Action) name Target; //This tells the action what xPawn skin to change
                      var(Action) localized string AnimationString; //Eventually parse for swap order
                      
                      function bool InitActionFor(ScriptedController C)
                      {//start function
                      
                          local Actor a;
                          local int i;
                      
                          //Starting a loop, the upper limit of which will eventually be set by the
                          //length of the AnimationString
                          for(i=0; i<2; i++)
                          {//start loop
                      
                          if(Target != 'None')
                      	{//start if
                      		//Find all xPawns with the name specified in 'Target'
                              ForEach C.AllActors(class'Actor', a, Target)
                              {//start ForEach
                      
                              //Eventually we will parse the letters in AnimationString in sequential
                              //order and display a different skin during that iteration of the loop
                              //based on the letter in the string. For now, we are using hardcoded
                              //skins for testing (baby steps)
                              if(i==0)
                              {
                              a.Skins[1] = Texture'LipSyncTextures.Sarah.SarahHead_A';
                              }
                              else
                              {
                              a.Skins[1] = Texture'LipSyncTextures.Sarah.SarahHead_E';
                              }
                      
                              }//close ForEach
                      
                          //We need to insert a 1 second pause here so the loop will pause a second
                          //before the next iteration of its skinswap. Eventually the length of the
                          //pause will be set by the LipSyncTime value, for now my next babystep is
                          //just to hardcode a 1 second delay somehow.
                          //
                          // 1 second pause code???
                      
                          }//close if
                      
                          }//close loop
                          return false;
                      }//close function
                      
                      function string GetActionString()
                      {
                      	return ActionString@Target;
                      	return ActionString@LipSyncTime;
                      }
                      
                      defaultproperties
                      {
                          ActionString="Fire TextureSync"
                      	LipSyncTime=1.000000
                      }
                      So, there we go... the segment I'm currently concentrating on is highlighted in red. Any help is appreciated, I'll post here if I figure something out.

                      Comment


                        #12
                        Problems found so far

                        make it != None.... no quotes
                        The AllActors is a bit much... you could probably use DynamicActors or at least class'xPawn' .

                        Other than that you may have to rewrite the function a different way for sleeping... so its called every second instead of how its being done right now.

                        Comment


                          #13
                          MrSlate,

                          Thanks for the comments.

                          make it != None.... no quotes
                          I think this actually refers to a field in the ScriptedAction that's a String... if you delete the value out of there, it defaults to the text 'none' in the editor. That's why (I think) it's a string, as I pulled this from another ScriptedAction script, and they all work like that for the most part.

                          The AllActors is a bit much... you could probably use DynamicActors or at least class'xPawn' .
                          Good point, I'll play with that... this came from ACTION_DestroyActor originally, so I bet that's why the AllActors is in there (since it could be called upon to destroy any number of actor types).

                          Other than that you may have to rewrite the function a different way for sleeping... so its called every second instead of how its being done right now.
                          Yeah I think that might be a good approach... I was just looking at ACTION_FadeView and it looks to have a setup similar to what I'd like to do with this script... I'm going to play with that approach and post here if it works.

                          Comment


                            #14
                            BOOYAH!

                            Sweetness. Managed it. Had to take a different tack but it works. Basically the big secret was simply to move the skinswapping routine into the Pawn script. That opened up a whole slew of new options including using the 'Sleep' command for pauses (you can't use Sleep in a ScriptedSequence because it is static).

                            Here's the end result.

                            First, extended a new xPawn called xSyncPawn. Here's the code.

                            Code:
                            class xSyncPawn extends xPawn;
                            
                            #exec OBJ LOAD FILE=LipSyncTextures.utx
                            
                            state SwappingSkins
                            {
                            Begin:
                                Skins[1] = Texture'LipSyncTextures.Sarah.SarahHead_A';
                                Sleep(1.0);
                                Skins[1] = Texture'LipSyncTextures.Sarah.SarahHead_E';
                                Sleep(1.0);
                                goto('Begin');
                            
                            }
                            Next, added a new ScriptedAction to the editor, ACTION_StartLipping. Here's the code....

                            Code:
                            //=============================================================================
                            
                            // AIScript action to implement texture based lipsyncing
                            
                            //=============================================================================
                            
                            class ACTION_StartLipping extends ScriptedAction;
                            
                            var(Action) name Target; //This tells the action what xPawn skin to start swapping
                            
                            function bool InitActionFor(ScriptedController C)
                            {//start function
                            
                                local Actor a;
                            
                                if(Target != 'None')
                            	{//start if
                            		//Find all xPawns with the name specified in 'Target'
                                    ForEach C.AllActors(class'Actor', a, Target)
                                    {//start ForEach
                            
                                    a.GotoState('SwappingSkins');
                            
                                    }//close ForEach
                            
                                }//close if
                            
                                return false;
                            }//close function
                            
                            function string GetActionString()
                            {
                            	return ActionString@Target;
                            }
                            
                            defaultproperties
                            {
                                ActionString="Start Talking"
                            }

                            BOOYAH. Fairly **** easy. All I did then was add an xSyncPawn to my level, add the ACTION_StartLipping command to it's AIScript, and watch the magic of skinswapping unfold.

                            Again, this is a babystep as I have much more customization planned (perhaps the the final version will pass a string from the ScriptedSequence to the State of the xPawn which will tell it which skins to display... still debating). But, I wanted to post it because I've noticed people have similiar problems.

                            Comment

                            Working...
                            X