Skip to content

Commit

Permalink
16 For Loops
Browse files Browse the repository at this point in the history
  • Loading branch information
rickdavidson committed Jun 29, 2018
1 parent 63c9235 commit de73de8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
15 changes: 14 additions & 1 deletion README.md
Expand Up @@ -225,4 +225,17 @@ Deeper understanding of the concepts covered thus far in this section.

**After watching (learning outcomes)…**

Create a WebGL build and publish online.
Create a WebGL build and publish online.


### 16 For Loops ###

**In this video (objectives)…**

1. Find a bug in our game which causes our standalone PC build to break.
2. Figure out why the game is breaking because of the bug.
3. Use a for loop to change our input mechanism and stop ArrayOutOfIndex errors.

**After watching (learning outcomes)…**

Fix our ArrayOutOfIndex error using a for loop for player input.
15 changes: 5 additions & 10 deletions Text101/Assets/Scripts/AdventureGame.cs
Expand Up @@ -28,17 +28,12 @@ void Update()
private void ManageState()
{
var nextStates = state.GetNextStates();
if(Input.GetKeyDown(KeyCode.Alpha1))
for (int index = 0; index < nextStates.Length; index++)
{
state = nextStates[0];
}
else if (Input.GetKeyDown(KeyCode.Alpha2))
{
state = nextStates[1];
}
else if (Input.GetKeyDown(KeyCode.Alpha3))
{
state = nextStates[2];
if (Input.GetKeyDown(KeyCode.Alpha1 + index))
{
state = nextStates[index];
}
}
textComponent.text = state.GetStateStory();
}
Expand Down

8 comments on commit de73de8

@amarcelissen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed your lessons on Text101 several times and can not find anywhere a script that includes "q" to quit.
Can you please show me how you did this.

Thanks Alf

@coach-potat0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed your lessons on Text101 several times and can not find anywhere a script that includes "q" to quit.
Can you please show me how you did this.

Thanks Alf

just add this in managestate part

if (Input.GetKeyDown(KeyCode.Q))
{
state = startingState;
}

@Noel-alt832
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a compilation error that occurs every time I try to play my text adventure game. It says something like AdventureGame is already included under namespace and stuff like Start and Uptade methods are already defined. Can I have suggestions as to what my problem might be?

@Noel-alt832
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote code for the c# script AdventureGame up until the for loop lecture. It worked fine until I used the for loop and the problem stated in my previous comment started to occur.

@Crowinflames
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a compilation error that occurs every time I try to play my text adventure game. It says something like AdventureGame is already included under namespace and stuff like Start and Uptade methods are already defined. Can I have suggestions as to what my problem might be?

I have the same error and can't find what's wrong, even tried to write it whole again and same result. I get error CS0101 and error CS0111. Anybody has a possible solution?

@Crowinflames
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so I was trying to rewrite everything and noticed something, there were two AdventureGame.cs scripts in the assets, one within the Scripts folder and the other in Assets. Deleted the one in Assets and everything works like magic.

@Noel-alt832
Copy link

@Noel-alt832 Noel-alt832 commented on de73de8 Jul 6, 2021 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Noel-alt832
Copy link

@Noel-alt832 Noel-alt832 commented on de73de8 Jul 6, 2021 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.