Announcement

Collapse
No announcement yet.

Exec Functions within States?

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

    Exec Functions within States?

    Having a problem getting these things to work within states.

    I have approximately the following code:
    Code:
    state WaitForStuff
    {
        function BeginState()
        {
            log("Entered"); // this gets logged properly
        }
    
        exec function Blah()
        {
            log("Blah");
        }
    }
    The class that this lies in extends GameInfo, so the exec functions should be valid. The state is being entered because "Entered" is logged. However, whenever I try to run "Blah" from the console, I get an "Unrecognized Command" error. Any idea what's wrong here? Thanks!

    #2
    You may have to define a Blah() function outside of state code.

    like outside your state code:
    Code:
    exec function Blah()
    {
      log("blah outside state");
    ]
    
    state WaitForShyte
    {
      
        function BeginState()
        {
            log("Entered"); // this gets logged properly
        }
    
        exec function Blah()
        {
            log("Blah in state");
        }
    }
    I may be wrong, but I dont think that functions that are defined ONLY in states will work out.

    Comment


      #3
      i have tons of functions already in state code only, but i have a feeling you may be right with regard to exec functions. perhaps they'll only work if they're global...

      Comment


        #4
        So what happens if something tries to call that function, but your object is not in the state?

        The functions that are in state only, are the only things that call that function within the same states?

        Comment


          #5
          the compiler won't allow you to call those functions from anywhere OUTSIDE that state, only from within. so really they're just more for nice little packaging and naming, etc.

          Comment


            #6
            Well it certainly makes sense to have state only functions, I just didnt know if the compiler would like it.

            Did it work out for the execs?

            Comment


              #7
              they were originally global -- i was just trying to localize them to prevent spaghetti code. so basically i put it back to the way it was and it works again. but now everything is hunky-dorey, thanks! (except for the drawscale3d/lighting issues -- but that's in my other post).

              Comment


                #8
                Right but does it allow you to call a state specific exec function?

                Comment


                  #9
                  nope, it seems it can't find them. had to make all exec functions global.

                  Comment


                    #10
                    You could always have the exec function check the state when it's called, if you wanted to limit it.

                    Dicky B

                    Comment


                      #11
                      yeah, or use state Whatever { ignores BadFunction; } as i am now.

                      Comment


                        #12
                        If it works, it works.

                        Dicky B (and that's how it should be)

                        Comment

                        Working...
                        X