Hello community!
It appears I have run into yet another roadblock (already) (yay :headshake: ). Let me explain what I am trying to do first:
At any point in the game, the player can control (1..5) parties and can cycle through them by the pressing of a key. I am struggling with a particular aspect of the cycling method. I can easily put all my party ids in an array, but to be able to cycle, I must know which party the player actually controls (an information I am also able to find). With that information, I could cycle to the previous or the next party in the array (or go back to the first or last index if need be).
So I needed a method that would return the index of an element in an array. Thanks to the internets, I have found the array#index method. However, for some reason, it won't work in RPG Maker! Let me show you an exemple:
# Let's say I have these:all_parties_array = [1,2,3,4,5]current_party = 1# When I use the index method, unexpected information is returned, as though I hadn't supplied the method with a valid argument/object😛rint all_parties_array.index(current_party)=> #<Enumerator:0x5a17700># Substituting the variable for an integer yields the same kind of result. But when I type the exact same code in my computer's shell, however, it works like a charm! Has array#index been rewritten in RGSS3 or what? Does any of you have an idea of what I might be doing wrong or of a work around?
Thanks!
EDIT:
If you have any insight on why I encountered this issue, feel free to pitch in, but I just ended up defining a new method to mimic the array#index functionnality. So until then, I guess the thread could be closed. Sorry for such a useless topic. :blink:
If anyone is interested:
It appears I have run into yet another roadblock (already) (yay :headshake: ). Let me explain what I am trying to do first:
At any point in the game, the player can control (1..5) parties and can cycle through them by the pressing of a key. I am struggling with a particular aspect of the cycling method. I can easily put all my party ids in an array, but to be able to cycle, I must know which party the player actually controls (an information I am also able to find). With that information, I could cycle to the previous or the next party in the array (or go back to the first or last index if need be).
So I needed a method that would return the index of an element in an array. Thanks to the internets, I have found the array#index method. However, for some reason, it won't work in RPG Maker! Let me show you an exemple:
# Let's say I have these:all_parties_array = [1,2,3,4,5]current_party = 1# When I use the index method, unexpected information is returned, as though I hadn't supplied the method with a valid argument/object😛rint all_parties_array.index(current_party)=> #<Enumerator:0x5a17700># Substituting the variable for an integer yields the same kind of result. But when I type the exact same code in my computer's shell, however, it works like a charm! Has array#index been rewritten in RGSS3 or what? Does any of you have an idea of what I might be doing wrong or of a work around?
Thanks!
EDIT:
If you have any insight on why I encountered this issue, feel free to pitch in, but I just ended up defining a new method to mimic the array#index functionnality. So until then, I guess the thread could be closed. Sorry for such a useless topic. :blink:
If anyone is interested:
Code:
def find_array_index(array, object) i = 0 array.each do |val| if val == object return i else i = i + 1 end endend