[ACE] Skill Levels & Ruby Scripting

Joined
Jun 11, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
So I've searched around and can't find a clear answer to a few questions...

My goal at the moment is to add levels to the skills in the game. I've seen a few scripts that do this, but I want to make my own and am having a lot of trouble figuring out which things to call in Ruby.

So far I've gone to Script Editor, and copied Game_Actor to the materials section so I can alter it without messing up the original Game_Actor class.

My plan is two give each skill a level by having one array listing all the skills in the game, and another array listing the level an actor has in each of those skills. Then when I need to know a skills level, I look up the position X of the skill in the first array, and find it's level in the second array simply by looking at slot X.

For example:

def SkillsArrays   @Array1=[Fire,Ice,Thunder] #This would be replaced with an actual array of the skills, something I need to figure out how to do   @Array2=[2,13,3] #This would be an array of the levels an actor has in the skills. So Fire is lvl 2, Ice is lvl 13, Thunder is lvl 3.enddef LookUpSkillLevel(skill_id)   @Array2.at[@Array1.index{skill_id}]end^^From what I can understand, this *should* take skill_id, find it's index in Array1, then use that index number to return the level value from Array2

So assuming the above code is workable, my biggest stumbling block right now is how to make an array out of all the skills in RPGMaker.

I noticed this snippet in the Game_Actor code:
 (@skills | added_skills).sort.collect {|id| $data_skills[id] }

And from what I've read in Slip Into Ruby, this is creating an array of all the skills known to the actor and then getting data for the skills. Would using just

(@skills | added_skills).sort give me a sorted array of the character's skills? And if so, should I be concerned about the actor learning more skills later and having to add more to the skill-level array?

If my assumptions are correct (which I doubt), then I think the final code would look like this:

def SkillsArrays   @Array1 = (@skills | added_skills).sort   @Array2 = []   @Array1.size do #Takes the size of the array and then repeats the next line of code that many times. So if there's 100 skills, it repeats the next line 100 times. I hope.      @Array2.push(0) #Adds a 0 to Array 2, giving each skill a starting level of 0.   end   end#This *should* leave me with Array1 being filled with skill_id values, and Array2 being an array filled with as many slots as there are in Array1, and each slot is a 0.def LookUpSkillLevel(skill_id) #What I use when I want to find a skills level   @Array2.at[@Array1.index{skill_id}] #This should find the index of a given skill_id in Array1, then find the value for the skill by looking at that index in Array2.endDoes this seem like it should work, or am I missing something?

Edit: Forgot to fully title thread, sorry. Got distracted trying to get all the info in here >_>
 
Last edited by a moderator:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
31,358
Reaction score
7,672
First Language
German
Primarily Uses
RMMV
Please edit your post with "more reply options" to give it a good title
 

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
785
First Language
English
Primarily Uses
RMMV
Is most of that even necessary?

I think you could just do with a single array and 2-3 methods

Something like:

Code:
def init_skill_lvls  # just initialize an empty array somewhere  @array = []enddef skill_lvl(skill_id)  @array[skill_id] || 0 # if the array doesn't have the skill_id return 0 instead of nil enddef skill_lvlup(skill_id)  @array[skill_id] = 0 unless @array[skill_id] # initialize that skill lvl to 0 if it doesn't exist  # could also do @array[skill_id] ||= 0  @array[skill_id] += 1end
 
Joined
Jun 11, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
Is most of that even necessary?

I think you could just do with a single array and 2-3 methods

Something like:

def init_skill_lvls # just initialize an empty array somewhere @array = []enddef skill_lvl(skill_id) @array[skill_id] || 0 # if the array doesn't have the skill_id return 0 instead of nil enddef skill_lvlup(skill_id) @array[skill_id] = 0 unless @array[skill_id] # initialize that skill lvl to 0 if it doesn't exist # could also do @array[skill_id] ||= 0 @array[skill_id] += 1end
I'm still trying to learn Ruby and RPGMaker scripts, so probably a lot that's unneccessary >_> Thanks for the help, I got something sort-of-working after two hours, but it's a jumbled mess...

Let me see if I understand what you're showing me.

I understand initializing an empty array, so that parts clear.

def skill_lvl(skill_id)@array[skill_id] || 0 # if the array doesn't have the skill_id return 0 instead of nilend^Will this method do anything prior to being called? Or I should ask... is there anything in this array to begin with, and if not, how/when do I populate it with skill_id values?

I've also seen the "@variable || 0" before, but I don't think I understand the syntax. Does the || operator mean that it returns the first value (@array[skill_id]) unless it results in nil, in which case it goes to the second value (0)? Somewhere I learned that || was meant to be "or", but clearly Ruby treats it differently or I'm misunderstanding.

def skill_lvlup(skill_id)@array[skill_id] = 0 unless @array[skill_id] # initialize that skill lvl to 0 if it doesn't exist# could also do @array[skill_id] ||= 0@array[skill_id] += 1endSo this one I would call in a script using $game_party.leader.skill_lvlup(skill_id) or some other form of an actor.skill_lvlup(skill_id) here, correct?

Does the ||=0 mean "set the value equal to" 0 "unless the value exists"? That one I've wondered about too, and I think I'm understanding much better now.

One last question; is skill_id an integer that I can get by looking at RPGMaker's Database under the Skill section? (i.e. 001: Fire in the database would have a skill_id of 1, and 010: Heal would have a skill_id of 10) Or is it something else altogether? I've tried messing around with scripts to figure it out but I wound up getting confused.

Thanks a bunch for the help, I'm getting a much better understanding of both ruby and what to do in RPGMaker :)
 

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
785
First Language
English
Primarily Uses
RMMV
Will this method do anything prior to being called? Or I should ask... is there anything in this array to begin with, and if not, how/when do I populate it with skill_id values?

The array should be empty, unless you had already started lvling skills with the lvl up method.

|| is or in ruby, so the return value will be the array value at the skill_id index or 0. So if that array value was nil it'll return 0 instead of nil. So you did understand it correct, all its doing is trying to return the value that isn't false, and if they're both not false, return the first one.

So this one I would call in a script using $game_party.leader.skill_lvlup(skill_id) or some other form of an actor.skill_lvlup(skill_id) here, correct?

Yes, but it's probably better to call it through $game_actors[ACTOR_ID].skill_lvlup(skill_id)

Not to sure how to explain ||= but it's basically:

@array ||= []# same as:mad:array || @array = []Maybe someone else can help better explain it.

One last question; is skill_id an integer that I can get by looking at RPGMaker's Database under the Skill section?

Yes those numbers in the database are the skill id's.
 
Joined
Jun 11, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
Not to sure how to explain ||= but it's basically:mad:array ||= []# same as:mad:array || @array = []Maybe someone else can help better explain it.

One last question; is skill_id an integer that I can get by looking at RPGMaker's Database under the Skill section?

Yes those numbers in the database are the skill id's.
I think I understand teh ||= symbol now. In the code you gave, if array has no value, then return an empty array?

Thanks a bundle. Knowing the skill_ids will help a lot. Now I'm wondering how to fill the skill level array with actual values... Since it starts empty, does anything we have so far fill it in?

I'm wondering if the skill_lvlup(skill_id) method ends up inserting a value to an array when the skill isn't already in it. For example, I have an array [0,0,1], and I want to put something into the array index 5, which clearly doesn't exist in the array. Would the method put a NIL in the 3 and 4 indices and then slot a 0 into the 5 index, then increase the index to a 5? Visually:

def array_init@array=[0,1] #running array_init creates an array named @array with values [0,1]enddef arraystuff(x) #Then say I run arraystuff(5)@array[x]=0 unless @array[x] #This returns that @array(5)=NIL, so will it then change @array to become [0,1,NIL,NIL,NIL,0]?@array[x]+=1 #Assuming this became [0,1,NIL,NIL,NIL,0], it becomes [0,1,NIL,NIL,NIL,1]?endAssuming I've got everything correct so far, I need to initialize any skill levels the character starts with (presumably to 1). Would using the skills array that's default in RPGMaker's Game_Actor section give me the skill_ids of everything the character learns upon creation, or would that give me a different set of data?
 

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
785
First Language
English
Primarily Uses
RMMV
Yes thats how it will look. I don't remember what the skill array holds, so I printed it out and its an array filled with the skill objects. So if you want to get the id's from that array you can do:

skills.collect {|skill| skill.id } # make a new array filled with the skill id values(this is assuming you're inside Game_Actor)

How I tested it just incase you're not sure how:

Inside Game_Actor I just added a simple print to see how the skills array looks

Code:
  #--------------------------------------------------------------------------  # * Object Initialization  #--------------------------------------------------------------------------  def initialize(actor_id)    super()    setup(actor_id)    @last_skill = Game_BaseItem.new    p skills # First test    p "Ids:"    p skills.collect {|skill| skill.id } # 2nd Test with an array of id's  end 
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
Shakura: Just as a bit of additional information, your interpretation of how adding nonexistent indexes to an array works in Ruby is absolutely correct: if you have a 2-element array and set array[5] to a value, it'll insert nil into all the indexes in between to expand the array as needed.
 
Joined
Jun 11, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
Thanks again guys! I just spent another couple hours today figuring out how to initialize the known skills to 1...  It involved a lot of typos, rage, and google >_> Here's my final code, I typed some comments explaining each to make sure I understood, then went back and deleted them because that was a lot of comments >_> I found out talking myself through it was an easy way to tell if I knew what I was doing at all or if I was just playing guesswork... guesswork didn't work -_- Thankfully the code does :3
 

  def init_skill_levels    @skill_lvl_ary = [] #Makes a blank array to contain the levels of each skill.    @skills.each {|x| @skill_lvl_ary[x]=1}   end#^Creates a skill array, and sets each *known/learned* skill to level 1 upon actor creation. Other ways I could do this but I decided to put it here.  def skill_lvl(skill_id)    @skill_lvl_ary[skill_id] || 0   end#Returns a given skills value, needs the skills ID to look it up from the array.  def skill_lvlup(skill_id)    @skill_lvl_ary[skill_id] = 0 unless @array[skill_id]    @skill_lvl_ary[skill_id] += 1   end#Levels up a skill by 1. def skill_lvl_set (skill_id,i)    @skill_lvl_ary[skill_id]=i  end#Sets a skills value to i, I plan on making an RPG with mechanics similar to E.V.O. Quest for Eden if anyone's played that.#AKA You're an animal and can "evolve" (See: Fantasy mutation!) different parts with different levels in each skill, so#I need to be able to directly set them up and down.Thanks again for all the help :D I feel really good having learned so much (... so little compared to all of RUBY  ;_; )
 

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
785
First Language
English
Primarily Uses
RMMV
I think your main problem would be this:

@skills.each {|x| @skill_lvl_ary[x]=1} A bit lazy to open up vxa and test, but @skills is an array holding the skill objects. So when you're doing .each{|x| stuff here }, x is equal to the skill object, not an integer relating to the skill id.

So instead you should try doing:

Code:
@skills.each {|x| @skill_lvl_ary[x.id] = 1 }
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
Actually, @skills contains the skill ids. The actual objects are retrieved whenever needed by the "skills" method.


/edit: That goes for every game object stored in $data_... structures except actors, which are cached.
 
Last edited by a moderator:

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
2,604
Reaction score
1,959
First Language
English
Primarily Uses
RMMV
On a related note, EVO: Search for Eden is an awesome game.
 
Joined
Jun 11, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
New question/next step: How and/or where do I add parameters? I'm thinking about an alternative to XP and a few other things to throw in attribute-wise. I'm hoping I can get going just by knowing which default scripts to poke in, but I haven't quite found out where or how to code in more parameters for an actor... I don't want a full script write-up, because I want to do and learn myself, but I can't seem to figure out where to start, even after searching a bunch.
 

Quxios

Veteran
Veteran
Joined
Jan 8, 2014
Messages
1,055
Reaction score
785
First Language
English
Primarily Uses
RMMV
Oh right I got .skills() and @skills mixed up lol.

For parameters you would create the new variables and methods inside Game_BattlerBase. You could probably just do something as simple as an attr_accessor and then initializing the variable to the what ever default value.
 
Joined
Jun 11, 2015
Messages
18
Reaction score
1
First Language
English
Primarily Uses
Now I'm looking at scene_equip and trying to figure out how to remove the box and commands for "Equip" "Clear" "Optimize". From poking around I found out both how to move the window around and get rid of the words & commands.... but not to resize the window so I can effectively be rid of it while still allowing for the "cancel" to work (so you can back out of the window rather than having the game take no inputs what so ever). Any pointers on where to get more info for dealing with the default windows codes?
*Edit* Just figured it out by adding in @command_window.height = 0. I could still use some tutorials or links since I'll be playing around with this more >_>
 
Last edited by a moderator:

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

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,015
Members
137,563
Latest member
MinyakaAeon
Top