Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Scripts & Tutorials
Reload this Page [Essentials tutorial] Pokémon: Essentials coding 101.

Notices
For all updates, view the main page.

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 July 30th, 2011 (06:20 AM). Edited July 30th, 2011 by Rai Rai.
Rai Rai's Avatar
Rai Rai Rai Rai is offline
Master of everything!
 
Join Date: Aug 2010
Gender: Male
Posts: 267
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.

Spoiler:
Code:
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
Reply With Quote
  #2    
Old July 30th, 2011 (06:32 AM).
Gmack's Avatar
Gmack Gmack is offline
I'm back!
 
Join Date: Mar 2010
Location: Florida, USA
Gender: Male
Nature: Calm
Posts: 82
Send a message via Windows Live Messenger to Gmack
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
__________________
Official Blog :: http://gmacksblawg.wordpress.com/

Official Website :: http://gavinsblawg.webs.com/about
Reply With Quote
  #3    
Old July 30th, 2011 (05:06 PM).
ProdigyX's Avatar
ProdigyX ProdigyX is offline
 
Join Date: Jun 2010
Location: Australia
Age: 21
Gender: Male
Nature: Brave
Posts: 244
HAhaha very nice i see you worked over it while i was sleeping :D
Reply With Quote
  #4    
Old August 6th, 2011 (01:28 AM).
Luka S.J.'s Avatar
Luka S.J. Luka S.J. is offline
@LukaSJ0
 
Join Date: Dec 2008
Location: Croatia
Age: 22
Gender: Male
Nature: Adamant
Posts: 892
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.
__________________
Reply With Quote
  #5    
Old August 6th, 2011 (06:59 AM).
Rai Rai's Avatar
Rai Rai Rai Rai is offline
Master of everything!
 
Join Date: Aug 2010
Gender: Male
Posts: 267
Quote originally posted by Luka S.J.:
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 .
Reply With Quote
Reply
Quick Reply

Sponsored Links

You may also like.. (Beta)
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 UTC -8. The time now is 10:27 PM.