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.
 
Better you had made a new class for it, otherwise it won't work.

First, you have to create the Contents property for it. Make sure you initialized it at the constructor "initialize" of the window.
self.contents = Bitmap.new(width-32, height-32)

Then, make a new method for this class (that's why you had to make a new class).
We can do the dirty or the correct way.
The correct way is to make a method that'll draw your text in the Contents (wrapping Bitmap.draw_text() on Contents).
The dirty way is to make a function that'll return us the Contents so we can manipulate it as we need.

Let's do the dirty way :)P).
Code:
def get_contents
  return self.contents
end

Once you made the window, you can call this function and then call the draw_text method at the event of your choice.
Code:
@myWindow = Window_Mywin.new
@myWindow.get_content.draw_text(0,0, 256, 32, "The Dirty Way")


Hope it helps you. =D
SEE YA!!!!!
 
Here's a quick question for anyone.  Is there anyway to turn a floating integer into a whole integer?  And just in case I said that wrong, I mean making a number with a decimal place round up or down depending on if the decimal was .5 or higher?
 

Zeriab

Sponsor

floating integer? An integer is by definition whole.
I believe you can convert Floats (floating points) to integers by using the .to_i method. It should follow the standard rounding rules.
You can look in the help file and search for Float. It has a description of the method present

*hugs*
- Zeriab
 
The Numeric type (base for all the numbers you use on Ruby) has some functions to rounding up or down (or to the closest).

To round to the closest, it's the round function: myVar.round
To round down (e.g., 3.8 will be 3), it's floor: myVar.floor
And to round up (e.g., 11.05 will be 12), it's ceil: myVar.ceil


Take care! =D
SEE YA!!!!!
 

revee

Member

um.... sorry for asking weird question... but, i wanna ask you all something...

what does "return" refer?
i really doesn't understand it at all....

and, it is possible to make Windows_Command became horizontal, not vertical...

thank you if you answer this weird question
 
revee,

the "return" keyword specifies the function's return value. A method ("def" block) may return a value when called. When they do, it's called a function. A function may be used to math, checks and other things. E.g. a function that sums two values, or a function that returns whenever you have succeed to attack an enemy. Some methods/functions requires arguments in the call to work. Those are specified between ()s. Yet some functions doesn't requires any argument at all, as a function that returns the PI value.
Code:
result = sum(3, 4)
attacked = player.attack_hit(enemy)
number = Math.pi
A function differs from a method simply because it has the "return" statement.
This is a method:
Code:
def close_window
  self.contents.dispose
  self.dispose
end
And this is a function:
Code:
def pi
  return 3.141592654
end


For making Window_Command horizontal, you have two options:
- overwrite the class
- set the number of columns to the number of items being displayed

Overwritting the class requires you to rewrite the drawing functions, input and etc...
Changing the number of columns is the most simple method, as you can use the standard Window_Command class as it is. Just change the number of columns and voilá, it's horizontal.

SEE YA!!!!!
 

Zeriab

Sponsor

! stands for not. (Boolean operator)
Code:
!true == false #and
!false == true

! can also be placed at the end of method names
Code:
array = [1,3,2]
new_array = array.sort!
The ! indicates that it is a destructive method. This means it alters the object on which it is called. (array.sort also returns a sorted array but does not alter the array on which it is called)
This is merely a convention which is not followed often enough for you to rely on it.

*hugs*
- Zeriab
 

Aeioe

Member

Alright, after reading through this thread my question is going to seem really simple in comparison...

In Window_Status I've added a bunch of little images with numbers next to them like this:
Code:
self.contents.font.color = system_color
    self.contents.draw_text(05, 130, 96, 32, "Skills")
    @mining = Sprite.new
    @mining.bitmap = RPG::Cache.picture("GG Mining")
    @mining.x = 20
    @mining.y = 180
    @mining.z = 100 # 1 - 9999+.

This works fine in the status menu, but when I exit the menu all the words disappear as they should but the images stay up. How can I delete those images at window close?

Thank you!
~Aeioe
 

Injury

Awesome Bro

Hey there, I was wondering if anyone can run me over some arrays and maybe give an example of how/what I would use one in? I know it involves multiple numbers, but what would you do with them? I looked over tutorials explaining that it's a way to identify variables or instances of the same name, but what about other applications in gaming?
 
An array can contain multiple values. But why have

Variable = [3, 5 ,7]

when you can have

Variable1 = 3
Variable2 = 5
Variable3 = 7

?

Because of the way you get numbers from arrays : Indexes. In the above example, Variable[1] == 3 Variable[2] == 5 and Variable[3] == 7. But you don't have to write a number in the brackets []. You can have another variable in it. Example : Variable[anothervariable] == 3 when anothervariable == 1

Why is it useful? First, it's clean neat, and you can have arrays (also called tables for a good reason) with more then one dimension (ex : Variable = [[1, 2, 3],[4, 5, 6]] Variable[1][1] == 5)

Second, how would you, for example, erase all pictures with events? Erase Picture : 1, copy and paste it 49 times and change the value of each? Or is it easier with this? :

for i in 0..2
$game_screen.pictures[ i ].erase
end

Saves times. There are probably billions of other possibilities, but this is the basics.
 
Arrays, eh? They are used very, very often. Usually you're going to find it hard to get around using arrays and/or hashes in more complicated scripts.

Why arrays are useful is because it uses a numeric index sorting. The first index starts at 0 and the last index is unlimited as far as I know.
The reason for using arrays is you can push data into the next available index so you can keep control of all items you have put in there.
Take a look at the Window_Item for example. It checks every item, but only pushes those items the part has 1 or more of in the inventory into the array.

A simple array example:
Code:
ary = []
rand(100).times do
  ary << rand(100)
end
p ary
You may also use ary.push(rand(100)) to do the exact same thing.

Arrays have several useful methods to control them. Such as sort will sort the array alphabetically.

Like so:
Code:
ary = ['a', 'b', 'd', 'c']
ary.sort!
p ary # => ['a', 'b', 'c', 'd']
If you are wondering why I used sort!, that is because it alters the object directly, where I believe sort only returns it sorted.

As usage examples of where this would be useful, take a look into Window_Item, Window_Skill and Window_EquipItem in the default scripts.

Hope that helped.

EDIT: A tad too late again...
 
I am new to this website, but I acquired both RPG Maker XP and RPG Maker VX. Can anyone tell me how to put my Battles into sideviews, so that all people (and weapons and monsters and animations), attack damage, and magics appear in the screen, please? Thank you!
 

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