Jump to content
kal

Ruby/RGSS3 questions that don't deserve their own thread

Recommended Posts

Wow that script is huge by the way! Looks awesome too. I'm gonna go through it and see what I can learn. A lot can go wrong in such a big script, so yeah it might be better if you stick with copy/pasting mitchi.

 

And here's something you can do to make copy/pasting a lot easier (this requires that you have Ruby installed - download it here: http://rubyinstaller.org/)

 

Let's write a simple Ruby script that checks if an RPG Maker VX rvdata file has changed, and if it has the script will copy it to a RPG Maker VX Ace project folder. This will enable you to edit scripts in VX and simply press CTRL+S to save the project and then the program will automatically copy it to your Ace folder for you, and the changes will be in effect the next time you start your Ace game.

 

Start by creating a new folder (for example: C:\Acescripts\copy). Now create a new file called copy.rb and open it up in a text editor.

 

Let's leverage the powerful FileUtils standard library to make this script really simple:

 

require 'fileutils'
VX = "C:/Users/Kal/Documents/RPGVX/Testing2/Data/Scripts.rvdata"
ACE = "C:/Users/Kal/Documents/RPGVXAce/Project1/Data/Scripts.rvdata2"
loop do
 unless FileUtils.identical?(VX, ACE)
FileUtils.copy_entry(VX, ACE, false, false, true)
puts "Copy complete"
 end
 sleep 1
end

 

So here we have two constants, VX and ACE that holds the path the the VX rvdata file and the Ace rvdata2 file.

Then there's an infinite loop. In the loop we use the FileUtils.identical? method to see if the two files are the same. This means that the VX rvdata file has been copied and overwritten the Ace rvdata2 file already so we do nothing in this case. If this is not the case, that means that the two files are different, and we need to replace the current rvdata2 file with VX's rvdata file.

 

To do this I used the FileUtils.copy_entry method. This method copies the first file system entry (VX in this case) to the second (ACE). The third flag (true) tells FileUtils to remove the source entry before copying, which is what we want in this case.

 

sleep 1 will pause the script for 1 second, so we don't stress the CPU unnecessarily.

 

Now open up a command prompt and change to the folder you made. Type "ruby copy.rb" (without the quotes) and leave the command window open. Now try and make some edits to your VX script editor and it should automatically copy it for you. :)

 

Edit: Here's something completely different that I just found out about. You can get Peter Cooper's Ruby 1.9 walkthrough for only $9, but only until the 19th! Hurry up and get this if you do any RGSS coding it's a really valuable resource at a great value: http://rubyinside.com/19walkthrough/xmas.html?utm_source=rubyweekly&utm_medium=email

Edited by kal

Share this post


Link to post
Share on other sites

Thats what I was trying to figure out how to do but through a script Fomar. I kinda have it working myself now but the issue is that the script input method in the events command is too small for what I'm trying to do and I was trying to figure out how to get it to run in a script that could be called.

Share this post


Link to post
Share on other sites

 

No need making an script call

 

 

I learn something new every time I look at the interface, thanks.

 

@Lowell - make a method somewhere and call that e.g.

module Lowell

 def self.make_message
   $game_variables[1] = "something"
 end
end

 

Then call it from an event.

Lowell.make_message

Share this post


Link to post
Share on other sites

I got a question, I know rgss3 uses ruby 1.9.2 'n all, but can it use all the functions and classes that ruby 1.9.2 can use? If it's been answered already just link to the post.

Thanks.

Share this post


Link to post
Share on other sites

Yes you can use the full 1.9.2 language (as far as I know). For example, you can now use methods such as require and load to run external Ruby files, which you couldn't do in RGSS2. What you can't do is use the standard library or gems (external packages) because Enterbrain didn't include the standard lib in VX Ace. For example in normal Ruby you would do something like this

require 'yaml'

To load the Yaml library (a library to serialize objects to a human readable format that is part of the Ruby standard library). If you try that in VX Ace you get an error saying there is no such file to load.

Edited by kal

Share this post


Link to post
Share on other sites

Hi! I'd like to know if there's a way to make snapshots of the screen (as in, Graphics.Snap_to_bitmap) and use them in an in-game picture that can be manipulated with "Move picture", "Erase Picture", etc, and how can one do it? Thanks in advance

Share this post


Link to post
Share on other sites

This may or may not require it's own thread, noteboxes.

Now I haven't read the help manual on them but does anyone have a clear idea of how to use them with ruby?

 

Thanks^^

Share this post


Link to post
Share on other sites

This may or may not require it's own thread, noteboxes.

Now I haven't read the help manual on them but does anyone have a clear idea of how to use them with ruby?

 

Thanks^^

Usually it's the variable and .note

e.g. $data_skills[1].note

If it's just a flag you want to put in the notes you can just use .include?() and a simple regex. I believe YanFly has a note tagging script in his core module, you might be interested in looking at that.

Edited by Fomar0153

Share this post


Link to post
Share on other sites

This is probably weird, but why did enterbrain have to simplify drawing menu text? Yes, it's a good idea to simplify but not when you want HP and MP to differ locations.

 

I know I can just do what I've done with XP/VX I just found this odd.. and kind of annoying>< I also have to recode formations but meh that's for another day.

Share this post


Link to post
Share on other sites

this:

def check_hp

   if @actor.state?(2) #POISON
  refreshbitmap
  @health.bitmap = Cache.load_bitmap("Graphics/Menus/","PoisonHealth.jpg")
  @healthlead.bitmap = Cache.load_bitmap("Graphics/Menus/","PoisonHealthLead")
  @healthtop.bitmap = Cache.load_bitmap("Graphics/Menus/","PoisonHealthTop")
   end

   if @actor.hp > @actor.hp * 3 / 4 #Above 75%HP
  refreshbitmap
  @health.bitmap = Cache.load_bitmap("Graphics/Menus/","+75%Health.jpg")
  @healthlead.bitmap = Cache.load_bitmap("Graphics/Menus/","+75%HealthLead")
  @healthtop.bitmap = Cache.load_bitmap("Graphics/Menus/","+75%HealthTop")
   end



   if @actor.hp < @actor.hp/4 #Below 25%H
  refreshbitmap
  @health.bitmap = Cache.load_bitmap("Graphics/Menus/","25%Health.jpg")
  @healthlead.bitmap = Cache.load_bitmap("Graphics/Menus/","25%HealthLead")
  @healthtop.bitmap = Cache.load_bitmap("Graphics/Menus/","25%HealthTop")
   end

   if @actor.hp < (@actor.hp*3)/4 #Below 75%HP
  refreshbitmap
  @health.bitmap = Cache.load_bitmap("Graphics/Menus/","-75%Health.jpg")
  @healthlead.bitmap = Cache.load_bitmap("Graphics/Menus/","-75%HealthLead")
  @healthtop.bitmap = Cache.load_bitmap("Graphics/Menus/","-75%HealthTop")
   end

   if @actor.hp == 0 #DEAD
  refreshbitmap
  @health.bitmap = Cache.load_bitmap("Graphics/Menus/","0%Health.jpg")
  @healthlead.bitmap = Cache.load_bitmap("Graphics/Menus/","0%HealthLead")
  @healthtop.bitmap = Cache.load_bitmap("Graphics/Menus/","0%HealthTop")
   end

 end

Dont know why but only the 'DEAD" work correctlly

all other methods returns always "HP above 75%"

any help?

Share this post


Link to post
Share on other sites

Are... you trying to ask for HP to be above HP?

Try @actor.mhp for the actor's MaxHp.

if @actor.hp < (@actor.mhp * 0.75).to_i
 if @actor.hp < (@actor.mhp * 0.25).to_i
   if @actor.hp == 0
   # 0 Hp - Dead

   else
   # 25% Hp
   end
 else
 # Less than 75%, greather than 25% Hp

 end
else
# Greater than 75% Hp
end

Share this post


Link to post
Share on other sites

What does:

 


$data_system.opt_extra_exp ? 1 : 0

##and

battle_member? ? 1 : reserve_members_exp_rate

 

mean? I know they are evaluating something and returning a .... 1? (nil returns a 0?) so....whats going on here?

Share this post


Link to post
Share on other sites

That's a ternary operation. You can read about it here.

 

http://en.wikipedia....rnary_operation

 

battle_member? ? 1 : reserve_members_exp_rate

 

It is equivilant to:

 

if battle_member? == true
 return 1
else
 return reserve_members_exp_rate

 

You can assign the resultant to another variable if you want.

 

value = battle_member? ? 1 : reserve_members_exp_rate

Share this post


Link to post
Share on other sites

thank you bubbles that was confusing me to no end. I also have more question, the following code does not change the max level to above 99, why? I traced it back and this is where the max level is being set...

 

class RPG::Actor < RPG::BaseItem

 alias init initialize
 def initialize
@max_level = 999
init
 end

end

 

My help file and the script comments are in Japanese so i can only decipher so much.

Edited by A.

Share this post


Link to post
Share on other sites

thank you bubbles that was confusing me to no end. I also have more question, the following code does not change the max level to above 99, why? I traced it back and this is where the max level is being set...

 

class RPG::Actor < RPG::BaseItem

 alias init initialize
 def initialize
@max_level = 999
init
 end

end

 

My help file and the script comments are in Japanese so i can only decipher so much.

What script were you looking in I can probably help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×