PDA

View Full Version : [Essentials tutorial] Pokémon: Essentials coding 101.


Rai Rai
July 30th, 2011, 06:20 AM
Well, today I announce myself here to give all of you game developers the basics of coding within Essentials. The main aim is to teach those how to make a simple window script with the day to day functions many other developers out there use to make their menus have that extra touch.
Enjoy.
Ps. If you want the code to keep reference without having to keep coming back here, I've put it in at the bottom of the thread.
Made a mistake on the code, on the last end of the code delete it, that will fix the error I made.
http://i1004.photobucket.com/albums/af167/carmaniac94/Tutorial.png
class Window_Lesson < SpriteWindow_Base #name of the class which also takes on
#another class name traits
def initialize # need in all window scripts
super(x,y,width,height) # replace inside with what size and place you want it
@Sprites=[] # calls the sprite class, helpful on disposing all the sprites
@Sprites["BG"] = Sprite.new # makes a new graphic
@Sprites["BG"].x = 0 #where it is pace on X axis this case 0
@Sprites["BG"].y = 0 #where it is place on y axis, this case 0
@Sprites["BG"].z = 9999 # The layer picture is on
@Sprites["BG"].bitmap=RPG::Cache.picture("whateveryouwant") #calls the sprite
#==================# Following sectino is needed to show text
@sprites["overlay"]=Sprite.new(@viewport)
@sprites["overlay"].bitmap=Bitmap.new(Graphics.width,Graphics.height)
@sprites["overlay"].z=9999999
pbSetSystemFont(@sprites["overlay"].bitmap)
@overlay = @sprites["overlay"].bitmap
@overlay.clear
@baseColor=Color.new(12*6,12*6,12*6)
@shadowColor=Color.new(12*14,12*14,12*14)
#==================# Section ended
@Sprites["BG"].opacity=0 # makes transparent
loop do #loops the following command
Graphics.update
Input.update
update #calls update in a loop
if $scene != self
break
end
end
end
end # ends the def
def update # defines update
#===================# Follwing needed to display text
# The first 20 shows where the text will be displayed on the X-Axis
# The second 20 shows where the text will be displayed on the Y-Axis
# If you want to add in more text later on in the code then use the following:
# But without the # infront of the line.
# textPositions.push([_INTL("Load Save1."),230,450,false,@baseColor,@shadowColor])
textPositions=[
[_INTL("Put what ever you want here."),20,20,false,@baseColor,@shadowColor],
]
#===================#
@frame=+1 # makes a frame count
if Input.trigger?(Input::C) # checks if C is pressed
p 'this works' #Pulls a window saying what's inside the ''
end # ends def
if @frame==50 # checks if frame is at a certain amount
@frame=0 #changes frame count back to 0
end
51.times do #loops the method inside the amount of times.
@Sprites["BG"].opacity+=5 #adds 5 onto the opacity everytime
end #ends loop
if Input.trigger?(Input::B)
break # Breaks window
end
end
end # Ends class
#to call window use in a script command Window_Lesson.new

Gmack
July 30th, 2011, 06:32 AM
sigh.... Finally someone makes this! Something i can relate to, not tutorials.
And best of all, it's for essentials! What a novel idea! XD

ProdigyX
July 30th, 2011, 05:06 PM
HAhaha very nice i see you worked over it while i was sleeping :D

Luka S.J.
August 6th, 2011, 01:28 AM
I'd have to be a downer, but there are quite a few thigs up there which would either give you a syntax error or an unwanted result. Good try though, the code is really clean. Now onto the fixes:

1. Quite an easy mistake to do with @frame. You started performing math functions without defining the variable. You first need to put @frame=0 somewhere before the update starts.

2. No text will be drawn as you forgot to place pbDrawText after textpositions have been defined, not to mention the lack of @overlay.clear to refresh the text.

3. The 51.times do command will not make the opacity go up smoothly, instead it will be filled in one frame, as there should be a pbWait(1) command before the end, that will make the whole function ladt 51 frames. Plus since it's in a loop, that function will repeat infinately, freezing your game, which is not what you want.

4. I have no idea what you put @frame in there for as it just resets when it reaches a number, don't know if that was intentional.

That's all I can see wrong/inaccurate for now.

Rai Rai
August 6th, 2011, 06:59 AM
I'd have to be a downer, but there are quite a few thigs up there which would either give you a syntax error or an unwanted result. Good try though, the code is really clean. Now onto the fixes:

1. Quite an easy mistake to do with @frame. You started performing math functions without defining the variable. You first need to put @frame=0 somewhere before the update starts.

2. No text will be drawn as you forgot to place pbDrawText after textpositions have been defined, not to mention the lack of @overlay.clear to refresh the text.

3. The 51.times do command will not make the opacity go up smoothly, instead it will be filled in one frame, as there should be a pbWait(1) command before the end, that will make the whole function ladt 51 frames. Plus since it's in a loop, that function will repeat infinately, freezing your game, which is not what you want.

4. I have no idea what you put @frame in there for as it just resets when it reaches a number, don't know if that was intentional.

That's all I can see wrong/inaccurate for now.

Heh yeah, was pretty late at the time of doing it XD. I'll change up all the errors once I get back tonight. Was a 5 minute whip up type thing cause I was asked questions :P.