07-30-2015, 04:50 AM
I was just posed a question. Can you sort data from RPGMaker XP variables and retrieve the value quickly? Oh, sure, you can use the sort method in 'Array', but has anyone thought about how to put it into an event and return that final product?
Well, I did it in about 5 or so minutes.
In an event, you can use the SCRIPT call feature, so you can do a little Ruby coding... and this is what I came up with:
Yes, I named the array 'arr'. I was in a Captain Jack Sparrow mood.
In this, you can get the data in RMXP variables 11-14, and it grabs the last one of the array (remember, it's an index, so it is index value 3). After that, it shoves the largest value into RMXP variable 6 as a result.
I later returned with some additional code (not shown above). The same event also looks to see WHICH variable had the largest value (or first one it encounters with that value), and returns that too.
For those wanting to see it work in a demo, just crank out a fresh one and put the below 'attached' Data folder in its place.
They also said the code had a problem with Drago's Core script, so this includes that script to show no conflict occurs... at no additional charge.
Data.zip (Size: 188.97 KB / Downloads: 4)
Well, I did it in about 5 or so minutes.
In an event, you can use the SCRIPT call feature, so you can do a little Ruby coding... and this is what I came up with:
Code:
arr = []
for i in 11..14
arr.push($game_variables[i])
end
arr.sort!
p arr
p arr[3] # 4th item
$game_variables[6] = arr[3]
In this, you can get the data in RMXP variables 11-14, and it grabs the last one of the array (remember, it's an index, so it is index value 3). After that, it shoves the largest value into RMXP variable 6 as a result.
I later returned with some additional code (not shown above). The same event also looks to see WHICH variable had the largest value (or first one it encounters with that value), and returns that too.
For those wanting to see it work in a demo, just crank out a fresh one and put the below 'attached' Data folder in its place.
They also said the code had a problem with Drago's Core script, so this includes that script to show no conflict occurs... at no additional charge.
Data.zip (Size: 188.97 KB / Downloads: 4)