Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Special Support - A great place to learn to Script

Everyone wants to learn to script, but no one really knows where to start. In my honest opinion, the best place to learn is just by reading the default scripts. I learned to script with the japanese RMXP, so I didn't have English comments at my disposal, so everyone of the new generation has that upperhand. Anyways, what I think the best thing to do to learn to script is read the default scripts, and understand each line.

So what I am offering here is support for anyone trying to learn to script. If there is a line of code you don't understand, ask me here. If there is something you want to know, like where in the script editor does something happen, ask here.
  • Ask about a certain line of code : What it means, does, etc.
  • Ask where the coding is for a certain function
PLEASE DO NOT ASK SOMETHING OTHER THAN EXISTING CODE, OR WHERE IN THE DEFAULT SCRIPTS TO FIND A CERTAIN BLOCK OF CODE. Your post will be deleted.

This is a Trial and Error topic. Hopefully, it can lead to more a use full FAQ for beginners.
 
yes, I researched a little yesterday and found out about the same.
So, a Sprite is basically not an animation?

So, if I want to put animated Sprite in my sprite_battler, how to do that?
I used show_animation() for this one, though in def update.
 
@DivineLight:
A Sprite is not an animation. I'll give you a general explanation into the animation, PLUS an Animation class so everyone can use:
Code:
class Animation < Sprite
  attr_accessor :current_frame
  attr_accessor :max_frames
  attr_accessor :current_animation
  attr_accessor :frame_width
  attr_accessor :frame_height
  attr_accessor :frame_distance 
  attr_accessor :animation_distance
  attr_accessor :animated
  attr_accessor :replay
  attr_accessor :reversed
  attr_accessor :is_vertical
  def initialize( view = Viewport.new(0,0, 640,480) )
    super(view)
    @current_frame = 0
    @max_frames = 0
    @current_animation = 0
    @frame_width = 32
    @frame_height = 32   
    @frame_distance = 0
    @animation_distance = 0
    @animated = true
    @replay = 1
    @reversed = false
    @is_vertical = false
  end
  def update
    super
    if not @animated
      return
    end
    if @replay == 0
      @current_frame = [[@current_frame+(@reversed ? -1 : 1), @max_frames].min, 0].max
    elsif @replay == 1
      @current_frame = (@current_frame+(@reversed ? -1 : 1)) % @max_frames
    elsif @replay == 2
      @current_frame = [[@current_frame+(@reversed ? -1 : 1), @max_frames].min, 0].max
      if [0, @max_frames].include?(@current_frame)
        @reversed = (not @reversed)
      end
    end
    if not @is_vertical
      self.src_rect.x = (@frame_width + @frame_distance) * @current_frame
      self.src_rect.y = (@frame_height + @animation_distance) * @current_animation
    else
      self.src_rect.x = (@frame_width + @animation_distance) * @current_animation
      self.src_rect.y = (@frame_height + @frame_distance) * @current_frame
    end
    self.src_rect.width = @frame_width
    self.src_rect.height = @frame_height
  end
end
I've just wrote this code, so blame with me if it doesn't work. Although I'm preety sure it does.
Use it as an ordinary Sprite. But it has some cool properties to play with. You'll probably use frame_width, frame_height, max_frames and current_animation a lot. They are preety self-explained. The bitmap can have more than a single animation. You can select wich is playing with current_animation. If is_vertical is false (default), then each row is a different animation, and the columns are frames. If it is true, then it is reversed (duh). The replay property says how it'll be played. When replay is zero, it is played once and stops. When it is one, it keeps playing forever. And when it is two, the animation is reversed when it is finished.

@MukanshinBlack:
That's because it is [email='@event.id]'@event.id[/email]' instead of '@event_id'.

SEE YA!!!!!
 

khmp

Sponsor

Code:
$game_map.events.each do |id, game_event|
  next if game_event.nil?
  if game_event.event.name == Test_String
    print 'chode'
  end
end

But in order to use that code within a "Script..." event command it requires you insert an empty section in the Script Listings under Materials and paste this code:
Code:
#==============================================================================
# ** Game_Event
#------------------------------------------------------------------------------
#  This class deals with events. It handles functions including event page 
# switching via condition determinants, and running parallel process events.
# It's used within the Game_Map class.
#==============================================================================

class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :event                    # event
end

Good luck with it slabix! :thumb:
 
Ok this is my firstime post here because i have some questions before i can start i think  :smile:

I have made lot of scripts with php but never before with RGSS2.
Now is my question is there a list with explanation of the code.

I wanna also know how i can add a new category in the menu system.
Have some great new options in my mind to created.

I hope that you can help me.
Have a nice day
dannyvriens :smile:
 

dastmo

Member

I have a question too. I understood that RGSS2 is Ruby based scripting language. That means that if I learn Ruby, I will understand RGSS2 much easyer, right???

PS: It's a stupid question, I know, but the only programing languages I have used before are HTML and VisualBasic.
 

khmp

Sponsor

dastmo":2rfr0bej said:
I have a question too. I understood that RGSS2 is Ruby based scripting language. That means that if I learn Ruby, I will understand RGSS2 much easyer, right???

PS: It's a stupid question, I know, but the only programing languages I have used before are HTML and VisualBasic.

Precisely correct. An understanding of Ruby will give you a huge jump start into the world of RGSS2. And if you understand Visual Basic it'll help a great deal in learning Ruby. Good luck with the scripting dastmo.
 
Sephiroth say...i have my hands on the Blizzard ABS....i saw this one forum where it told me to insert a new script page above the Main script and put the Blizzard Script there....i did so and named it Blizzard ABS so i could know exactly where it was so i started my game and got a ?????'BlizzardABS'? 237???System Stack Error???????? Stack Level Too Deep =( could you tell me what i did wrong? or maybe give me some instructions as to where to put the custom scripts you download? it would be greatly appreciated
 
How do you do by script a simple command that can be done by the events command, "Show message" because the "print" command sends a windows window and not a game menu window!
 

khmp

Sponsor

Kirkinho":1camx606 said:
Sephiroth say...i have my hands on the Blizzard ABS....i saw this one forum where it told me to insert a new script page above the Main script and put the Blizzard Script there....i did so and named it Blizzard ABS so i could know exactly where it was so i started my game and got a ?????'BlizzardABS'? 237???System Stack Error???????? Stack Level Too Deep =( could you tell me what i did wrong? or maybe give me some instructions as to where to put the custom scripts you download? it would be greatly appreciated

I suggest creating a Support Topic for this Kirkinho.

Ultima1":1camx606 said:
How do you do by script a simple command that can be done by the events command, "Show message" because the "print" command sends a windows window and not a game menu window!

What's wrong with a Windows messagebox for debugging? You would still need to use the "Script..." event command to call it. So you won't be saving yourself a hell of a lot of work. Still I guess you could create a Script Request for a Debug_MessageWindow to display anything you ask of it. I don't think you'll be avoiding Ruby doing it though. Just be sure to be detailed.

megamariohead":1camx606 said:
how can i make a loading bar

Just thinking about right now this is something I would do. But I know there are probably a million different approaches. So if anyone else has any ideas for megamariohead shout'em out. What you could also do is store internally the percentage of the information loaded within the Loading_Class object.

Code:
# The class that will load the assets and do the work we need it to.
loading_class = Loading_Class.new
# total_runs - The amount of runs that loading has currently undergone.
# loading - Boolean that means we are still loading material.
total_runs, loading = 0, true

# Our sprite to draw the loading bar.
sprite = Sprite.new
sprite.bitmap = Bitmap.new(200, 32)

# While the loading boolean is active.
while loading
  # Update the Graphics.
  Graphics.update
  # The percentage of the information we have loaded so far.
  loaded = width * (total_runs / loading_class.expected_runs.to_f)
  # Draw the bitmap as far as we need to draw it.
  sprite.bitmap.fill_rect(0, 0, sprite.bitmap.width * loaded, 32, Color.new(255, 0, 0))
  # Whether or not we still have things to load it determined by the return of the loading assets method.
  loading = loading_class.loading_assets
  # Increment the total run count so we can draw the bar further.
  total_runs += 1
end
 

Twirly

Sponsor

Ok here's my question...
In Vlads ABS i've seen the line bitmap.draw_text("miss") (you can see that text if an enemys attack or yours misses) How can i print that text too?
 
@ragnaroa: You would have to read a certain maps rxdata, get the event, and add it to you new map. A method like this works (in theory).

Code:
class Game_Map
  def add_evt_from_map(map_id, event_id, new_id, x, y)
    if @events.has_key?(new_id)
      p 'Error: Event ID already in use."
      return
    end
    map = load_data(sprintf("Data/Map%03d.rxdata", map_id))
    @events[new_id] = Game_Event.new(@map_id, map.events[event_id])
    @events[new_id].move_to(x, y)
    if $scene.is_a?(Scene_Map)
      $scene = Scene_Map.new
    end
  end
end

None of the local switches will be transfered however and such.

@asdren: What?
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top