LOG_IN

LOG_OUT
[connected]

RGSS = Scripting Basics - Window Class 5 5 11

View previous topic View next topic Go down Message [Page 1 of 1]

#1 RGSS = Scripting Basics - Window Class

G@MeF@Ce

Administrator
CD3DF5

Administrator CD3DF5
||||||||||||||||
Here you will learn to create a basic window with
a simple text message to be displayed.

Each line of code will be commented to explain it's purpose.

Start by copy and paste this script into the RMXP script data base (F11)

Code:
class My_First_Window < Window_Base #1
  def initialize #2
    super(0, 0, 350, 150) #3
    self.contents = Bitmap.new (width - 32, height - 32) #4
    #this shows what is in the window with a 32pixel margin#5
    refresh # run the variable named "refresh"#6
  end # end the initialization process#7
  def refresh #8 define what refresh does
    self.contents.clear #9 clear content of the variable Bitmap
    self.contents.draw_text(0, 0, 300, 32,"This is my first window")#10
  end #11 end the refresh process
end #12end the window class


Now let's take a look at each line of code...

#1 = class sub-window under the Window Base class.

Code:
class My_First_Window < Window_Base


#2 = define start process
Code:
def initialize


#3 = instruct window size and location
Code:
super(0, 0, 350, 150)


"super" calls the Class to start
(arguments) = from left to right

0= x window position
0 = y window position
350= x window width
150 = y window height

#4 = like the body to a web page, this creates the viewable content inside the window with a 32 pixel margin or inner frame
Code:
self.contents = Bitmap.new (width - 32, height - 32)


#5 = is just a comment line beginning with a #
Code:
#this shows what is in the window with a 32pixel margin#5

*in case you missed the first lesson...
RGSS+RMXP Comments

#6 = this calls the method named refresh which is defined later in the script
Code:
refresh # run the variable named "refresh"#6


#7 = end method
just like HTML tags in where you have to start and end a link, or div,
RGSS is pretty much the same in regards to starting a class, def (method) to 'if statements.

Code:
  end #to close/end the defined method 'initialize'#7


*note, when running a script, the system looks for the 'initialize' method first if not then 'main'
or it will crash*

#8 = just like defining the initialize method, this will define a method call 'refresh'
*remember we are calling this method 0n line #6 which is called inside the initialize method ~ still with me?
Code:
  def refresh #8 define what refresh does


#9 = this basically clears the window's contents so that there is a clean slate every time you call your window
Code:
 self.contents.clear #9 clear content of the variable Bitmap


#10 = now this writes the test message on the clean slate
Code:
 self.contents.draw_text(0, 0, 300, 32,"This is my first window")#10


self.(this window)contents.(what's inside)draw_text(0,0,300,32,"YOUR TEXT")

(arguments) = from left to right
0= text horizontal position
0= text vertical position
300 = width of text field
32 = height of text field
"YOUR TEXT" = keep in between " "

11 = close the defined method named refresh
Code:
 end #11 end/close the refresh process


12 = close the defined class named
My First Window - which is being used under the Window_Base class.
Code:
end #12end the window class



Now to display this window you may use an event with the following call script in the list of event commands
(RMXP - third tab, bottom right option)

Code:
My_First_Window.new


your window will look just like this!

Spoiler:


simple but not easy...
the level of difficulty will increase as we continue our adventures in RGSS for RMXP

*remember I'm only sharing what I'm learning = 101
G@MeF@Ce's signature
http://g4m3f4c3.deviantart.com http://twitter.com/#!/mr_gameface101 http://www.facebook.com/mrgameface101 http://soundcloud.com/mr_gameface101 http://www.youtube.com/user/MrGameface101?feature=watch

Legault123

Active Member
Active Member
||||||||||||||||
thank you so much for de classes! They are just like you said, simple but not easy. It takes time, I think I'm doing just fine, I need to make a list of these 'things' -don't know the name :$ - like:

super : call the class to start

Like a dictionary with all that stuff. I'll keep studying and post what I dont understand here (:
Legault123's signature

supercow

Active Member
Active Member
||||||||||||||||
@gameface could it be the enemy mini hud script got bug (where sometimes doesnt show its hud) because of the refresh problem? or not enough of it?
if used too many refresh would it make a script more lag? silent
whats the diff bettwen refresh and update? Neutral
sorry for the random question Embarassed
supercow's signature

G@MeF@Ce

Administrator
CD3DF5

Administrator CD3DF5
||||||||||||||||
supercow wrote:@gameface could it be the enemy mini hud script got bug (where sometimes doesnt show its hud) because of the refresh problem? or not enough of it?
if used too many refresh would it make a script more lag? silent


@supercow - I'll address the issue with the e-mini HUD on that topic (there's a bug with the 'for loop' method I believe, hope to have it worked out soon)
and yes, to refresh/update more than needed can definitely cause lag.

supercow wrote:
whats the diff bettwen refresh and update? Neutral
sorry for the random question Embarassed

this is on topic with making windows Cool
To answer your question about refresh and update, these are methods used to do exactly that, "update" if coordinates change such as position, new HP, etc...
and "refresh" to clear and rewrite/redraw graphics/text.


Legault123 wrote:
I need to make a list of these 'things' -don't know the name :$ - like:

super : call the class to start


@Legault123-there's different types of variables
some with @ or $ or constants which are in ALL_CAPS.

these set values and label methods that can be called from various places in the script itself or throughout the script database.

A Class is like a block of code that you can access to use what is needed. Super will call the Window_Base Class that's being used. So instead of writing everything needed to make a window, you call the class that makes windows and make the needed window through setting the arguments.

Maybe I will make a 101 on variables and arguments as it helped me a lot when I started out learning RGSS.

*Warning - the more you learn about scripting, the more you will need to learn about scripting.

if anything, RMXP > Help > F1 Contents |
look up classes / methods / variables.

Hope this helps guys...


G@MeF@Ce's signature


Hey Guest, check out my demos!
Super Mockup Project
Cool Puzzle Cave
Into the Nexas
Web_Plat
Getroid
G.A.S.




G101's theme colors






http://g4m3f4c3.deviantart.com http://twitter.com/#!/mr_gameface101 http://www.facebook.com/mrgameface101 http://soundcloud.com/mr_gameface101 http://www.youtube.com/user/MrGameface101?feature=watch

Legault123

Active Member
Active Member
||||||||||||||||
ok ok I'm getting it, but as you said, the more I learn the more questions I have.I've been searching on the net and found some very good starter tutorials for scripting but they are on spanish, maybe I can translate them and write them here for every newbie like me, what do you think ?

Waiting for a new class Very Happy
Legault123's signature

G@MeF@Ce

Administrator
CD3DF5

Administrator CD3DF5
||||||||||||||||
@Legault - you did say that you would help me with Spanish ^,^

that would be great! we need more tutorials in the creative support center ~ it's so brand new.

I'm excited to see where scripting will take you,
I recall mr_wiggles starting off with event systems, now take a look at him with all his awesome scripts.
G@MeF@Ce's signature


Hey Guest, check out my demos!
Super Mockup Project
Cool Puzzle Cave
Into the Nexas
Web_Plat
Getroid
G.A.S.




G101's theme colors






http://g4m3f4c3.deviantart.com http://twitter.com/#!/mr_gameface101 http://www.facebook.com/mrgameface101 http://soundcloud.com/mr_gameface101 http://www.youtube.com/user/MrGameface101?feature=watch

Legault123

Active Member
Active Member
||||||||||||||||
yeah I'll help with spanish, it's great with girls.. I've been told 8-) hahaha just ask and I answer ;D

I start working on translating the tutorials if the guy who made them allows me and post them here on a new topic.

mr wiggles must be an example to everyone haha, you know he still has the name "Eventalist" while the only thing that I see from him are awesome scripts! I got a lot to learn.. let's see what happens (:
Legault123's signature

mr_wiggles

EVENTALIST
006633

 EVENTALIST 006633
||||||||||||||||
Yea takes time to learn, but there are a lot of useful sites out there and helpful people. Events helped me understand for the most part.

(All events are scripts, the commands get converted trough the Interpreter class)

Working with events help you project the outcome to what you created, which is very useful because writing scripts from scratch is hard trying to get it to make it do what you want it to.

(What helps me is creating the features first then making them work.)
mr_wiggles's signature


Outbreak: First Blood - Progress: Demo:

<- Thanks Blue

Spoiler:

METAL FRESH is a paint contractor that specializes in refinishing metal and vinyl siding. We paint metal buildings as well as siding on homes.


Metal building painters around northern Illinois and southern Wisconsin .
http://metalfreshcoatings.com

Legault123

Active Member
Active Member
||||||||||||||||
When I have enough time, I'll start translating from spanish to english, some scripting classes I've seen. Maybe in the process I learn something.

In the meantime, can you name the webs you used to visit to learn? Thank you!
Legault123's signature
#10 Re: RGSS = Scripting Basics - Window Class

mr_wiggles

EVENTALIST
006633

 EVENTALIST 006633
||||||||||||||||
mr_wiggles's signature


Outbreak: First Blood - Progress: Demo:

<- Thanks Blue

Spoiler:

METAL FRESH is a paint contractor that specializes in refinishing metal and vinyl siding. We paint metal buildings as well as siding on homes.


Metal building painters around northern Illinois and southern Wisconsin .
http://metalfreshcoatings.com

handy333

Active Member
Active Member
||||||||||||||||
This is the only tutorial where it explains everything about everything.

But I still don't fully understand the super()
command.

Do I have to use Initialize for my Def name because I would like to use ini.
Its short and easy to type. Or are Initialize and Main keywords/important?

Oh and I would really like to understand how width - 32, height - 32 means. Mainly what the - does.
handy333's signature
http://www.facebook.com/handy.fox http://soundcloud.com/handyfox http://www.youtube.com/channel/UCkBX7ZxqoXslAtqsdrmsn_w http://projectrisingsun.weebly.com/
#12 Re: RGSS = Scripting Basics - Window Class

G@MeF@Ce

Administrator
CD3DF5

Administrator CD3DF5
||||||||||||||||
handy333 wrote:This is the only tutorial where it explains everything about everything.

it really just covers the basics in making a window with text.

handy333 wrote:But I still don't fully understand the super()
command.

"super" is the keyword that tells the interpreter to search the parent class and find the initialize method.

handy333 wrote:Do I have to use Initialize for my Def name because I would like to use ini.
Its short and easy to type. Or are Initialize and Main keywords/important?

Yep, "initialize" is the method you must use to 'automatically call' a new object of a class.

handy333 wrote:Oh and I would really like to understand how width - 32, height - 32 means. Mainly what the - does.

welp there's a 16 pixel border inside ruby windows that can't be drawn on, so a minus 32 pixels is commonly used to draw to the edge.
G@MeF@Ce's signature


Hey Guest, check out my demos!
Super Mockup Project
Cool Puzzle Cave
Into the Nexas
Web_Plat
Getroid
G.A.S.




G101's theme colors






http://g4m3f4c3.deviantart.com http://twitter.com/#!/mr_gameface101 http://www.facebook.com/mrgameface101 http://soundcloud.com/mr_gameface101 http://www.youtube.com/user/MrGameface101?feature=watch

handy333

Active Member
Active Member
||||||||||||||||
You don't know how much this has helped me.
It was a giant leap in Learning.
handy333's signature
http://www.facebook.com/handy.fox http://soundcloud.com/handyfox http://www.youtube.com/channel/UCkBX7ZxqoXslAtqsdrmsn_w http://projectrisingsun.weebly.com/

handy333

Active Member
Active Member
||||||||||||||||
Ooh, is there a way to change the opacity of the window.

And and what is attr_accessor and the others like reader and write.
handy333's signature
http://www.facebook.com/handy.fox http://soundcloud.com/handyfox http://www.youtube.com/channel/UCkBX7ZxqoXslAtqsdrmsn_w http://projectrisingsun.weebly.com/

NuKa_BuBble

The only one
D3FF42

||||||||||||||||
To change the opacity of a window, use:
self.opacity = (set a value between 0 and 255)

attr_accessor allow to read and change the value of a variable in another class.
attr_reader, read the variable only
attr_writer, change the value only
NuKa_BuBble's signature


___________________________________________________________________________

Booyah!

...._
._|_|_
. ( ')>
http://nukabubble.deviantart.com/ http://soundcloud.com/nuka_bubble http://www.youtube.com/user/NuKaBuBble?feature=mhee

handy333

Active Member
Active Member
||||||||||||||||
Thanks, sorry to be the bother again but I'm really starting to understand this as I go but...I have another question(maybe a few more in the future -_-).
In Input.press?(Input::(X)) what is the question mark(?) for and do I need it here.

I'm trying to make the opacity rise, lower, and reset via button push. I have them in the update def.

Oh and if I wanted to add a window skin to the the script its self how would I do that.

Thanks again.
handy333's signature
http://www.facebook.com/handy.fox http://soundcloud.com/handyfox http://www.youtube.com/channel/UCkBX7ZxqoXslAtqsdrmsn_w http://projectrisingsun.weebly.com/

NuKa_BuBble

The only one
D3FF42

||||||||||||||||
It's as a question, you ask: Did the player pressed a button? It is the button (Input::X)? It's a parameter to the method.
And, it's not Input.press?(), it's Input.trigger?().

To change the window skin, press help in the script editor. Search in the index for th class Window.

Don't need an update method for a window class, you can change the name and while the window is called in a class, you refresh this defined method. If you check in the sample, in Scene_Map, I only call the refresh method. I use more the update to update... you know? Very Happy Like if you have a huge script that must refresh 10 differents methods. The update will gather all the method and refresh them.

(I took it from my karma script)
Like for a HUD:
Code:
#==============================================================================
# ** Karma_Hud
#------------------------------------------------------------------------------
#  This class handles the karma HUD.
#==============================================================================
class Karma_Hud < Window_Base
  include NuKaBuBbles_Karma
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
    super(HUDX, HUDY, 640, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    refresh
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    self.contents.clear
    self.contents.font.size = 24
    length = 1
    length = 0 if $game_party.karma.abs.to_s.size == 1
    length = ($game_party.karma.abs.to_s.size * 15) - (48 / 2) if $game_party.karma.to_s.size > 2
    if $game_party.karma >= Good
      draw_picture(-4, 2, 0, 0, 1, 1, Good_Pic)
      draw_numbers(16+48+length, 0, $game_party.karma, Number_Pic, 3, 0)
    elsif $game_party.karma <= Evil
      draw_picture(-4, 2, 0, 0, 1, 1, Evil_Pic)
      draw_numbers(16+48+length, 0, $game_party.karma, Number_Pic, 3, 2)
    else
      draw_picture(-4, 2, 0, 0, 1, 1, Neutral_Pic)
      draw_numbers(16+48+length, 0, $game_party.karma, Number_Pic, 3, 1)
    end
    if $game_switches[KPSWITCH] == true
      self.visible = true
    else
      self.visible = false
    end
  end
end

#==============================================================================
# ** Scene_Map
#------------------------------------------------------------------------------
#  This class performs map screen processing.
#==============================================================================
class Scene_Map
  include NuKaBuBbles_Karma
  #--------------------------------------------------------------------------
  # * Main
  #--------------------------------------------------------------------------
  alias karma_hud_main main
  def main
    @karma_hud = Karma_Hud.new
    karma_hud_main
    @karma_hud.dispose
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  alias karma_hud_update update
  def update
    karma_hud_update
    @karma_hud.refresh
  end
end
NuKa_BuBble's signature


___________________________________________________________________________

Booyah!

...._
._|_|_
. ( ')>
http://nukabubble.deviantart.com/ http://soundcloud.com/nuka_bubble http://www.youtube.com/user/NuKaBuBble?feature=mhee

handy333

Active Member
Active Member
||||||||||||||||
This may be a little off subject but...
Is it possible/easy to make a music
equalizer with rgss?

I want to use certain variables from the bass equalizer in a song to effect the window transparency and color.
handy333's signature


http://www.facebook.com/handy.fox http://soundcloud.com/handyfox http://www.youtube.com/channel/UCkBX7ZxqoXslAtqsdrmsn_w http://projectrisingsun.weebly.com/

NuKa_BuBble

The only one
D3FF42

||||||||||||||||
Ahhhhh, I never used the music variables in RGSS but, everything is possible. You must know that the limit, it's your knowledge.
NuKa_BuBble's signature


___________________________________________________________________________

Booyah!

...._
._|_|_
. ( ')>
http://nukabubble.deviantart.com/ http://soundcloud.com/nuka_bubble http://www.youtube.com/user/NuKaBuBble?feature=mhee
#20 Re: RGSS = Scripting Basics - Window Class

handy333

Active Member
Active Member
||||||||||||||||
Sounds serious.

Here's a good/noob question.

How do you assign the player's screen_x to a variable.
handy333's signature
http://www.facebook.com/handy.fox http://soundcloud.com/handyfox http://www.youtube.com/channel/UCkBX7ZxqoXslAtqsdrmsn_w http://projectrisingsun.weebly.com/

NuKa_BuBble

The only one
D3FF42

||||||||||||||||
So you must know that. You can call every class by using $followed_by_the_class_name and assign them to a variable like this:
@variable = $game_actor.screen_x

I havn't updated it but, you can have some video RMVX video tutorials by GubiD. It's the same base so it's might be useful to watch them.
NuKa_BuBble's signature


___________________________________________________________________________

Booyah!

...._
._|_|_
. ( ')>
http://nukabubble.deviantart.com/ http://soundcloud.com/nuka_bubble http://www.youtube.com/user/NuKaBuBble?feature=mhee

handy333

Active Member
Active Member
||||||||||||||||
Sounds Great.
handy333's signature


http://www.facebook.com/handy.fox http://soundcloud.com/handyfox http://www.youtube.com/channel/UCkBX7ZxqoXslAtqsdrmsn_w http://projectrisingsun.weebly.com/

View previous topic View next topic Back to top Message [Page 1 of 1]

 

Chatbox system disabled
Personal messaging disabled