Using the Enemy Action List

Hey all,

This is my first post here, so first of all heya!

I've been browsing the web quite a bit but I couldn't find an answer to my problem. A lot of my google searches led me here so I thought I would make an account and ask my question.

I have been trying to use the content from the Enemy Action List to build an AI for my custom battle system. Each enemy has a multitude of actions that are returned in this form.
unknown.png


If the enemy had only one skill I could use commands like .condition_type or .skill_id to retrieve the data in here. However each enemy has more than one action, and I do not know how to access the data
I have tried using a variety of array index techniques like array[0][2], etc but none of them seem to work.

I want to build my own AI that uses skills based on the conditions set in the editor, but it will be impossible if I can't retrieve the data in there.

Please help me :ewat:
Hey there,

You are correct about the array indexes, normally enemy actions are stored in an array, so you should be able to access them like this:

array = $data_enemies[1].actions
array[0].skill_id # Skill ID of the first action
array[1].skill_id # Skill ID of the second action


For whatever reason your printout shows an Enumerator instead of an Array, so you might have accidently used something like
array = $data_enemies[1].actions.select
instead.

(An Enumerator does not support random access like array indexes, and usually can only be used to traverse elements of a set once and is then discarded)


Hope this helps in any way; you can always post these kinds of questions in the Learning Ruby and RGSS section too.
Hey,

I set the array to data_enemy.actions instead of data_enemy_action_select as you suggested and I can use it as an array now!

I am fiddling with ruby although I don't really fully understand what I'm doing lol I will definitely post on that topic next time.

Thanks a lot.
On second glance:
If you use the select method with a code block you won't get an Enumerator back, but a reduced array of elements that passed the condition, which might have been what you were trying to do:
Code:
numbers = [1, 2, 3, 4, 5]

even_numbers = numbers.select { |entry|
  entry % 2 == 0
}

p numbers # [1, 2, 3, 4, 5]
p even_numbers # [2, 4]

Anyways, glad it helped. :]
Thanks for the more detailed answer, just trying to pass the content of the skill actions in my own functions because I want it to fit the math behind my game better!
Your first answer was perfect <3

Original thread: https://forums.rpgmakerweb.com/threads/using-the-enemy-action-list.133304/