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

Oops! My bad! I was super tired yesterday X3
I am LOLing so damn hard right now.

Anyway, got a quick one.... (not really but still...)

Does anyone have a good - EFFICIENT - method for checking what the radius from a specific point is?

For example..

self.x.between?(1, 5)Would check the x co-ordinates.

I am looking for something that will create a circular radius of [x] pixels from [x] position and then return an array (or whatever) of the radius circumference.

Anyone?
That's a bit difficult, because the array could contain hundreds of coordinates.


Are you just wanting to check what the distance is in pixels between two objects?


This comes from Game_Character's jump method:


distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round


and is the standard formula for calculating a distance between two points. That's about the best I can come up with. If you actually want all the points along the circumference, then you'd be looking for a formula to plot a circle. And it wouldn't be efficient.
Distance of any point P from a circle of center C is:

d = sqrt( (P.x - C.x)**2 + (P.y - C.y)**2 )

The formula for a point on the circumference of a circle of center C and radius R is:

x = C.x + cos(α) * R

y = C.y + sin(α) * R

for a given angle α.

You can test whether P(x,y) is inside a circle by testing whether the distance between P and C is greater than the radius.

What are you actually trying to do with it? Returning an array of points sounds like the wrong thing to do.
Would this do?

Code:
def get_around_coordinates(px, py, radius)  xs = (px - radius..px + radius).to_a  ys = (py - radius..py + radius).to_a  xs.product(ys)end# Then, to see if a given [x,y] exists within this radius, do:get_around_coordinates(5,5,3).include?([8,6]) => trueget_around_coordinates(5,5,3).include?([8,9]) => false
Those are much better than I was anticipating. Its times like this I wish I understood the mathematics side of scripting more :/

Also, I realized after typing it that an array would be highly inefficient ^_^

Anyway, what I am trying to achieve is basically this...

- Pixel A is created (this pixel can move)

- Pixel B is created (then held in place)

- Pixel A is then checked to see if it is within a certain radius of Pixel B. This should include horizontal / diagonal / vertical directions.

- A true / false value is returned.

From the looks of it, Galenmereths suggestion seems like its about what I need. I will give that a test in a little while 🙂
I noticed now that you wanted a circular grid, so I modified the code for that. This still creates an array, however:

def get_around_coordinates(px, py, radius) result = [] (-radius..radius).each do |x| (-radius..radius).each do |y| result << [x+px,y+py] if Math.sqrt(x**2 + y**2).round <= radius end end return resultendIf all you need is to simply check if a given point is within a certain radius of another given point, then Kaelan's solutions i the way to go. In code, it could be:

def point_a_within_radius_of_point_b?(point_a = [], radius = 0, point_b = [])  ax = point_a[0]; ay = point_a[1]; bx = point_b[0]; by = point_b[1]  distance = Math.sqrt( (ax - bx)**2 + (ay - by)**2 )  return distance <= radiusend# point_a_within_radius_of_point_b?([250,250], 300, [500,250]) => true# point_a_within_radius_of_point_b?([250,250], 240, [500,250]) => false

Hope this is readable; the parameters point_a and point_b are both expected to be arrays. You could use the arrays directly in the formula, but for readability's sake I converted them to ax, ay, bx, and by.
That is exactly what I was needing. Thanks very much to you both 😀
Which part of my script is broken?
http://i.imgur.com/pDSZO4V.png
My current error is: Unexpected '=', expecting $end

My goal is to have a "common Event" that will take 5% of my elemental_rate from one element to another

i.e. Fire resistance from 50% to 55% and Ice resistance from 150% to 145%

the 'Actor' 'Change Parameters' looks like a much cleaner process, but it only lists 8 parameters. I can get simmilar functionality by creating a new state (40 new states actually) and have been able to test this by seting

$game_actors[1].element_rate(3)

to a variable then getting a NPC to tell me in a speachbubble. Writing a script was my last resort but I cant find any other way to overwrite a players elemental_rate.
@raskalnickoff

Please open a new thread in future to discuss problems with specific scripts /scripts you are developing or event procedures such as this one.

The main problem with what you are trying to do is the fact that you cannot change the values of an actors element rate without external scripts.

HERE is a script that allows for attack / defensive element rates.  There will be more out there somewhere ^_^
Thanks Dekita, I was expecting to have made a simple error, with a simple fix. Your script seem to replace the element_rate variable rather than change it. I'll keep working on it.
When doing Euclidean distance checking if you don't actually need the distance, but just have to check if it's less than another value avoid this structure.

Math.sqrt(x**2 + y**2).round <= radius
Instead go one step further and use the following principle:

x**2 + y**2 <= radius**2
*hugs*

 - Zeriab
That line of code is just...

Beautiful...

Just beautiful...

If it was a woman, I would ask it out ^_^
Hey there,

I am trying to work with Yanfly's Gab Window. So far I've had success, but there is one thing I just can't seem to accomplish.

I want to have an event that will gab if you get close to it. The proximity part works, but I would like the gab(text, character_name, character_index) to reference the Event's current Graphic. This would allow for easy copy and paste of the event for different NPCs throughout the game to call out to you as you approach, with minimal changes to each event.

My issue is that I have had no success trying to figure out how to reference the instance variable (character_name) and (character_index) inside the gab function. Is it possible?

Any help would be much appreciated.
Edit: Tested, and this works just like you want it to 🙂

Code:
event = $game_map.events[self.event_id]gab("your text", event.character_name, event.character_index)
Edit: Tested, and this works just like you want it to 🙂

event = $game_map.events[self.event_id]gab("your text", event.character_name, event.character_index)
Awesome! Worked perfectly. Thanks so much for your quick response.  👍   😉
Hi everyone I have a question about item, how can we assign a value to an item, I mean like this :

My party have 50 potion, then I want to make it 30, I know there's an event command that change item and decreasing it, but let's say I don't know that I had 50 potions, then how can I make it become 30 If don't know the amount of my previous potion in inventory?
I know we can do it from control variable too, but I wonder if it can be done from script, because I'm the type that don't very like using variables for a thing like this(because it spend out many variables if I make a lot problem like above). I figured there is this method in Game_Party which give the value of specific item when called : item_number(item). Just to make sure, I tried to call it like this from event command: p $game_party.item_number($data_items[1]) and yes it gives me the value of my potion in inventory, however..

I can't assign a value through this method, I tried it $game_party.item_number($data_items[1]) = 30, it throw me an error. I hope my explanation is not to confusing, and sorry for this silly question. Thanks everyone..
Honestly, I would just use Control Variables to figure out how many the party had, then I'd do a conditional branch to see if there were more than 30, and if so, subtract 30 from the variable, then do a Change Items to remove whatever's in the variable.


$game_party.item_number() = 30 won't work because item_number is a method to TELL you how many items there are (in fact, that's exactly what Control Variables uses), not a method to let you SET the number of items. You still have to use the lose_item method to change the number.


If you want to do it without variables, I'd say something like this might work:

Code:
$game_party.lose_item($data_items[1], [0, $game_party.item_number($data_items[1]) - 30].max)
Obviously, you only want to reduce the number to 30 if you HAVE more than 30 to start off with.
$game_party.lose_item($data_items[1], [0, $game_party.item_number($data_items[1]) - 30].max)

Oh wow this works nice, thanks shaz I appreciate it 🙂
I'm using Yanfly's Ace Message System. I want a special text to look like it's on a computer screen or something. I can do almost all of what I want with this script, except I would like to not have the default windowskin showing just for this message. Is there a way to temporarily disable it? (And sorry if I'm missing something obvious as usual, I did read through the script several times to try to make sure I wasn't missing something. But I probably am anyway.)

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