Day 7 - Progress

Today I'll be finishing up the challenge system and implement 1 - 3 challenges. 

Challenge System
I started by working on the challenge system again. Yesterday I created the instantiation of the challenge, but when I instantiated them they all ran there code. I've kinda been breaking my brain over this, because there are so many ways to solve this, but I wanted to keep my code on this short. The best way (I could think of) was to disable the GameObjects directly after instantiation. Now all challenge objects (along with their components) were disabled. The next step was to manually enable the gameobject I needed, when needed. Again, many ways to do this, but I found a solution that perfectly fit my purpose. I already kept track of the currentChallenge in the ChallengeManager. To enable the challenge gameobject that goes along with the current challenge, I used this integer to search for the right object in the list (see image below).














At the same time, I also worked on changing the Challenge States, as you can see in the image above.. For testing purposes I check for key input to trigger the states to change. The most important were the Start and End state. The other states will be modified later.

For now I leave the system as it is and move on to the challenge implementation, which also goes hand in hand with the system itself. Once I make progress on the challenge implementation I can get back to the challenge system.

Challenge Implementation
Once more, I created a new test scene. I do this to make sure I don't mess up anything that's already in the test scene. One of the most important features for the challenge implementation is programming the actual action, which in this case is a drag and drop system. After watching several tutorials and reading API, documentation and posts on this subject, I finally found a great tutorial series from quill18creates. I followed the instructions step by step to create a drag and drop system for my challenges. The system allows me to drag an item (OptionCard) into one of the DropZones and the DropZone will become its new parent. To see if I could bind their values, so I can later check the answers in the test run, I created a enum with the variables ANSWER1 - ANSWER5. For testing purposes the optioncards may now only be dropped in the DropZone with the same value. This will later be used for the answer check in the test run. 


In the image above you can see the drag and drop system in action. This screenshot shows me dragging the black figure onto one of the DropZones above. If I let it go above a DropZone it automatically snaps onto its new parent, else it will snap back to the row it came from.

Eventhough I'd rather optimize the value check, I had to settle with this simplified (semi-hard-coding) solution, due to time and the amount of work I still have in store. Maybe, if there's time, I will optimize this in the polishing stage. 

Scene Set Up
Like I explained before I've been working in multiple test scenes. But now it's time to put everything together in my Monitor Scene. Once I've got everything for the monitor view in one scene I get a clear view on what I need to do next.

It's really starting to come together! 

Challenge System & Implementation
After merging my scenes and reassigning values, I got back to the challenge system and implementation. Most of the challenge functions where reacting to key input, for testing purposes. But now I'd actually assign conditions for these functions. I've created the start, end, game over functions and also the test run.

Now, the test run was quite complicated. When the test run is triggered it needs to check if the enum value of the DropZone is equal to the enum value of the OptionCard. The first step was already made when I created the code to make the cards drop only in the zone of the same value. I'm not going to keep that in ofcourse, that would take away the whole purpose of the challenge. But the check was already there and it worked! So I struggled for hours to get the check in some kind of for or foreach loop that would check for all of the dropzones if the card value was equal to its own. I tried many different approaches, only to get stuck again. So, how did I solve this? It's so easy, I just created a public bool for the draggable items that shows if the rightanswer is true or false. Then in my OnDrop function I re-used the check statement, but moved the transform outside the check, so the card always moves to its new parent. Then I added a score system for the right answers. If the answer is right it increases by 1, if not it decreases by 1. At first this wasn't working properly, because if I moved the card between the DropZones it would modify the score each time, which resulted ending up with impossible scores, like -2. So what I did was adding an extra statement to check wether the draggable item had its bool set to true or false, and only modify the score (and bool) if the bool was false and needed to be true, and the other way around. (see image below)
























I lost so much time on this issue and then the solution turned out ot be so simple! I was defenitely overthinking it!

Comments