Hey there, @dethham!
Here’s my idea. I may edit later as I progress through this myself and see how Ben has us implementing states, etc:
Create an array of Text objects that will hold each “block” of text you want the user to scroll to. Make sure you keep track in comments how many are needed for each room (in each state). You will also need a single integer field to keep track of the index (position in the array) of the current block of text.
Then, whenever your player hits enter, you will either:
- Increase that integer field by one
- Decrease the integer field by a number equal to one less than the number of text blocks for that scene
The action you take will depend on the current index and state. If you are on the final text block in a state and they , you’ll do the latter to reset the blocks of text for that scene (this will loop the text for a scene continuously). Otherwise, you’ll do the former.
As an example, consider the following:
I have an array textBlocks as follows:
textBlocks = [ “Text0”, “Text1”, “Text2”, “Text3”. “Text4”. “Text5”, “Text6” ]
** the number at the end of each string is that string’s index in the array. **
The pseudocode may look like:
textBlocks = [ "Text0", "Text1", "Text2", "Text3". "Text4". "Text5", "Text6" ]
/**0-4 are in state 1, 5-6 are state 2**/
int index = 0
Update()
{
if (SpaceKeyDown)
{
if ( state == state1 and index == 4) index = index - 4
/**there are 5 text blocks in state 1**/
else if (state == state2 and index == 6) index = index - 1
/**there are 2 text blocks in state 2**/
else index = index + 1
}
/** You'll also want your normal state logic to set index if the input
/** changes the state, and you want to display the next textBlock
TextBox.Text = textBlocks[index]
}
Best coding practice would really dictate that you keep most of those “magic numbers” (random integers with no explicit reasoning) in variables instead of writing them out directly (this is for readability of your code). We would also put the last line inside wherever there’s a change in index instead of at the end of update for speed purposes. However, the above pseudocode will get the job done. To elucidate, let’s walk through an example. I’ll give the action the player does and the resulting index and text. Make sure you follow why the text and index are those values.
Action: Starts game
Index: 0
Text Displayed: Text0
Action: Spacebar pressed
Index: 1
Text Displayed: Text1
Action: Spacebar pressed 3x
Index: 4
Text Displayed: Text4
Action: Spacebar pressed
Index: 0
Text Displayed: Text0
Action: State Change (on, say, “M” key pressed)
Index: 5 (this is not handled by the pseudocode above. You’d set the index to the first index in the new state wherever you handled state changes.)
Text Displayed: Text5
Action: Spacebar
Index: 6
Text displayed: Text6