8 Replies Latest reply on Aug 3, 2013 1:39 PM by DirBuddy12

    Moving sprite randomly

    DirBuddy12 Level 1

      I have to make a game similar to breakout where a ball moves randomly but a paddle controls how it moves and makes it collide into bricks for points.

       

      This is where I have got so far with my code.

       

      -- sprite 28 is the ball and sprite 27 is the paddle

       

      move sprite(28).locv(random(350) -- I get an message with this line of code saying that a comma is expected

       

        if sprite 28 intersects 27 then sprite(28).locv(+5) -- I don't get an error message with this line but I am not sure whether it works

       

      any help on where I have gone wrong would be very helpful thank you

        • 1. Re: Moving sprite randomly
          Sean_Wilson Adobe Community Professional

          Unless you have a #movie level handler named 'move', thus overloading the in-built #move command, your first line of code won't do anything. FWIW the move command is to move a cast member in the castLib, and you appear to be clutching at straws. Perhaps you could explain what you want this first line of code to do? (I think I know already, but it's often useful to start with plain English then look to break it down and translate into Lingo)

           

          At the very least you have left a dangling unclosed parenthesis:

          move sprite(28).locv( random(350) )

           

          Your next line won't do anything even if the first compiled. I expect you were trying for:

          if sprite 28 intersects 27 then sprite(28).locV = sprite(28).locV + 5

          1 person found this helpful
          • 2. Re: Moving sprite randomly
            DirBuddy12 Level 1

            For the first line I want sprite 28 to move random around the screen but when sprite 28 collides with sprite 27 it makes sprite 28 move upwards.

             

            Does that make more sense?

             

            Does the built in move command help with this?

             

            What's the difference between my second line and yours, why do you have to repeat the same thing for it to work?

            • 3. Re: Moving sprite randomly
              Sean_Wilson Adobe Community Professional

              For the first line I want sprite 28 to move random around the screen but when sprite 28 collides with sprite 27 it makes sprite 28 move upwards.

              Does that make more sense?

              Does the built in move command help with this?

              Did you read the documentation for the 'move' command? If so, does it sound like it will do what you require?

               

              What's the difference between my second line and yours, why do you have to repeat the same thing for it to work?

              The difference is that mine will work while yours won't. Lingo doesn't have an increment-and-apply operator like Flash or other languages do (which in any case would involve syntax like sprite(28).locV += 5). The 'repetition' is there because this is how to get Lingo to do what is intended

              • 4. Re: Moving sprite randomly
                DirBuddy12 Level 1

                I have found some information on the move command but I am still quite confused.

                 

                I don't understand exactly what an actor is, is it just an object or is it a character that needs to be created?

                 

                If it is a character how can the skin be changed on something created in a different program? What is the importance of changing the skins of the actor?

                 

                What does it mean by the "villagers" skin files and them being stored in the world's Monster folder?

                 

                If an actor is not created then the move command won't work, is that right?

                 

                Also can the move command then be set to random numbers instead of set numbers?

                 

                As I want a ball to move freely in the game until it interacts with the paddle which makes it move straight up.

                 

                Any help on this would be very helpful thanks

                • 5. Re: Moving sprite randomly
                  DirBuddy12 Level 1

                  Also I found this code when researching the move code,

                   

                  SCENE 125, "Shop2", SCENE, "Shoe Store", 0, 0

                  ACTOR 1, "Old Carl", "joshVillagers", 3, 20, 80
                  IF -T12, @noYoungCarl
                  ACTOR 2, "Young Carl", "joshVillagers", 15, 50, 80
                  2: I, %0, only appear later, %1, you %3!

                  @noYoungCarl

                  1: I am Old Carl... I am always here.

                  END

                   

                  What does using the @ mean, is noYoungCarl an object or a line in the script?

                   

                  Also why have they used percentages?

                   

                  The creator states that the code creates the Old Carl character actor "1" and have him stand in the lower center, then the player has to have token 12 (T12) to create Young Carl or else it jumps to the label and skips creating Young Carl.

                   

                  What does it mean by token, I understand that it assigns a text description but how do you do that and is it something is seen on screen or do they get the token if it is text?

                   

                  Sorry for all the questions I am just struggling to understand all these new terms and how they work on their own and together.

                   

                  Thanks

                  • 6. Re: Moving sprite randomly
                    Sean_Wilson Adobe Community Professional

                    That's not Lingo or Director (Adobe software) related

                    • 7. Re: Moving sprite randomly
                      Sean_Wilson Adobe Community Professional

                      See below. You have located something unrelated to Adobe Direcotr and are therefore even more confused when trying to apply it.

                       

                      When you have Director open, you can hit F1 to open the associated Help. You can then search this for 'move'. However, there's no point as it doesn't do what you want it to (but I'd hoped you would discover this for yourself, instead you're off on a tangent).

                       

                      You move an object on the stage (a sprite) by altering its location property: sprite().loc or .locV for vertical-only changes and .locH for horizontal-only changes

                      1 person found this helpful
                      • 8. Re: Moving sprite randomly
                        DirBuddy12 Level 1

                        Ok that makes more sense, is there a way to alter the location properties to random numbers so that it moves without being controlled?

                         

                        I am sorry that I am new to this and find it really difficult to change from Java to this language.

                         

                        Thanks for your help