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.
 
But in refresh I don't find call this method. I created own design of Status window. And I tried delete method dummy. No troubles I not see. All correctly work without def dummy. Not understand for what was write this method

About scripting. How can I draw picture from folder Graphics/Picture? Bitmap.new(filepath) not work correctly, because it require FULL filepath.

khmp: You can edit your previous post saintninja. Don't double/triple post. You can also delete this message when you see it.
 

khmp

Sponsor

saintninja":1tdaiv2u said:
About scripting. How can I draw picture from folder Graphics/Picture? Bitmap.new(filepath) not work correctly, because it require FULL filepath.

How can I draw picture from folder Graphics/Picture? Bitmap.new(filepath) not work correctly, because it require FULL filepath

Code:
Bitmap.new('./Graphics/Pictures/bitmap_filename')
or
Code:
RPG::Cache.picture('bitmap_filename')
 
Bitmap.new('./Graphics/Pictures/bitmap_filename') not work! Game close and print message: ./Graphics/Pictures/bitmap_filename not found.
RPG::Cache.picture('bitmap_filename') work fine thanks!

2khmp  thanks for modify my double post. This was my stupid fault... I will more warning next time;)

I have one more question. I writen script. How can I call this from Event???
 
Depends. I suppose it's a class like Game_* scripts, so you should call a script like this one:
Code:
$script = MyWholeNewScript.new

But that depends of what your script is. Remember that ALL Scene_* scripts are set into the $scene variable, so it should be like:
Code:
$scene = Scene_MyScript.new

SEE YA!!!!!
 
Does VX use the same code as XP? I'm going to learn how to code and don't want to waste my time on the wrong one.

Also, what is wrong with this?
If $game_party.actors=@4
@direction = 4
force_move_forward
end
It was supposed to force the player forward if there are 4 actors in the party.
 

khmp

Sponsor

Kelton":2mkzpq93 said:
Does VX use the same code as XP? I'm going to learn how to code and don't want to waste my time on the wrong one.

Also, what is wrong with this?
If $game_party.actors=@4
@direction = 4
force_move_forward
end
It was supposed to force the player forward if there are 4 actors in the party.

RMXP and RMVX use the same exact version of Ruby 1.8.1. So yes the scripting language is the same. However if you meant that scripts are compatible in between them? No.

Code:
if $game_party.actors == 4
  $game_player.move_up
end
 

Mechz

Member

Is there a command for forcing the game into fullscreen? Like, a graphics.command

Or maybe a variable I can set to "true" via the scene processing

Also, is "wait()" the same as "graphics.wait()"? In the process_battle_start method in scene_battle, the program does a wait(10) after clearing @message_window--- Is that 10 important? Could I change the frame number to, say, 1, or 20 without a noticeable effect?
 
I tried putting that script on an action button event and it doesn't work. Help?
That should be...
Code:
if $game_party.actors == 4
  @direction = 4
  force_move_forward
end

Is there a command for forcing the game into fullscreen? Like, a graphics.command
Nope. You need to simulate the ALT+ENTER keypress so it'll change to fullscreen.
Check out some fullscreen scripts out there. They're exactly what you need.

Also, is "wait()" the same as "graphics.wait()"? In the process_battle_start method in scene_battle, the program does a wait(10) after clearing @message_window--- Is that 10 important? Could I change the frame number to, say, 1, or 20 without a noticeable effect
As much as I know, it's useless. =/
If I remember correctly, graphics.wait() will simply not redraw the screen for a time, and wait() will halt all the process for a time. Beware, if you halt the process for a long time your game may time out. That happens when Input and Graphics are out of sync, or when Input and Graphics has been not updated for a short period.

I mean, a procedure is a def right? so what can an alias do?
It renames a procedure. Let's say you have previously declared "def refresh" and then you need to create another refresh that'll have part of the old one. Instead of redoing it, you may want to rename the old refresh and make the new one so it'll call the old procedure.

Code:
def refresh
  @value = 3
end

alias my_old_refresh refresh

def refresh
  my_old_refresh
  print @value
end

You may call the renamed procedure as a standard procedure, whenever or wherever you need. ;)


SEE YA!!!!!
 
thanks for the alias.

now with Minimalistic Sideview Battle System.
Code:
  alias side_view_setup setup
  def setup(actor_id)
    side_view_setup(actor_id)
    @battler_name = ''
    @battler_hue = 0
    case actor_id
    when 1
      @battler_name = 'Ralph'
    end
    Bitmap.new('./Graphics/Battlers/Ralph.png')
  end
  
  def use_sprite?
    return @battler_name != ''
  end
  
  def screen_x
    return index * 20 + 100
  end
  
  def screen_y
    return index * 50 + 170
  end
  
  def screen_z
    return 100
  end

that makes the battler visible, right? but which one?
I reckon this one did it

Code:
  def use_sprite?
    return @battler_name != ''
  end

but, is that really the one? and I don't understand how?

Another question, if I want to draw a Bitmap in battle, what do I have to do?
Code:
Bitmap.new('./Graphics/Battlers/Ralph.png')
I made that line in def setup(actor id) but nothing happens.
I mean, how could I recall [show picture] just like usual, but in battle?
 
@DivineLight:
That piece of code selects the Battler image for the character and sets some procedures to return screen position and if it'll use a battler.

"that makes the battler visible, right? but which one?"
No. Well, I can't simply explain what it do. It's more complicated than that...

Code:
  def use_sprite?
    return @battler_name != ''
  end
This creates a function that'll return if it'll use a sprite. Basically, it checks if any Battler picture has been choosed.

Code:
I made that line in def setup(actor id) but nothing happens.
That'll not work, because you haven't made a Sprite that will draw it. Bitmaps are a bunch of pixel color data. It's just information. To draw it on screen, you need a Sprite. These has a "bitmap" property, that'll store the Bitmap information.
@mysprite = Sprite.new
@mysprite.bitmap = Bitmap.new("put file here...")
Another thing. Never use "Bitmap.new" to load your files. Use the Cache functions instead. To load a Battler, for example, you should use "RPG::Cache.battler(file, hue)".

You should read more RGSS tutorials and also study the other scripts. ;) Those are preety nice sources for learning.
SEE YA!!!!!
 
Hi, I figure this goes here as I'm trying to work out how a default script works.

I want to add a new part to game_party, for what hair type they have. This will be an integer.

Something testable, like...

$game_party.actors[0].hair_type = 1

How would I do this?
 

Zeriab

Sponsor

What you really want is not something new to Game_Party, but to Game_Actor.
You want to add an attribute to Game_Actor.
Assuming you both want to read and write to it you can do it like this:
Code:
class Game_Actor
  attr_accessor :hair_type
end
There ya go ^_^

Note that the default value is nil

The reason I added it in the Game_Actor class is simply that the hair type belong to the actor and not to the party. Unless you want a party hair style >_>
 
Let's start with the basic...

There's a Sprite class you should use for displaying pictures. Using it is easy as one-two-three. I believe you know about objects. If you don't, here's info about it. If you already learned about it, just skip it.
Objects, or instances, are exactly what they mean: an object. They are created from a class, that determines what this object do. For example, in a RPG we could have a Monster class, and many monster objects, such as "slime", "wolf" and et cetera. That explained, you should know that objects have properties and methods. Keeping into the Monster example, a Monster object could have name, HP, MP and other things. Those are properties. There's also methods, things a Monster could do, like attack, disappear, calculate damage and move its battler picture, just to mention some of them. An object is created like this:
@mymonster = Monster.new
That's just an example. @mymonster is the variable that'll "hold" the object, or if you prefer, that will be the object (but that isn't actually true, but works fine to explain to newbies). Monster is the class that we use to make the object. And "new" is a method of the class (yes, they have methods too) that makes the object. Classes are unique because they can be used to make new objects, be sure to remember that. Also, never forget that the object will have the class properties and methods!
We can read an object property:
@mymonster.name = "Gooey"
@mymonster.hp = 300
And we can execute an object method, too.
@mymonster.attack(@another_monster)
@mymonster.moveto(x, y)
@mymonster.disappear
Some methods requires information to be passed to it, so it can be executed corretly. For example, we should specify who to attack, and where to move to. Even some "new" methods, that we use to create objects, needs some information sometimes. If you don't know, by the way, the X and Y are positions. X is the horizontal position, and Y is the vertical position. They are used, like, everywhere.
Oh, by the way, have you seen that "@" symbol? It means that @mymonster is used only on the class I've created it. So let's say I've made it on Scene_Battle, I can use it ANYWHERE on Scene_Battle, but not in other classes. There's also a $ symbol. Variables that have this symbol are used in any script. If you don't use any symbol, then the variable just can be used into the "def" it has been created.
That's a preety raw explanation, probably there's more you should learn about objects. But that's more of the basic and what you REALLY need to know.

Alright, now about Sprites. A Sprite class is used for putting a Bitmap on screen. There's a Sprite class and a Bitmap class. We should, first, make a Sprite.
@picture = Sprite.new

Well, I need to stop now (I'm at school :P). But I'll continue later! :)
SEE YA!!!!!
 
I hope this is in the correct place, as well as formatted properly, with a clear and concise request...

To being delving into the world of scripting, I suppose my first option should be to peruse this thread entirely, and see if my specific topic is already covered.  But I'm a bit impulsive, so I'll just ask.  I'd like to begin my scripting lesson with something simple.  So I'm thinking of a system where when it's intitalized it sets up an array of strings.  For the sake of explanation, let's say 10 strings.  Then I'd like a method call that I could call from an event that would return a random element from that array as a response to a player action.  In reality, should be quite simple really, no?  Could be easily implemented via an event, I think, but setting it up as an event wouldn't help with my scripting education...
 
Sorry for taking so long to answer...
I'm preety busy with a school project right now. :P

@DivineLight:
Well, we should know that Sprite classes has many attributes. Knowing them will make everything easier:
Sprite.bitmap -> It's a Bitmap object that holds the picture this Sprite will draw. Yeah, sprites aren't pictures, they just draw a picture (that is the bitmap).
Sprite.x and Sprite.y -> As I said, X and Y are for positions.
Sprite.visible -> This determines whenever the sprite is drawn. As default, it is set as true, so you should care on it only if you really need to make a sprite to disappear.
Sprite.update -> This... is not an attribute. It's a method. As any "update" method, it should be called each frame, on the scene's update method.

There's not a "draw" method for the Sprite class. If the sprite exists, and it's Visible attribute is set as true, it is drawn. Simple as that! ^^
There are plenty of other attributes and methods, but those aren't really necessary.
Hope you understood... :)

@wizaerd:
I, uh... fail to see your question. :P

SEE YA!!!!!
 

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