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.

How to use *.rb files in xp/vx

How do I go about using my ruby scripts in Rpg Maker?
And also, can I use classes that are built in to xp
(Win32API for example), but not built in to ruby itself?

Any help is appreciated.
 

Zeriab

Sponsor

I know of two ways to run external .rb-files.
You can require them:
[rgss]$: << '.' # Add the current working directory
require 'my_file' # You don't have to write .rb, but you can do it
[/rgss]
Note that you cannot require .so-files like you can in Ruby.
The other way is to load the data of the file and then evaluate it:
[rgss]file = File.open('my_file.rb', 'r+')
data = f.read
file.close
eval(data)
[/rgss]
With this approach the file extension doesn't have to be .rb

The difference between the former and latter approach is that require only execute the file the first time where as the second way evaluates the data every time it is encountered. There probably are other differences although I doubt they will be of any significance except in rare situations.

*hugs*
- Zeriab
 
The difference between the former and latter approach is that require only execute the file the first time where as the second way evaluates the data every time it is encountered.

so in other words you shouldnt use require incase someone press f12?
 

Zeriab

Sponsor

You run the code in the game environment which means that you can use all classes and etc. which is present. That includes the hidden classes.

@SolstICE:
Or perhaps that is exactly what you should use in case of F12.
If the code should not be executed more than once then require will take care of it.
If it overrides methods then you shouldn't use require.

It really depends on the situation.
 
One more question (for real this time).

How do I make a rescue for subclasses of the StandardError class?

Do I do this:

rescue StandardError::Error

or rescue Error

or what?

And can I have multiple rescue clauses in one begin/end?

Like:

begin

rescue Err1

rescue Err2

end
 

Zeriab

Sponsor

You just rescue the particular classes you want.
You can have something like
[rgss]begin
  # some code
rescue ArgumentError
  # Rescue Argument Error
rescue NameError
  # Rescue Name Error
rescue StandardError
  # Rescue all other standard errors
rescue RuntimeError
  # This will never be called since 'rescue StandardError' catches this one as well.
end
[/rgss]

Do you see how this works? Look in the help file for checking which error classes are built-in.
Feel free to ask if there is anything you don't understand.

*hugs*
- Zeriab
 

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