PDA

View Full Version : [Guide] Scripting in Essentials 101


carmaniac
December 8th, 2012, 08:57 AM
[css-div="padding: 2px 2px 2px 2px; border: solid 1px #000; background-color: #FFF6EF;width: 100%;"]Scripting 101, things you may want to know.
[css-div=float: left;margin-right: 10px;margin-up: 10px;width: 150px; height: 300px;"][css-div="padding: 2px 2px 2px 2px;font-variant: small-caps; color: #000; border: solid 2px #000; background-color: #d0e4fe;"]Index:
Section 1: Images.
Section 2: Pokémon.
[/css-div][/css-div]
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:
[css-div="padding: 2px 2px 2px 2px; background-color: #FFF6AD;width: 685px;"]
@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.
[/css-div]

You can also manipulate the images in many ways. For example:
[css-div="padding: 2px 2px 2px 2px; background-color: #FFF6AD;width: 685px;"]
@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.
[/css-div]

[css-div="padding: 2px 2px 2px 2px; background-color: #FFF6AD;width: 685px;"]
@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.
[/css-div]

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.

[css-div="padding: 2px 2px 2px 2px; background-color: #FFF6AD;width: 800px;"]
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.
[/css-div]
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.

[/css-div]

venom12
December 10th, 2012, 02:59 PM
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 :)

carmaniac
December 10th, 2012, 03:39 PM
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.

Luka S.J.
December 11th, 2012, 12:37 AM
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.

Dying Light
December 11th, 2012, 09:32 AM
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.

carmaniac
December 11th, 2012, 10:23 AM
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.

Dying Light
December 11th, 2012, 10:42 AM
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. :)

Luka S.J.
December 11th, 2012, 10:47 AM
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.

korjamer
December 12th, 2012, 01:33 PM
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!

carmaniac
December 15th, 2012, 03:06 PM
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.

zingzags
December 15th, 2012, 10:42 PM
@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.