Within public class, making it available globally within the entire script.
a. Identifying the number of steps as an integer and in increments of one.
b. Using vector math, identifying the location of Home and Player.
The start function is calling the Welcome Message.
The welcome message is comprised only of print statements. Since the problem is that the game continues after it completes, then this area cannot be the problem.
The update is called every frame which is essentially every time the player moves one step.
a. If the input is down, up, left, or right arrow respectively then calculate the current player location using the player location, plus increment in whichever direction the player moved. The variables applied with vector math gives a new value which is printed to the console.
The PrintUpdateandContinue function is called every frame, after the player location is worked out.
a. When the game is over we have a print statement which is designed to print to the console āGame Overā. This must be where the problem is because it simply is printing the words to the console and nothing to end the program.
So, we need something to prevent the user the ability to continue the game. This is different than terminating the game with the ESC key, which can be added later unless using iOS. Time to look through Unity Docsā¦
I found a reference at the following url:
However, the solution seems to be beyond the scope of our project so I will post this and have a look at the answer in the course video. I donāt currently understand what is needed to resolve the problem.
Update: After watching the course video, I see that the solution is very easy. LOL.
ā¦and all the while the Duck Sensei sat there patiently, listening to you, hearing your words and thinking, āSoon, he will watch the course video and realise how very easy the solution isā¦ā
LOL, I hear ya. It was painful for me to do it that way rather than just looking ahead. But, I played the game and actually glad that I did because I discovered a few things in Unity Docs, and learned how to write a short script to close the game using the ESC key.
hehe, I did suggest it a little while ago @sampattuzzi, itās under the branding topic in the moderators forum Think Ben had some concerns regarding shipping⦠would be kind of unique though
Ok, just paused the video for this challenge and had myself a think.
The Update function is polling the arrow keys every frame, regardless of the game state (player has reached home or player has not yet reached home)
So far, weāve learned about conditions and booleans
We need to figure out a way to stop listening to the keys once the goal has been reached and exit that state either by calling a āblankā method, or āstopping the gameā
Figure out how/where to set a condition when the player has not yet reached home. There is a gameOver boolean in the method called by each of the Update conditions, but I donāt like that this boolean is being declared in this method. Not sure if it should be declared at the top-level or just set another one.
So, after a few minutes of tinkering, this is what I came up with:
Initialized a new boolean gameWin = false up at the root so it is accessible by all functions below
Before polling the keys in Update, I set the condition to check if (gameWin == false) and nested all the arrow keys conditions within this boolean check. As long as gameWin has a value of false, then check the keys during the Update method. I didnāt put any code to execute when the condition of this boolean evaluates to true
In the PrintPosition function, if the gameOver condition evaluates to true, I added the gameWin = true expression after the print statement so that on the next updated frame, the keys will no longer be active.
Hope that made sense, and hopefully Sam did something similar
Unfortunately we arenāt actually in any loop. We could delete the game object as a way of not getting called and essentially ābreakingā out of the loop.
@sampattuzzi I can translate, read and āspeakā code, but I have never been a āproper programmerā. Iāve been taking all of Benās Unity courses to get me some C# scripting experience. I canāt program my way out of a paper bag; I am still learning, and it is usually the syntax of the (any) language that trips me up.
A better example of my coding level/experience would be if I were in Germany speaking with someone who only spoke German. I could understand most of what is being said, but, besides being able to say āHelloā, āGood Morningā, āpleaseā, āthank youā and the basics, I would have difficulty having a full conversation in German without a translator/help. I simply need more practice and repetition and exposure to the C# language.