Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.

Reply
 
Thread Tools
  #1    
Old December 8th, 2012 (8:57 AM). Edited December 15th, 2012 by carmaniac.
carmaniac's Avatar
carmaniac carmaniac is offline
Where the pickle surprise at?
     
    Join Date: Apr 2009
    Location: England
    Age: 22
    Nature: Relaxed
    Posts: 682

    Scripting 101, things you may want to know.

    Index:


    Section 1: Images.
    Section 2: Pokémon.

    Hello, and welcome to Carmaniac's; Scripting, things you may want to know. In this thread, I shall be providing most functions within codes that people may want to know, but can't seem to find the help to learn it. For instance, how to show images, how to add in text, how to do checks for Pokémon, or anything else you guys would like to learn.





    Section 1: Images.


    In this section, we shall learn the basic commands on how to load up images. To begin with, we shall start by seeing what type of variables there are, that we can use to first, define an image. There's two different ways you can conduct this. You can create an array, to display the images, which, is easier to remove all the images when the script ends. Or you can use a standard variable to display the image. Examples below:

    @sprites = {} #This line is crucial if you want to use the array method.

    @sprites["Background"] = Sprite.new # This defines the variable is a new sprite.
    @sprites["Background"].x = 20 # This sets the horizontal position, showing it as
    # the value of 20.
    @sprites["Background"].y = 100 # This sets the verticle position.
    @sprites["Background"].z = 900 # This sets which layer the image is on, higher the
    #number is, the higher the image is set above other images.
    @sprites["Background"].bitmap = BitmapCache.load_bitmap("Graphics/FolderName/ImageName")
    #This line is setting what the image will be, ("Graphics/FolderName/ImageName") is
    #important as it directs the code to where the image is.


    You can also manipulate the images in many ways. For example:

    @sprites["Background"].zoom_x = 2
    @sprites["Background"].zoom_y = 2

    The lines above change the zoom size of the graphic by a scale of 2.
    @sprites["Background"].angle = 0
    Use this if you would like to change the angle of the image. You can also do fun things in the update
    method of the script with this. For instance @sprites["Background"].angle+=1 with constantly
    rotate the image.
    @sprites["Background"].opacity = 255
    This changes the opacity of the chosen image 255 being visible and 0 being invisible.


    @Background = Sprite.new # Defines normal variable as a sprite
    @Background.x = 20 # Defines the horizontal position.
    @Background.y = 100 # Defines the verticle position.
    @Background.z = 999 # Defines layer
    @Background.bitmap = BitmapCache.load_bitmap("Graphics/FolderName/ImageName")
    # Defines image path.


    That is the basic information you need to know when it comes to displaying images.

    Section 2: Pokémon.


    In this section, we look at basic functions that relate to Pokémon. We shall be using functions from the previous section, to display the Pokémon, and also a new function of images will be included. Lets begin.


    if $Trainer.party.length>=1
    # This checks if you have 1 or more Pokémon.
    @sprites["Pkm1"] = AnimatedSprite.new(sprintf("Graphics/Icons/icon%03d",$Trainer.party[0].species),2,128/2,64,2)
    # This line is creating the image of the first Pokémon in the party.
    # $Trainer.party[0].species is the first party, party numbers go 0-5.
    @sprites["Pkm1"].x = 20
    @sprites["Pkm1"].y = 20
    @sprites["Pkm1"].z = 999
    end
    # This ends the check.
    $Trainer.party[0].hp
    This shows the current hp for the first Pokémon.
    $Trainer.party[0].totalhp
    This is the max hp value for the first Pokémon.
    $Trainer.party[0].moves[0].pp
    This is seeing the value of the first Pokémons' first move pp amount. Moves are shown in the values 0-3
    0 being move 1 and 3 being move 4.
    $Trainer.party[0].moves[0].totalpp
    Checks the max amount of pp for the first move of Pokémon 1.

    I will be adding more functions to this thread as I go along, for now, this is the basic info people may want. If you'd like anything else, please send a PM to me or post in this thread about what you would like, and I shall get back to you with the information on here.
    __________________

    Pokémon: Lost Souls.







    Developed by Carmaniac.


    Quote:
    Originally Posted by Luka S.J. View Post
    My balls seem to be fine.
    Reply With Quote

    Relevant Advertising!

      #2    
    Old December 10th, 2012 (2:59 PM).
    venom12's Avatar
    venom12 venom12 is offline
    Pokemon Crystal Rain Relased
       
      Join Date: Sep 2006
      Age: 26
      Gender: Male
      Nature: Adamant
      Posts: 529
      You should use $Trainer.party.length>0 instead of if $Trainer.party.length>=1, because it checks if you have first pokemon not the second
      Reply With Quote
        #3    
      Old December 10th, 2012 (3:39 PM).
      carmaniac's Avatar
      carmaniac carmaniac is offline
      Where the pickle surprise at?
         
        Join Date: Apr 2009
        Location: England
        Age: 22
        Nature: Relaxed
        Posts: 682
        Quote:
        Originally Posted by venom12 View Post
        You should use $Trainer.party.length>0 instead of if $Trainer.party.length>=1, because it checks if you have first pokemon not the second
        That's kind of the whole point for it to be checking Pokémon number 1 lol. It works perfectly fine when doing >=1 >=2 >=3 etc.
        __________________

        Pokémon: Lost Souls.







        Developed by Carmaniac.


        Quote:
        Originally Posted by Luka S.J. View Post
        My balls seem to be fine.
        Reply With Quote
          #4    
        Old December 11th, 2012 (12:37 AM).
        Luka S.J.'s Avatar
        Luka S.J. Luka S.J. is offline
        Jealous Croatian
           
          Join Date: Dec 2008
          Location: Croatia
          Age: 24
          Gender: Male
          Nature: Adamant
          Posts: 1,100
          Quote:
          Originally Posted by venom12 View Post
          You should use $Trainer.party.length>0 instead of if $Trainer.party.length>=1, because it checks if you have first pokemon not the second
          That is pretty much the same thing. The first method checks if the length is 1 or above. The second method checks if length is 1 or above.
          __________________

          Reply With Quote
            #5    
          Old December 11th, 2012 (9:32 AM).
          Dying Light's Avatar
          Dying Light Dying Light is offline
          Pegasus Knight
             
            Join Date: Jun 2011
            Location: Exiled
            Gender: Male
            Nature: Hardy
            Posts: 368
            This a good thread, carmaniac. Maybe this will help some of the newbies and lower the number of question threads.

            And I think venom12 meant that since if $Trainer.party.length>=1 checks for Pokémon number 1, in the code 1 basically means 2, and 0 means 1. That would make the code actually search for the second Pokémon in the party, not the first since the first is 0. Although, if they function the way you describe, then there should be no problem.
            __________________
            None

            “Our only limits are the ones we place on ourselves.”
            Reply With Quote
              #6    
            Old December 11th, 2012 (10:23 AM).
            carmaniac's Avatar
            carmaniac carmaniac is offline
            Where the pickle surprise at?
               
              Join Date: Apr 2009
              Location: England
              Age: 22
              Nature: Relaxed
              Posts: 682
              Quote:
              Originally Posted by Musketeer View Post
              This a good thread, carmaniac. Maybe this will help some of the newbies and lower the number of question threads.

              And I think venom12 meant that since if $Trainer.party.length>=1 checks for Pokémon number 1, in the code 1 basically means 2, and 0 means 1. That would make the code actually search for the second Pokémon in the party, not the first since the first is 0. Although, if they function the way you describe, then there should be no problem.
              When it comes to party.length, it literally is just that, checking the length of the party. if it's >=1 it's seeing if the party length is 1 or higher. The 0 being 1 logic however, applies to the number of the party, i.e $Trainer.party[0] being the first Pokémon. Found that out the hard way on the length checks when I was getting errors calling the Pokémon into a menu XD.
              __________________

              Pokémon: Lost Souls.







              Developed by Carmaniac.


              Quote:
              Originally Posted by Luka S.J. View Post
              My balls seem to be fine.
              Reply With Quote
                #7    
              Old December 11th, 2012 (10:42 AM).
              Dying Light's Avatar
              Dying Light Dying Light is offline
              Pegasus Knight
                 
                Join Date: Jun 2011
                Location: Exiled
                Gender: Male
                Nature: Hardy
                Posts: 368
                Quote:
                Originally Posted by carmaniac View Post
                When it comes to party.length, it literally is just that, checking the length of the party. if it's >=1 it's seeing if the party length is 1 or higher. The 0 being 1 logic however, applies to the number of the party, i.e $Trainer.party[0] being the first Pokémon. Found that out the hard way on the length checks when I was getting errors calling the Pokémon into a menu XD.
                OH! Now I see what you mean. I derp.

                Heheh, well at least that's the beauty of scripting. You get an error, and you fix it... rinse and repeat until you get it right.

                But anyway, I love the way this thread has been organized, and makes viewing common functions easy. This is an amazing reference sheet in a way. I'm definitely subscribing to this thread.

                Good work on this man.
                __________________
                None

                “Our only limits are the ones we place on ourselves.”
                Reply With Quote
                  #8    
                Old December 11th, 2012 (10:47 AM).
                Luka S.J.'s Avatar
                Luka S.J. Luka S.J. is offline
                Jealous Croatian
                   
                  Join Date: Dec 2008
                  Location: Croatia
                  Age: 24
                  Gender: Male
                  Nature: Adamant
                  Posts: 1,100
                  Quote:
                  Originally Posted by Musketeer View Post
                  And I think venom12 meant that since if $Trainer.party.length>=1 checks for Pokémon number 1, in the code 1 basically means 2, and 0 means 1. That would make the code actually search for the second Pokémon in the party, not the first since the first is 0. Although, if they function the way you describe, then there should be no problem.
                  The symbol > stands for greater than, while >= is for greater than or equal to. By that logic, if we do >0 or >=1 the minimum number will be the same, 1. And since when you have a Pokemon in your party, the lowest number your party can have is 1. There is a difference between indexes and length of arrays, one being that the first index in an array is always 0, and that the minimum positive (non nil) length of an array is 1.

                  Lol, ninja'd.
                  __________________

                  Reply With Quote
                    #9    
                  Old December 12th, 2012 (1:33 PM).
                  korjamer's Avatar
                  korjamer korjamer is offline
                  Pixel Artist
                     
                    Join Date: Apr 2011
                    Gender: Male
                    Nature: Relaxed
                    Posts: 19
                    This post is Wonderful! Keep it going I am learning so much and I have always wanted to dive into the scripting world! (I'm more of an artist) Thank you so much Carmaniac!
                    Reply With Quote
                      #10    
                    Old December 15th, 2012 (3:06 PM).
                    carmaniac's Avatar
                    carmaniac carmaniac is offline
                    Where the pickle surprise at?
                       
                      Join Date: Apr 2009
                      Location: England
                      Age: 22
                      Nature: Relaxed
                      Posts: 682
                      Added a couple more lines to manipulating Pokémon and the graphics. I'll be later on adding how to display text and also a code example to show what each does, including an example image of the output.
                      __________________

                      Pokémon: Lost Souls.







                      Developed by Carmaniac.


                      Quote:
                      Originally Posted by Luka S.J. View Post
                      My balls seem to be fine.
                      Reply With Quote
                        #11    
                      Old December 15th, 2012 (10:42 PM).
                      zingzags's Avatar
                      zingzags zingzags is offline
                      PokemonGDX creator
                         
                        Join Date: Jan 2009
                        Location: Boston
                        Age: 23
                        Nature: Adamant
                        Posts: 562
                        @Musketeer
                        @Venom12
                        When you are using " $Trainer.party[0]", you are referring to the array party, which lies in the Trainer class "I think", remember computers start from 0, not from one. So when you are programming it is important to know that you always start at 0. But lets say you are trying to initialize an array, in lets say java or c++, what you would do is array_name[number of elements]. So for example pokemon[10], you will have 10 elements which can be used to hold a value. But as I said before to get the first value in the array, you would use pokemon[0].

                        $Trainer.party.length is the size of the array, so as Luka said before is true.
                        __________________
                        Check out the Pokemon Game Engine I am working on:
                        https://github.com/sjosegarcia/Pokemon
                        Reply With Quote
                        Reply
                        Quick Reply

                        Sponsored Links
                        Thread Tools

                        Posting Rules
                        You may not post new threads
                        You may not post replies
                        You may not post attachments
                        You may not edit your posts

                        BB code is On
                        Smilies are On
                        [IMG] code is On
                        HTML code is Off

                        Forum Jump


                        All times are GMT -8. The time now is 6:48 AM.