Jump to content
kal

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

Recommended Posts

Heyo, im trying to add a event to the map. But its rather difficult.

 

This is how far i came but now i dont know any further.

huhn = Game_Character.new
huhn.set_graphic("Animal",2)
viewport = Viewport.new 10,10,640,480
$game_map.events[$game_map.events.length] =
Game_Event.new( 1, Sprite_Character.new(
viewport,huhn))

 

May anyone know?

Share this post


Link to post
Share on other sites

Hey, I'm currently in the process of charting the unkown waters of RGSS3 and I took a moment to test my memory of the ruby I learnt a year or so ago for RMVX on what I have already charted. I am currently finishing up my notes on the Vocab module and I noticed that they have an abbreviated and non-abbreviated form of basic terms.

I made this code:

def Vocab.level(a)
 if a == 1
   Vocab::level_a
 elsif a == 0   
   Vocab::level
 end

end

 

In an event, I placed a script call:

puts Vocab::level(0);

puts Vocab::level(1);

 

My problem is, I get an error whenever I use the second line of that event. "Script 'Game_Interpretter' line 1411: ArgumentError occured. Wrong number of arguments (0 for 1)". In the RGSS console window, I get the output for the first line, so I know it works properly AND that the API isn't offsetting my arguments by +1 to make it more human compatible. What is causing the issue, and how can I prevent this in the future?

Share this post


Link to post
Share on other sites

So what you are doing is that you are overriding the default implementation of the module method level in Vocab. You can call module methods in two ways:

 

# first way
Vocab.level
# second way
Vocab::level

 

Your first line (puts Vocab::level(0)) will fail because the code will go in to the elsif statement and attempt to call the module method level again (in other words, it will try to call itself). However, this fails because there is no argument for that line, and it needs one argument because that's how you defined the level method.

 

Your second line succeeds because it calls the module method level_a which does not require any argument (as defined in the editor).

 

Personally, I prefer to use the dot syntax when calling a module method and not :: which is used for accessing constants in a module.

Share this post


Link to post
Share on other sites

Ah, I understand now. I got used to C++ allowing overloaded functions. I suppose I'll have to make a call to basic(basic_id) if I want it to work then.

 

I agree with using the dot operator instead of the double colon, but It didn't cross my mind that ruby would allow it. I'm happy that I remember enough to understand what the scripts are doing when I look at them in the editor, but it's obvious that I need to become more versed in the niceties of how code executes.

 

Thanks for the clarification.

Edited by Aarowaim

Share this post


Link to post
Share on other sites

Quick question, anyone know the Input.press? for backspace and if there isn't one how do you add it to the Input module; if possible?

 


 

Edit:

Second question: How do you keep Scene_Title from fading in, when I tried duing it from Scene_Map it effect other Scene's to like Scene_Name. I just want to Title screen to not fade in when going to scene_map.

Edited by Bigace360

Share this post


Link to post
Share on other sites

How would I go about triggering a common event in battle with script? I know that skills can do it, but I have no idea where to look for how they trigger it. I found in the reference manual that it obtains the effects from RPG::UsableItem::Effect as follows:

class RPG::UsableItem::Effect
 def initialize(code = 0, data_id = 0, value1 = 0, value2 = 0)
@code = code
@data_id = data_id
@value1 = value1
@value2 = value2
 end
 attr_accessor :code
 attr_accessor :data_id
 attr_accessor :value1
 attr_accessor :value2
end

 

I understand what it's doing, but I don't know where RPG::UsableItem::Effect is processed, so I have no idea where to look for how a common event is called during battle.

Edited by Aarowaim

Share this post


Link to post
Share on other sites

Quick question, anyone know the Input.press? for backspace and if there isn't one how do you add it to the Input module; if possible?

 


 

Edit:

Second question: How do you keep Scene_Title from fading in, when I tried duing it from Scene_Map it effect other Scene's to like Scene_Name. I just want to Title screen to not fade in when going to scene_map.

 

I guess were ignoring this^^

Share this post


Link to post
Share on other sites

Quick question, anyone know the Input.press? for backspace and if there isn't one how do you add it to the Input module; if possible?

 


 

Edit:

Second question: How do you keep Scene_Title from fading in, when I tried duing it from Scene_Map it effect other Scene's to like Scene_Name. I just want to Title screen to not fade in when going to scene_map.

 

The input module does not define backspace as a symbol, you would need to make your own ruby code to do that. Backspace does appear as \b during text input. You may need to see if RGSS3 allows a function such as 'gets', but it would be more likely that you would need to find out the keycode for backspace and use that for a symbol. I have very little experience with input methods from standard ruby, considering that it is so hard to find information on the methods simpler than the 'gets' method.

 

As for your second question, consider the following code exerpts:

Scene_Base

 def post_start
perform_transition
Input.update
 end

 def perform_transition
Graphics.transition(transition_speed)
 end

class Scene_Title < Scene_Base

 def transition_speed
return 20
 end

 

I would change Scene_Title's transition_speed to return a value that'll make it fade in/out almost instantly. I do not know whether a higher or lower value is faster in this circumstance, but it should be easy to figure out.

 

How do you check how big the player's party is?

 

$game_party is an array of characters, '$game_party.all_members.size' to get the current size of the party. .size is a ruby method that can be used on any array.

Edited by Aarowaim

Share this post


Link to post
Share on other sites

How would I go about triggering a common event in battle with script? I know that skills can do it, but I have no idea where to look for how they trigger it. I found in the reference manual that it obtains the effects from RPG::UsableItem::Effect as follows:

class RPG::UsableItem::Effect
 def initialize(code = 0, data_id = 0, value1 = 0, value2 = 0)
@code = code
@data_id = data_id
@value1 = value1
@value2 = value2
 end
 attr_accessor :code
 attr_accessor :data_id
 attr_accessor :value1
 attr_accessor :value2
end

 

I understand what it's doing, but I don't know where RPG::UsableItem::Effect is processed, so I have no idea where to look for how a common event is called during battle.

 

Try this:

 

def run_common_event(id)
 # 117 => common event code, 0 => indent, id => id of common event
 list = [RPG::EventCommand.new(117, 0, [id])]
 $game_troop.interpreter.setup(list)
end

 

Basically what you want to do is to make a call to $game_troop.interpreter.setup and pass along and array that consists of the RPG::EventCommand that will in turn call your common event. When you do this a new fiber is created in $game_troop's interpreter object and this fiber (a fiber is like a lightweight thread) executes the common event in parallel to the main thread that runs the battle.

 

This is all you need to do execute a common event in battle. Take a look at RPG::Troop::Page and RPG::EventCommand for a better understanding of how it works.

 

One thing though, if you want your common event to execute after the battle is supposed to end, say for example after your party killed all the enemies you need to take a few extra steps. The default implementation will just exit the battle even if a fiber (that could be executing for example a common event) is running.

 

To change this first make the fiber instance variable readable in the Game_Interpreter class like this:

 

class Game_Interpreter
 # Make fiber readable so we can check if an event is running
 # before finishing the battle.
 attr_reader :fiber
end

 

Then alias and change one method in BattleManager like this:

 

alias_method :process_victory_cevent, :process_victory
def process_victory
  return unless $game_troop.interpreter.fiber.nil?
  process_victory_cevent
end

 

Now the original process_victory is only run if there is no fiber running in $game_troop.interpreter.

Share this post


Link to post
Share on other sites

Extremely beginner question here: I'm trying to change the color of the Window_BattleLog text that follows the user's name when a skill or item is used.

 

I've tried this, which works, but causes a line break in the text:

 


 def display_use_item(subject, item)
if item.is_a?(RPG::Skill)
  add_text(subject.name)
  change_color(system_color)
  add_text(item.message1)
  unless item.message2.empty?
	wait
	add_text(item.message2)
  end
else
  add_text(sprintf(Vocab::UseItem, subject.name, item.name))
end
 end

 

Basically, I want the battler's name to be white and the rest of the text gray.

 

Edit: the answer is to use an escape character. Thanks to Kread-EX for the info.

 

add_text(subject.name + "\\C[n]" + item.message1)

Edited by Kaidan

Share this post


Link to post
Share on other sites

Extremely beginner question here: I'm trying to change the color of the Window_BattleLog text that follows the user's name when a skill or item is used.

 

I've tried this, which works, but causes a line break in the text:

 


 def display_use_item(subject, item)
if item.is_a?(RPG::Skill)
  add_text(subject.name)
  change_color(system_color)
  add_text(item.message1)
  unless item.message2.empty?
	wait
	add_text(item.message2)
  end
else
  add_text(sprintf(Vocab::UseItem, subject.name, item.name))
end
 end

 

Basically, I want the battler's name to be white and the rest of the text gray.

 

Any pointers would be hugely appreciated.

 

Couldn't you append a blank sprintf of the second part of the message (in the coloured format) to the variable you would have used for the sprintf?

 

e.g, actor.name (white)

Switch colour

sprintf(Vocab::phrase, "")

 

Of course, you would likely have to cut the note into pieces using the %s as the divider, and then resume processing the sprintf after printing the variable in a different colour. You would store the %s's index in the string as a variable to allow easier resumption.

 

Sorry about the pseudo code, but I just turned off my computer and it takes a while to start up.

 

P.S

The line break is because of a \n (newline) character that is probably inserted by the add_text method.

Edited by Aarowaim

Share this post


Link to post
Share on other sites

I maked this code:

 

class Initial
 attr_accessor :message
 def initialize
 @message = "Hello"
 end
 def transmit
print @message
 end
end
initial = Initial.new
initial.message = "Hey!"
print initial.message

 

I want at start of game to show "Hey!". I getted from a tutorial from youtube( RGSS2) .What I maked wrong?

Edited by AlexxanderX

Share this post


Link to post
Share on other sites

print would (or may - I've seen puts used in Ace) print something to the console, but you would not see it in the game screen. To have it show on the menu or map you'd have to see how other text is displayed and do it the same way.

Share this post


Link to post
Share on other sites

I'm trying to reset the variable @move_speed from the Game_CharacterBase class back to 4.3 (which is what I have it at initially) after changing it to 6 with the built in event commands.

 

writing:

@move_speed = 4.3

in one of my events doesn't do it though, how can I get it back to 4.3?

Share this post


Link to post
Share on other sites

Well there are a couple of things you need to consider. First how exactly did you change the variable from the event commands? Are you changing the move speed of the player or of some event (which both inherit from Game_CharacterBase)?

 

So let's assume that you want to change the move speed of the player. You can get to the player object by using the global variable $game_player. Then to set the move speed do this:

 

$game_player.move_speed = 4.3

 

Only this will fail until you add an attribute_accessor to the Game_CharacterBase class (or you could add it to Game_Player if you only wish to change the move speed of the player). So attribute_accessor basically means that you can access (that is get the value of or change the value of) an instance variable from outside the object, which is what we are doing when we write $game_player.move_speed = 4.3

 

So go to Game_CharacterBase and add the following line

 

attr_accessor :move_speed

 

Then you can set the move speed by typing $game_player.move_speed = 4.3

 

If you want to change it for events you first need to get a reference to the event object you want to change, and then do the same thing.

Share this post


Link to post
Share on other sites

Thank you so much that is a huge help! I had no idea how to modify instance variables using events. Thank you!

 

Edit:

I cannot figure out how to properly call a script I wrote and saved under the "Materials" section of the script editor. The script box in the event creation window only allows for 11 lines of code and I need more space than that.

 

#b1, b2 and b3 are calculated
if(b1 && b2 && b3)
 #push snowball over edge
else
  #move it away from player
end

How can I call this from an event? I'm expecting there's a way to just write "ScriptName.method" in the little script box that you can bring up when writing events but I cannot figure out how. I am a bit new to Ruby so sorry for the noob questions.

Edited by eshra

Share this post


Link to post
Share on other sites

I maked this code:

 

class Initial
 attr_accessor :message
 def initialize
 @message = "Hello"
 end
 def transmit
print @message
 end
end
initial = Initial.new
initial.message = "Hey!"
print initial.message

 

I want at start of game to show "Hey!". I getted from a tutorial from youtube( RGSS2) .What I maked wrong?

 

In RGSS3 'p' and 'print' are for debug only purpose, so it's only used with the console window,

To do this in RGSS3, you can use msgbox as print, and msgbox_p as p.

 

 

The better form to call scripts in events, is to create an "Scripts for Events" Script in the script editor, and put your snippets into Procs, then call this procs in the Events.

This will be more flexible and reusable.

EG:

 

In the script:

 

EVENT_RANDOM_TELEPORT = proc do |intp|

_x = rand($game_map.width)

_y = rand($game_map.height)

$game_map.events[intp.event_id].moveto(_x, _y)

end

 

In the Event:

EVENT_RANDOM_TELEPORT.call(self)

 

 

The argument of the proc 'EVENT_RANDOM_TELEPORT' is the event interpreter, you can pass it by defining self as argument, because the event commands runs in the interpreter.

 

You can read more about Procs here: http://rgss3help.tk/.../full/Proc.html

 

Bye o/

Edited by Cidiomar

Share this post


Link to post
Share on other sites

Simple question. Is there a way to comment out entire scripts in the Script Editor? I've been using =begin =end (and it sucks when the coder puts them all over the place) but was wondering if you can just do something a simple command to maybe the script list name to make the game ignore it. (For testing 10+ scripts and not wanting to copy/paste them over and over)

Share this post


Link to post
Share on other sites

Can I somehow change the way draw_text handles text that's wider than the specified width? Or rather, does anyone know exactly what's in draw_text and what I have to work with if I want to override it?

Share this post


Link to post
Share on other sites

Can I somehow change the way draw_text handles text that's wider than the specified width? Or rather, does anyone know exactly what's in draw_text and what I have to work with if I want to override it?

 

Take a look at Bitmap#text_size

Whith this you can use an proxy bitmap to draw the text in, then copy it to the desired bitmap using Bitmap#blt

Edited by Cidiomar

Share this post


Link to post
Share on other sites

I've got a question about bitmaps...

When a bitmap moves to the left, and its X coordinate becomes negative, it's still displayed in-game. However, when it's moved upwards and its y coordinate becomes negative, it just disappears (does not apply for all bitmaps). Can anyone explain me how this works? Or has it something to do with the viewports? (just hate those things)

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   1 member

×