Checkinjg for higest four variables among eight

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
I'm trying to check what the four higest variables are among eight for an event. Is there a script call for that, or do i need to use 63 conditinal branches? or do i need to add all the other variables together, and then multiply the variable checked by 7?
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
1,076
Reaction score
856
First Language
English
Primarily Uses
RMMV
@Oddball Do you need to know what variable each value is in, or do you only want the four highest numbers?
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
Four highest out of eight variables

Edit: Actually, i think to avoid tie errors, it should probably check the lowest out of the four, and return vaild whichever variables are equal to or higher than it. Then it can turn on the four events that are needed out of the eight possible
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
1,076
Reaction score
856
First Language
English
Primarily Uses
RMMV
@Oddball Well, the following scriplet will return the four highest numbers out of the eight variables :

Code:
# 'v_id' is the start point; the ID of the first of eight variables
# 's_id' is the ID of the variable where you would like to save the four highest numbers

data = $game_variables.instance_variable_get(:@data)
data = data.slice(v_id, 8).sort {|x,y| -(x <=> y)}.take(4)
$game_variables[s_id] = data



# The data is saved as an array with four entries
# You can then access each of the highest numbers ...
$game_variables[s_id][n_id]

# Examples :
$game_variables[68][0]
$game_variables[68][1]
$game_variables[68][2]
$game_variables[68][3]
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
So this will save the four highest out of eight?
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
1,076
Reaction score
856
First Language
English
Primarily Uses
RMMV
@Oddball Yeap. Now, I am making the assumption that the eight variables are all in a row. The code above will start at the first variable and copy the next seven variables into a temporary array which is then sorted by highest to lowest. The top four are then stored into another variable.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
5,599
Reaction score
6,552
First Language
Indonesian
Primarily Uses
RMVXA
I'm not sure how Ossra's script work, but here is my version.
Code:
id = [1,2,3,4,5,6,7,8] # <-- variable ID you want to check
val = id.collect {|v| $game_variables[v]}.sort {|a,b| b <=> a}[0..3] # take index 0 up to 3
$game_variables[s_id] = val
Works exactly like Ossra's version but you don't need to specify start point, just throw the variable id.
 

Oddball

Veteran
Veteran
Joined
Sep 4, 2014
Messages
1,923
Reaction score
535
First Language
English
Primarily Uses
N/A
Going to use TheoAllen's scriptlet. Will give credit once game is release. thank you!
 

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

Latest Threads

Latest Profile Posts

Our latest feature is an interview with... me?!

People4_2 (Capelet off and on) added!

Just beat the last of us 2 last night and starting jedi: fallen order right now, both use unreal engine & when I say i knew 80% of jedi's buttons right away because they were the same buttons as TLOU2 its ridiculous, even the same narrow hallway crawl and barely-made-it jump they do. Unreal Engine is just big budget RPG Maker the way they make games nearly identical at its core lol.
Can someone recommend some fun story-heavy RPGs to me? Coming up with good gameplay is a nightmare! I was thinking of making some gameplay platforming-based, but that doesn't work well in RPG form*. I also was thinking of removing battles, but that would be too much like OneShot. I don't even know how to make good puzzles!
one bad plugin combo later and one of my followers is moonwalking off the screen on his own... I didn't even more yet on the new map lol.

Forum statistics

Threads
106,035
Messages
1,018,454
Members
137,821
Latest member
Capterson
Top