Announcement

Collapse

The Infinity Blade Forums Have Moved

We've launched brand new Infinity Blade forums with improved features and revamped layout. We've also included a complete archive of the previous posts. Come check out the new Infinity Blade forums.
See more
See less

Maybe the dumbest question about the simplest script ever

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

    Maybe the dumbest question about the simplest script ever

    Hello again!
    I'm trying to make a reaaaaally simple game in which some little cookies try to steal sugar to the baker.

    I have only still written the cookies AI (called cookiesAI) and every class this one needs (only definitions of the variables that cookiesAI refers to).

    Code:
    class CookiesAI extends UTBot;
    
    var Actor GusTarget;
    
    auto state Moving
    {
    Begin:
    	MoveTo(GusTarget.Location);
    
    }
    
    event Touch (Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal)
    {
    	if (Other.IsA('GusTarget'))
    		GotoState('Damage');
    	else
    		GotoState('Moving');
    }
    
    state Damage
    {
    Begin:
    
    	GusTarget.sugarBowlHealth--; //this is the line which gives me the error
    	
    }
    
    
    
    defaultproperties
    {
    	GusTarget=sugarBowl
    }
    I know it might be full of mistakes but it's the first game i create by myself without copying pieces of code from here and any correction will be apprecieted.

    Code:
    GusTarget.sugarBowlHealth--;
    UnrealFrontend says: Error, Unrecognized member 'sugarBowlHealth' in class 'Actor'

    If I change that line to
    Code:
    sugarBowl.sugarBowlHealth--;
    UnrealFrontend says: Error, 'sugarBowl': Bad command or expression

    How can i use that variable in CookiesAI??

    PD: If you need it this is currently the code of sugarBowl class:
    Code:
    class sugarBowl extends Actor
    	placeable;
    
    var int sugarBowlHealth;
    Thanks!!

    #2
    I know i should do this by typecasting but i haven't really understood how to do so.

    Comment


      #3
      change: "var Actor GusTarget;" into "var sugarBowl GusTarget;"

      Basically, If GusTarget is an Actor, it can only run the code of Actor, if it's sugarBowl, it knows all sugarBowl code and all Actor code, which is what you want.

      Comment


        #4
        Welcome to programming, where the biggest problems are usually fixed by the simplest of things.

        Comment


          #5
          This should work, did not test it though.
          If you dont manage to make it work , try something easier first,
          read through some more code :P

          ... or show us the log , so we can help you further
          Code:
          class CookiesAI extends UTBot;
          
          // lets say your GusTarget class is 'GusTargetClass'
          var GusTargetClass GusTargetRef;
          
          
          function PostBeginPlay()
          {
              local Actor localActor;
          
              super.PostBeginPlay();
          
          // lets say your GusTarget class is 'GusTargetClass'
          // and you have only one instance of it
          // there is surely a better ways to do it than this one, but its too late....
          
          // iterating through all actors
              foreach AllActors( class 'Actor' , localActor)
              {
          // if typecasting to our class does not fail , it means we found it
                  if (GusTargetClass (localActor) != none )
                  {
          // the first and only instance of GusTargetClass 
                      GusTargetRef = GusTargetClass(localActor);
          // we got the reference , bail out
          	    break;
          // we did it because,
          // if the GusTargetRef is not pointing to an existing actor, its useless to us
          	}
          
              }
          }
          
          auto state Moving
          {
          Begin:
          	if (GusTargetRef != none)
                      MoveTo(GusTargetRef.Location);
          
          }
          
          event Touch (Actor Other, PrimitiveComponent OtherComp, vector HitLocation, vector HitNormal)
          {
          	if (Other.IsA('GusTargetClass'))
          		GotoState('Damage');
          	else
          		GotoState('Moving');
          }
          
          state Damage
          {
          Begin:
          // 'sugarBowlHealth' should be defined in our GusTargetClass
          	if (GusTargetRef != none)
                      GusTargetRef.sugarBowlHealth--; //this is the line which gives me the error
          	
          }
          
          
          
          defaultproperties
          {
          }

          Comment


            #6
            Thanks! I knew i had to be something silly hahaha.

            Originally posted by rednaz View Post
            Welcome to programming, where the biggest problems are usually fixed by the simplest of things.
            When i first started programming in C++ some years ago i remember spending most of the errors correction time writing missing semicolons ¬¬'

            If only every error was so easy to fix...

            Comment


              #7
              Originally posted by AdAstra View Post
              Code:
                  var Actor localActor;
              It says: Error, Instance variables are only allowed at class scope (use 'local'?)

              I tryed this:
              Code:
              var local Actor localActor;
              But it doesn't work either

              Comment


                #8
                local variables are not instantiated with "var"

                try just
                Code:
                local Actor localActor;

                Comment


                  #9
                  lol! Sorry, silly mistake

                  Comment


                    #10
                    happens to the best of us

                    Comment


                      #11
                      thanks autowaaagh! im still i complete noob in UScript

                      Comment

                      Working...
                      X