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

Chucksaints

Veteran
Veteran
Joined
Dec 8, 2016
Messages
34
Reaction score
1
First Language
Portuguese
Primarily Uses
RMVXA
You have two options. Use either of
.contents_opacity = 128
OR
.contents.font.color.alpha = 128


Complicated. First, you have to erase the arrow from the windowskin image asset, then add your own sprite to the window.
As for the first one, is done, Thank you ^^

For the sprite, how can I check if there is scrollable content up/down & hide sprite if it hasn't?
 

Ebanyle

açspasl~d~dfflass
Veteran
Joined
Sep 2, 2016
Messages
327
Reaction score
184
First Language
Portuguese
Primarily Uses
RMVXA
How do I check values that can all fit into a condition?
For example, I'm trying to make X action in an event if the player is facing down or right direction.
Instead of checking it like this:

Code:
if $game_player.direction == 2
   do X thing
end
if $game_player.direction == 6
   do X thing
end
Is there a way I can check for both in the same condition? Like this:
Code:
if $game_player.direction == 2 [or] 6
   do X thing
else
   do Y thing
end
 

kyonides

Veteran
Veteran
Joined
Nov 17, 2019
Messages
52
Reaction score
10
First Language
English
Primarily Uses
RMXP
That should make it possible for you to check if the direction will ever trigger it.
 

D.L. Yomegami

Sanely Insane
Veteran
Joined
Jan 22, 2017
Messages
170
Reaction score
225
First Language
English
Primarily Uses
RMVXA
Does Ruby have an equivalent to the JS clamp function?

That is, can I write something like value.clamp(min, max) to ensure the value stays between the minimum number and the maximum number, or do I have to use something like ((value, 10).max, 9999).min?
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
110
Reaction score
49
First Language
English
Primarily Uses
RMXP
Quick google check says not until Ruby version 2.4.0

What you alternatively put is equivalent. Make the clamp method yourself if you want.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
4,631
Reaction score
5,267
First Language
Indonesian
Primarily Uses
RMVXA
Untested, but something like this might work.
Ruby:
class Numeric
  def clamp(min, max)
    return [[self,min].max,max].min
  end
end
 

kyonides

Veteran
Veteran
Joined
Nov 17, 2019
Messages
52
Reaction score
10
First Language
English
Primarily Uses
RMXP
You seem to ignore that an Array's min and max methods let you include more than just two values for Arrays have no specific size limit. (OK, Ruby arrays aren't as huge as C's or C++'s vectors...)
 

KK20

Just some XP Scripter
Veteran
Joined
Oct 11, 2018
Messages
110
Reaction score
49
First Language
English
Primarily Uses
RMXP
You seem to ignore that an Array's min and max methods let you include more than just two values for Arrays have no specific size limit. (OK, Ruby arrays aren't as huge as C's or C++'s vectors...)
Why would you need to use more than two values for a min or max? This comment contributed nothing of value to the question at hand.

Alternatively
Ruby:
class Numeric
  def clamp(min, max)
    [min, self, max].sort[1]
  end
end
 

kyonides

Veteran
Veteran
Joined
Nov 17, 2019
Messages
52
Reaction score
10
First Language
English
Primarily Uses
RMXP
You want a quick solution? Here's one!

Code:
class Numeric
  def clamp(mn, mx)
    return mn if self < mn
    return mx if self > mx
    self
  end
end
This one avoids making a value search by index that's unnecessary.
 

ZirconStorms

VX & VX Ace Scripts
Veteran
Joined
Dec 22, 2014
Messages
342
Reaction score
110
First Language
English
Primarily Uses
RMVXA
Anyway to use line breaks with bitmap.draw_text commands?
 

Users Who Are Viewing This Thread (Users: 0, Guests: 6)

Latest Threads

Latest Posts

Latest Profile Posts

The universe does not want me to do another letsplay it seems... I keep bumping into problem after problem... Oh well. Still have several days to sort them out.
I now have something new to learn. Lesson suggestions?
Finally with a new PC! Now I can do nice things both coding and gaming
nvidia release the IA paint to lsd landscape simulator
i just try , it very fun
"If the lion knew her own strength, hard were it for anyone to rule her". This would be my custom title if I had enough spaces for it. Coming off of personal pain, I'm glad I found the original quote I've tweaked.

Forum statistics

Threads
93,458
Messages
912,610
Members
122,988
Latest member
negajo
Top