Jump to content
kal

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

Recommended Posts

Ok, so I do that, but what is the symbol? For example, with the defaults I have, button 8 is R: how do I set R being pressed as a condition? Using :R doesn't work. Do I use :button_8 or something like that?

Share this post


Link to post
Share on other sites

Using :R should work.

Button 8 is the button number of a gamepad. It is also 'Q' key on the keyboard (if you look on the keyboard tab)

 

EDIT: 'W' on the keyboard... oops haha.

Edited by Galv
  • Like 1

Share this post


Link to post
Share on other sites

Ah.... I see now. The symbol :R is linked to the key W in my game. Thanks for the tip! I don't know why I was looking at the game pad tab. Not thinking clearly enough. :)

Edited by siChainlinks

Share this post


Link to post
Share on other sites

how do I return the amount of actors in my database?

I want a variable to hold that value

Share this post


Link to post
Share on other sites

I think in a Control Variable set to script you can use:

$data_actors.count - 1

Share this post


Link to post
Share on other sites

Note that $data_actors.count - 1 includes all of the "empty" actors as well.

 

Meaning, if your database looks like

1. Actor 1
2.
3.
4.
5. Actor 2
This would be treated as 5 actors and not 2. Edited by Tsukihime
  • Like 2

Share this post


Link to post
Share on other sites

How do I get the amount of "Alive" Battle Members? And the amount of "Alive" Enemies in the Troop?

Share this post


Link to post
Share on other sites

$game_troop.alive_members.count

$game_party.alive_members.count

  • Like 1

Share this post


Link to post
Share on other sites

Hi, I'd like to get a clarification. In many scripts I see something like this

 

random_variable_name ||= random_value

or this 

 

(random_variable_name ||= random_value)[index/key] = value

For the latter example,the random_variable is an array or a hash.

 

I tried to search for documentation on ||= but couldn't find any. I think that it's a syntax tweak for a 'conditionnal assignation' but I'd like to understand the full reach/range of it.

 

So could someone explain it to me or redirect me to documentation ? (I looked in Ruby-doc.org and such but couldn't find any thing)

Edited by Riff

Share this post


Link to post
Share on other sites
a ||= b

can be used instead of

a ? a : b

, which in itself is a shortened form of

if a
 a
else
 b
end

. "Give me a, but if it doesn't exist (or is false), assign it the value b."

Share this post


Link to post
Share on other sites

Oh okay, thanks. So is the second one equal to 

 

random_variable        = random_value if random_variable.nil?
random_variable[index] = random_value

?

Edited by Riff

Share this post


Link to post
Share on other sites

Your second example would be this:

random_variable_name = random_value unless random_variable_name
random_variable_name[index/key] = value

Share this post


Link to post
Share on other sites

How would I get Kread-EX's Custom Weapon Formulas to apply to more than 1 Skill?

 

Modifying 

if item == $data_skills[1] && user.is_a?(Game_Actor) 

Into

if item == $data_skills[1, 7, 8, 9, 10] && user.is_a?(Game_Actor)

Returns an Error

 

 

 

class Game_Battler
	#--------------------------------------------------------------------------
	# â— Calculates the damage value
	#--------------------------------------------------------------------------
	alias_method(:krx_wformula_gb_mdv, :make_damage_value)
	def make_damage_value(user, item)
		if item == $data_skills[1] && user.is_a?(Game_Actor)
			user.weapons.each do |wep|
				if wep.formula != nil
					value = wep.formula_eval(user, self, $game_variables)
					value *= item_element_rate(user, item)
					value *= pdr if item.physical?
					value *= mdr if item.magical?
					value *= rec if wep.formula_recovery
					value = apply_critical(value) if @result.critical
					value = apply_variance(value, wep.formula_variance)
					value = apply_guard(value)
					@result.make_damage(value.to_i, item)
					return
				end
			end
		end
		krx_wformula_gb_mdv(user, item)
	end
end

 

 

Share this post


Link to post
Share on other sites

I think you'd have to use

 

if [$data_skills[1], $data_skill[7], $data_skills[8], $data_skills[9], $data_skills[10]].include?(item) && user.is_a?(Game_Actor)

Because you can't compare a FixNum and an Array (and I think also because you can't call multiple value out of an array using that syntax)

Edited by Riff

Share this post


Link to post
Share on other sites

Thanks, it still returns an error. Perhaps I need to set up an Array of somesort before doing it?

ie.

$data_skills.array[1,7,8,9,10].include?(item) && user.is_a?(Game_Actor)

I don't know how Array works so sorry if I just created the worst line of script in the world.

 

 

 

Error: Line 158 NoMethodError occured

Undefined method '[]' for nil:NilClass

 

 

Share this post


Link to post
Share on other sites

Try this one

 

if [$data_skills[1], $data_skills[7], $data_skills[8], $data_skills[9], $data_skills[10]].include?(item) && user.is_a?(Game_Actor)

I think it didn't work just because I don't know how to spell properly s-k-i-l-l-s

  • Like 1

Share this post


Link to post
Share on other sites

One way is to say


[1,7,8,9,10].any? {|id| $data_skills[id] == item } && user.is_a?(Game_Actor)

I would suggest checking whether the user is an actor or not first before doing the loop.
  • Like 1

Share this post


Link to post
Share on other sites

Try this one

 

if [$data_skills[1], $data_skills[7], $data_skills[8], $data_skills[9], $data_skills[10]].include?(item) && user.is_a?(Game_Actor)

I think it didn't work just because I don't know how to spell properly s-k-i-l-l-s

 

Aha, yeah it works now! Thanks a bunch.

 

 

 

One way is to say

[1,7,8,9,10].any? {|id| $data_skills[id] == item } && user.is_a?(Game_Actor)
I would suggest checking whether the user is an actor or not first before doing the loop.

 

I'll try this one since it's more accessible (nevertheless thank you, Riff) And for your note, you mean to make it like this?

if user.is_a?(Game_Actor) && [1,7,8,9,10].any? {|id| $data_skills[id] == item }


 

And sorry to be that guy, but one last question:

How would I get a BGM to play at a position equal to a variable from an Event's Script Call?

I have this:

@> Control Variables: [0020: Multi-Use Variable] = Audio.bgm_pos

@> Script: pos = $game_variables[20]

:              : RPG::BGM.play("Song", 100, 100, pos)

But it doesn't work

Edited by AJNR

Share this post


Link to post
Share on other sites

 

 

How would I get a BGM to play at a position equal to a variable from an Event's Script Call?

I have this:

@> Control Variables: [0020: Multi-Use Variable] = Audio.bgm_pos

@> Script: pos = $game_variables[20]

:              : RPG::BGM.play("Song", 100, 100, pos)

But it doesn't work

 

Nothing related to the Weapon Formula, that works fine. Just my method of getting a BGM's Position isn't working.

Share this post


Link to post
Share on other sites

Music isn't playing? Can't find the file? Starting from the beginning? What is the value of your variable?

 

Not all formats support starting from a certain position.

Help file says only ogg and wav support it.

Edited by Tsukihime

Share this post


Link to post
Share on other sites

Sorry for the vague request, Hime.

I found this out looking through the Help Contents and all the Audio I have is converted to .Ogg Vorbis via Audacity.

The Error is:

undefined method 'play' for RPG::BGM::Class

 

The variable works because I tested it and displayed it in a textbox and it returns a number, am I using the wrong path

to get the file name?

 RPG::BGM.play("Song", 100, 100, pos)

"pos" being the variable, which is set in a line above the BGM.play

pos = $game_variables[20]

The variable is equal to the current BGM's Position so that when I switch, the new BGM starts at the position of the old BGM.

Edited by AJNR

Share this post


Link to post
Share on other sites

Haven't tested this but I think it should look more like:

RPG::BGM.new("Song", 100, 100, pos).play

Share this post


Link to post
Share on other sites

The problem with BGM.new is that I think it automatically starts it at the Position of 0.

When I used that, it returns wrong number of arguments (4 for 3)

The extra argument being the "pos", and first three being filename, volume and pitch.

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.

×
Top ArrowTop Arrow Highlighted