Hello, i have an array in this way:
data = [[3,10],[7,20],[15,29]]
The first term is the id player and the second is the quantity of money that he owns.
How can i find, the array position of the id player 7 for example (in this case position 1), considering that i dont know how much money he owns (variable)?
data.index { |value| value[0] == 7 }
Will return nil if there is no element with an id of 7.
What would be the best way to create an array containing the averages of all party member stats?
The long way would be something like this:
averages = [0,0,0,0,0,0,0,0]$game_party.all_members.each do |actor| for i in 0...7 averages += $data_classes[actor.class_id].params endendfor i in 0...7 averages /= $game_party.all_members.sizeend
The above probably wouldn't work correctly and would need to be tweaked a bit. But I need the stats without any modifications from weapons or armor.
Is that for Ace or another Maker? I'm asking because I'm not familiar with accessing the actor's current parameters without having to pass their level to the table as well.
Anyway, this is a (terse, relatively-hard-to-understand) version of what you have above that should work with Ace. Of course, I'm... writing this from a computer that doesn't actually have Ace installed on it, so this is completely untested and has a high probability of exploding as a result of that. Take it with about two pounds of salt.
avg = Array.new(7) { 0 }$game_party.all_members.each do |a| avg.size.times { |i| avg += $data_classes[a.class_id].params[i, a.level] }endavg.map! { |e| e / $game_party.all_members.size.to_f }This will give you accurate averages though, unlike your version above (which will perform the division without floating point values, which, of course, rounds the outcome).And just so you know, I don't think that this would perform any better than the version that you've already posted.
"Probably wouldn't work"?
Can you think up some tests to either find bugs or increase your confidence?
It can help to extract the core problem. You know, create a related data structure containing some test data you have crafted. Then calculate in hand what you expect the result to be.
Now you are ready to look into the algorithm where you can obtain fast response. It is of course not all-encompassing, but it usually pretty helpful.
*hugs*
Edit: Didn't noticed you Solistra =o
For the record, what Zeriab just described is basically how I wrote the little bit of Ruby that I just did. From my memory of how Ace uses actors, the party, and classes, the code that I wrote works -- but I built mock classes from memory, so again, take what I wrote with at least two pounds of salt.
I want to know more about note-tags. Can someone dearly explain to me how notetags work? I want to know the best approach on how to actually make and access a notetag, the conditions that you can run to it, or how is it readily available working once you start your game.
Specifically something like this for example:
On the enemies tab, I placed a notetag <type: poisonous>
so the condition I want to happen is that: when an enemy on the database is tagged with <type: poisonous> then whenever you enter the battle, (I don't know if its on BattleManager or Scene_Battle to access it), a chance that that monster's attack is poisonous, say for example 35% chance. I asked this since I really want to learn how it works, and placing state poison on each monster's attack is a bit of pain.
An advanced thank you for the person who would answer this.
Note tags are used in whatever way the scripter wants to use them. You write the script to suit your own requirements. Take a look at a few that use them already to see how they're read, and see if you can adjust it to do what you want.
If you can't do it yourself, then you probably really should be posting a new thread in Script Requests, as you're asking someone to make a system for you (or to help you make it), which means it's deserving of its own thread 😉
#===============================================================================class RPG::BaseItem#=============================================================================== # Base Item is the superclass of ALL database items ! def your_notetag_checking_method if self.note =~ /<your_note🙁.*)>/i # (.*) "catches" the information in the notetag eg <your_note: 1> it would get # the info "1" return $1.to_i # returns the first "caught" information, ie "1". else return 0 # default data to return end end end # You can then access this notetag anywhere, providing you first access the database# item, eg. actors, enemies, classes, skills...# Here is an example of how to check the note when the damage process is being# executed.. #===============================================================================class Game_Battler < Game_BattlerBase#=============================================================================== alias :random_ALIAS_name :execute_damage def execute_damage(user) p "NOTETAG WAS READ FOR #{self}" if self.note_check != 0 random_ALIAS_name(user) # Run original method endend#===============================================================================class Game_Actor < Game_Battler#=============================================================================== def note_check # Gets database notetag return actor.your_notetag_checking_method endend#===============================================================================class Game_Enemy < Game_Battler#=============================================================================== def note_check # Gets database notetag return enemy.your_notetag_checking_method endendput that into your script editor, give the notetag <your_note: 1> to an actor or enemy and deal damage, you will get info displayed in the console window showing that the notetag has been read.
then just change the methods to suit your needs.
There are many many ways of reading / using notetags , yout should try out a few until you are happy with a certain way of doing it.
Personally i pre-load the notetags using methods very similar to yanfly's.
But thats just personal preference...
Do you know why I admire you, @Dekita? You can explain everything by just putting on the codes!
I really appreciate this and I am learning the other syntax I have to, and I just ran on the notes thing and I wanted to know how to make them happen.
I was stressed on getting references from made scripts with notetags because it is already complex that they had this split function. I understand gsub but splitting and other things, not yet ATM.
Again, thank you Dekita 😀
Thanks both to Tsukihime and Dekita. Now reading <3
That would be because whatever you define in split is removed upon splitting, as it's considered simply a divider. Splitting it with /./ as an argument will *always* return an empty list. As an example:
a = "1,2,3,4"p a.split(/,/)
Would return ["1", "2", "3", "4"]. If I did this:
a = "1, 2, 3, 4"p a.split(/,/)
I would get ["1", " 2", " 3", " 4"]
Your second example, splitting with //, tells it to split when there is no character - essentially after every character in the string.