Hello,
I must admit that i've been running away from arrays for some time, but there comes a time when you simply can't do your thing without them. It came for me and i need your help to finally overcome one of the last obstacles in, well, some basic Playmaker functions (after that it's time for enums
).
As i said, it is simple but includes using arrays (i have been using them for some VERY basic stuff, nothing more).
Here's a simplified example:- There are three weapons in the game, let's call them Sword, Axe and Spear.
- Every weapon has three upgrade levels which are basically separate objects. So we have Sword1, Sword2, Sword3, Axe1, Axe2, Axe3, Spear1, Spear2, Spear3.
- Player can only hold two weapons, and use one weapon at a time (let's call it currently active weapon).
- When player holds Sword and Axe and pickups Spear, currently used weapon is replaced by Spear.
- When player holds Sword1 and Axe1 and pickups Sword1, Sword1 is upgraded to Sword2.
How i think it should be done:I have weapon objects themselves. They spawn on the player and do their thing (fire, deal damage...).
I have pickup objects which are basically empty objects with sprite renderer and collider.
Case 1:Player is equipped with Axe1 and Sword1, they are added to the
Weapons Equipped array - that's simple and i know how to do it.
Player stops on Sword1 pickup and clicks the button to pick it up.
Weapons Equipped array is be checked if it contains Sword1, Sword2 or Sword3. If it contains any of those three, Sword1 weapon object will be destroyed, removed from Weapons Equipped array, Sword2 weapon object will be created on player and added to Weapons Equipped array.
Pickup object will be destroyed.
Case 2:Player is equipped with Axe1 and Sword1, they are added to the
Weapons Equipped array.
Player stops on Spear1 pickup and clicks the button to pick it up.
Array is checked if it contains Spear1, Spear2 or Spear3. There are no such objects in the array, so the currently active weapon object (Sword1 or Axe1) is removed from array and destroyed. Spear1 weapon object will be created on player and added to Weapons Equipped array.
Pickup object will be destroyed.
I tried using the Arraymaker, and i suppose i should use Array Get Next to loop through all the array items, but i don't know how to use it. Ok, i can set it to loop through all of them, and then what? How do i compare the pickup object with all the array items? What does the result represent?
Ok, so there's Array Contains action, but the only way i can think of using it is like this:
- I pick up Sword1 pickup object
- I run Array Contains action and check if the array contains Sword1. If it doesn't the next state which checks is the array contains Sword2 is called, and so on.
Of course, the game is a bit more complicated than the example so it would take a few more events (which means more frames) to check for all weapon objects so i think this is not the right approach and can be done a lot simpler. I watched the Arraymaker GetNext tutorial by RezRezRez, but i don't quite get it, i'm more of a reading than watching guy.