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

Thanks Galenmereth~

I talked to my scripter but he had to leave. Since I'm using only numbers he said it'd be fine to use an array instead of a hash. Now my question is, would I be able to make a variable into a 2-D array? I'd need it to be such so that I can assign a specific event within a specific map its own health~

$game_variables[57][@map_id][this.id] = 500

(this being the event within the map)
Yes, but you have to define it as an array first:


$game_variables[57] = []


$game_variables[57][@map_id] = [] (you have to do this for every first-level element you want)
So would you say a safe way of doing this would be to initialize the first array at game start

$game_variables[57] = []

then for each map that requires it, initialize that specific array once

$game_variables[57][@map_id] = []

edit: awesome. Thanks guys~
If you have 200 maps, I'd do it like this, in the game's startup event (in a script call):

$game_variables[57] = []1..200 {|map| $game_variables[map] = []}Actually I'm not sure if that's the right syntax for the second line and I don't have Ace in front of me to check it out, so if it gives you an error, just use a 1..200 do |map| ... end loop instead.
Alternatively

Code:
$game_variables[57] = Array.new(201) { Array.new }
Or...

200.times {|i| $game_variables[57][i+1] = [] }Edit:

I like  Kaelans approach best 😛
Alternatively

$game_variables[57] = Array.new(201) { Array.new }
holy cow! What's that????

*bows to Kaelan's superiority*
http://ruby-doc.org/core-1.9.3/Array.html#method-c-new

On arrays, you can specify the size and a block to run when initializing each member. It's pretty handy!

You can do something similar with Hashes

Code:
map_info = Hash.new { |hash, key| hash[key] = "Map ID: #{key}" } map_info[1]         # => "Map ID: 1"map_info[275]       # => "Map ID: 275" map_info.keys       # => [275, 1]
ah... so that's how you use it... that's really handy! Thanks for posting that! 🙂
But will it let you save? Because that's what the earlier block did too, and Marshal was unable to dump it into file storage.

$game_variables[1] = Array.new(201) { Array.new }
This will actually save just fine. But this:

$game_variables[1] = Hash.new { |hash, key| hash[key] = "Map ID: #{key}" }Will cause Marshal to be unable to dump the object when saving. No error is given, but saving fails. I'm guessing it has to do with the fact that this stores som extra info on the object that Marslah just simply cannot dump into storage.
But will it let you save? Because that's what the earlier block did too, and Marshal was unable to dump it into file storage.

This will actually save just fine. But this:

$game_variables[1] = Hash.new { |hash, key| hash[key] = "Map ID: #{key}" }Will cause Marshal to be unable to dump the object when saving. No error is given, but saving fails. I'm guessing it has to do with the fact that this stores som extra info on the object that Marslah just simply cannot dump into storage.
That's because the hash holds a proc, which is what actually evaluates the key and determines what to do with it. This is because even after the hash is created, you're still going to use whatever is in the block when you try to access the hash. From the docs on Hash:

If a block is specified, it will be called with the hash object and the key, and should return the default value. It is the block’s responsibility to store the value in the hash if required.
There is no requirement that the array needs to keep any knowledge about the block after it's been evaluated.
I was wondering what would be the best way to determine the weapon type of the currently equipped weapon.

I wanted to set a variable equal to the weapon type and have a script make a decision based on that.
actor.equips[0].wtype_id if actor.equips[0]


should do it for you. You'll need to substitute actor in both places with whatever you're using - $game_actors[id], $game_party.members[index], $game_party.leader, ...
could also do...

actor.weapons.compact.firstto get the weapons data ** Not the weapon type.

For the type, you could do

actor.weapons.compact.first.wtype_id rescue nil 😉
I already made a topic for this but it seems no one there has the idea what's wrong. Can someone pinpoint why my effect on the sprites does not happen, also the fact that the sprites are invisible? My script is this one:

Spoiler
module SOULPOUR_L BREATH_SPEED = 1 BREATH_EFFECT_ENEMY_ID = [1,2,4,5,7,24,28] FLOAT_EFFECT_ENEMY_ID = [26] MOVESIDE_EFFECT_ENEMY_ID = [24,26] STATES_CANCEL_EFFECT = [7,50,54,60]end class Game_Battler < Game_BattlerBase include SOULPOUR_L #-------------------------------------------------------------------------- # * Alias Listings # Aliased Methods: add_state(state_id), remove_state(state_id) #-------------------------------------------------------------------------- alias :soulpour_battlerex_add_state :add_state alias :soulpour_battlerex_remove_state :remove_state #-------------------------------------------------------------------------- # * Add State #-------------------------------------------------------------------------- def add_state(state_id) soulpour_battlerex_add_state(state_id) if self.is_a?(Game_Enemy) for i in STATES_CANCEL_EFFECT if @states.include(i) @breath_effect = false @float_effect = false @moveside_effect = false end end end end #-------------------------------------------------------------------------- # * Remove State #-------------------------------------------------------------------------- def remove_state(state_id) soulpour_battlerex_remove_state(state_id) if self.is_a?(Game_Enemy) sce = false for i in STATES_CANCEL_EFFECT sce = true if @states.include?(i) end if sce == false @breath_effect = true if BREATH_EFFECT_ENEMY_ID.include?(@enemy_id) @float_effect = true if FLOAT_EFFECT_ENEMY_ID.include?(@enemy_id) @moveside_effect = true if MOVESIDE_EFFECT_ENEMY_ID.include?(@enemy_id) end end end endclass Game_Enemy #-------------------------------------------------------------------------- # * Included Modules #-------------------------------------------------------------------------- include SOULPOUR_L #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :breath_effect # Breath Effect attr_accessor :float_effect # Float Effect attr_accessor :moveside_effect # Move Side Effect #-------------------------------------------------------------------------- # * Alias Listings # Aliased Methods: initialize(index, enemy_id) #-------------------------------------------------------------------------- alias :soulpour_battlerex_initialize :initialize #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(index, enemy_id) soulpour_battlerex_initialize(index, enemy_id) @breath_effect = false @float_effect = false @moveside_effect = false @breath_effect = true if BREATH_EFFECT_ENEMY_ID.include?(@enemy_id) @float_effect = true if FLOAT_EFFECT_ENEMY_ID.include?(@enemy_id) @moveside_effect = true if MOVESIDE_EFFECT_ENEMY_ID.include?(@enemy_id) endendclass Sprite_Battler include SOULPOUR_L alias :soulpour_battlerex_initialize :initialize alias :soulpour_battlerex_update :update #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize(viewport, battler = nil) soulpour_battlerex_initialize(viewport, battler = nil) breath_effect_setup(battler) float_effect_setup(battler) modeside_effect_setup(battler) end #-------------------------------------------------------------------------- # ● Moveside Effect #-------------------------------------------------------------------------- def modeside_effect_setup(battler) @moveside_duration = rand(30) @moveside_speed = 0 end #-------------------------------------------------------------------------- # ● Float Effect Setup #-------------------------------------------------------------------------- def float_effect_setup(battler) @float_duration = rand(40) @float_speed = rand(3) end #-------------------------------------------------------------------------- # ● Breath Effect Setup #-------------------------------------------------------------------------- def breath_effect_setup(battler) @breath_phase = 0 @breath_effect = false @breath_effect_speed = 0 if @battler.is_a?(Game_Enemy) and @battler.breath_effect initial_breath = 1.00 + (@battler.screen_x * 0.001) - (@battler.screen_y * 0.001) initial_breath = 1.1 if initial_breath > 1.1 initial_breath = 0.9 if initial_breath < 0.9 self.zoom_y = initial_breath ex_speed = [[BREATH_SPEED, 1].max, 9].min speed = ex_speed * 0.001 @breath_effect_speed = speed + (rand(99) * 0.00001) end end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- def update soulpour_battlerex_update if @battler.is_a?(Game_Enemy) update_breath_effect update_float_effect update_move_side_effect end end #-------------------------------------------------------------------------- # ● Update Moveside Effect #-------------------------------------------------------------------------- def update_move_side_effect return if @battler == nil return unless @battler.moveside_effect @moveside_speed += 1 return if @moveside_speed < 4 @moveside_speed = 0 @moveside_duration += 1 case @moveside_duration when 0..10 self.ox += 2 when 11..15 self.ox += 1 when 16..25 self.ox -= 2 when 26..30 self.ox -= 1 else @moveside_duration = 0 end end #-------------------------------------------------------------------------- # ● Update Float Effect #-------------------------------------------------------------------------- def update_float_effect return if @battler == nil return unless @battler.float_effect @float_speed += 1 return if @float_speed < 2 @float_speed = 0 @float_duration += 1 case @float_duration when 0..15 self.oy += 2 when 16..20 self.oy += 1 when 21..35 self.oy -= 2 when 36..40 self.oy -= 1 else @float_duration = 0 end end #-------------------------------------------------------------------------- # ● Update Breaht Effect #-------------------------------------------------------------------------- def update_breath_effect return if @battler == nil return unless @battler.breath_effect if @breath_effect_speed == 0 ex_speed = [[BREATH_SPEED, 1].max, 9].min speed = ex_speed * 0.001 @breath_effect_speed = speed + (rand(99) * 0.00001) self.zoom_y = 1 + rand(10) * 0.01 end if @breath_phase == 0 self.zoom_y += @breath_effect_speed @breath_phase = 1 if self.zoom_y >= 1.05 else self.zoom_y -= @breath_effect_speed @breath_phase = 0 if self.zoom_y <= 1.01 end end end  
the effect seems to be there but the sprites and their effects are not actually appearing inside the battle.
actor.equips[0].wtype_id if actor.equips[0]

should do it for you. You'll need to substitute actor in both places with whatever you're using - $game_actors[id], $game_party.members[index], $game_party.leader, ...
could also do...

actor.weapons.compact.firstto get the weapons data ** Not the weapon type.

For the type, you could do

actor.weapons.compact.first.wtype_id rescue nil 😉
These both give me a lot of good information to go on, I really appreciate it! 😀
I already made a topic for this but it seems no one there has the idea what's wrong. Can someone pinpoint why my effect on the sprites does not happen, also the fact that the sprites are invisible? My script is this one:
This is not a "Questions that are posted elsewhere but haven't been solved" thread. Please continue looking for help in the topic you've already created.


If you HAVE a thread for it and people haven't been able to solve it, then clearly it is NOT a question that does not deserve its own thread.
Hi peoples I'm back with a question, is it possible to make a command in window alignment to be centered? I mean like in MS word.. For example command menu in title screen(New Game, Continue, Shutdown) Can we make it centered? Like this :

       New Game

        Continue

       Shutdown

Is that possible ? Oh yeah one question again, I'm just curious, is that also possible to change a font into a WordArt? 
Thanks all. Peace.. Sorry if any of my question is silly or wrong or deserves somewhere..
 
If you want this to ONLY apply to the title screen, add this into a new script slot:

class Window_TitleCommand < Window_Command def alignment return 1 endendIf you want it to apply to ALL command windows, add this into a new script slot instead:

class Window_Command < Window_Selectable def alignment return 1 endendI really don't know about your second question. WordArt? I suspect not. But that's not an RPG Maker question. You could ask it in the Program and Utility Discussion forum if you want.
Again shaz thank you for fast and great answer,

Oh well sorry about that WordArt I think that's not what I really want, I just want to make my text big by changing the font, font size and give it outline, after that I want the color of text is transparent(not the outline) so it kinda like a WordArt, but I don't know how to make that. So I think WordArt might save my problem.

Thanks again shaz and also for Dekita for helping me the last time, I forgot to thank..

Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/