Good day everyone,
Let me at first justify my post on this busy forum: I searched everywhere and tried to fix the problem myself, but, well, it didn't work. I am using free version of Construct 2, right now just testing the possibilities, and I have basic code experience - and that is what the questions is going to be about. I was able to implement so far all ideas I had in mind, and now I am trying to shorten my events amount and learn more advanced event handling.
So, long story short:
On game field there are n-number of substances. Picking two different substances creates a new potion. That potion moves automatically to the 2-container-inventory, and gets ready to be used (by a player).
A couple of rules:
1. There cannot be more than two potions in inventory.
2. Substances cannot be gathered if both inventory slots are taken.
3. If you already have substanceN, you cannot take another substanceN.
These all described above already works in the following event system. Now, I am trying to shorten my code and try learning/using advanced options Construct 2 has to offer.
Description of the code (.capx - I canot post URLs due to my low reputation, so please, just remove spaces in the following: http:// 1drv.ms /1OhN5iz ). It will lead to my cloud with access only to this file.
(First group - Dictionaries)
I used two dictionaries to store amount of potions and substances. Global variables were used before, and moving to a dictionary helped to decrease the amount of events roughly by 20.
(Second group - substanceGathering)
On collision with player substances get destroyed and are moved to the dictionary. System checks the total amount of potions in 2 container inventory (an array), and permits gathering if the amount is 2 or more.
(Third group - potionsBrewing)
System checks whether there is a possible combination of two substances, and immediately creates/brews a potion, removing two substances used.
(Fourth group - inventoryGetsPotions)
System checks whether there is a potion in the dictionary and moves it to the 2-container-inventory (an array), removing it from the dictionary. Here an IF-Else statement helps to move potion to an empty space.
Wuh, that is quite some read up here! So, the questions to users:
1. Second group - has a lot of similar code, is it possible to shorten it down to one? Would functions help out here?
2. Fourth group - I was thinking to use a loop here, to shorten the code, but I am not sure how to do it. I do can formulate it in a sentence, but just can't make the concept in Construct 2. So, should be a loop be like this:
1. System checks if any of PotionN Dictionary entries are equal to 1.
2. System moves that very same PotionN to the array, using same If/Else statement.
3. System sets that PotionN entry to 0.
3. If a second Player comes into the play, is there a way to optimize this whole code for it, using again, functions?
I am User Interface, User Experience designer, and games are my passion. I think you can see that I am not a great coder, but constant practicing should lead to a good output, I hope
I really appreciate your help and feedback on the code, thank you for your time!