Could anyone offer suggestions on automating a 3 deep scrolling menu that chooses a level for gameplay?
Hi everyone :)
I am making a typing game; the levels are strings such as public string myString = @"the string to type"; and the player types the strings for a wpm ....
There are many short levels so I have a scrolling level selection menu with a hierarchy of 3 levels of scrolling buttons; the first (Header) scrolling menu leads to a new (subHeader) scrolling menu which, when a button is selected, leads to the 3rd (level selection) scrolling menu; the buttons on this 3rd level actually choose the level with something like chooseLevel(levelSelected); where levelSelected is the text of the last button clicked.
I am using a button script and a control script for each of the 3 scrolling menus.
I have 30 to 40 levels currently (under various Header/subHeaders but may add hundreds more.
When I add a level, I sometimes need to make changes to all 3 control scripts and the switch statement on the script choosing the level.
I want to automate all this as follows (or some better way). I would like to code it so the control scripts for each scrolling menu receive the button information from the level itself. So, public string MyString = @"the string to type"; would now look more like
public string[] MyStringLevelOne = "header", "subHeader", "levelSelectionButtonText", @"the string to type";
Actually, more like,
public string[] MyStringLevelOne = "People in the New Testament", "Paul", "Acts 9:1", @"the string to type";
The control scripts would choose their button from the array above. I am having a hard time getting my mind around how to code this though. Each control script would need to get its button info from the array. This way, I only need to add the levels and all the buttons are updated automatically. I suppose a for loop?
I will get to work on the for loop... please offer suggestions if you can steer me in a more direct path...
Thanks!
So I have been kicking this around and now I am thinking of making a list of multiple arrays. Each array (in the list) would contain 4 strings, 1) the header (top scrolling menu- button's text), 2) subHeader (second scrolling menu- button's text), 3) a level name (third level menu- button's text - always unique to allow the player to choose a unique level) and 4) the actual text used in the gameplay which is also always unique.
public string[] sample {"People", "Jesus", "John 14:6", @"Jesus said to him, “I am the way, and the truth, and the life; no one comes to the Father but through $$anonymous$$e."};
The top scrolling menu control script would foreach through all the arrays' [0] index position and create a button for each unique entry. This would omit redundant header entries in the [0] position and only make one button per unique header. Top scrolling menu buttons= "People", "Things", etc
Once a button is selected, the second scrolling menu control script would compare (foreach) the pressed button's text with the all array's [0] index position and only take the ones that match (here, the matching redundant header entries are all and only included), then foreach again only through the now reduced list of arrays to make buttons from the [1] index position. Second scrolling menu buttons = "Paul", "Jesus"; "ground", "tree"; etc
Once a second scrolling menu button is pressed, the third scrolling menu control script would filter the arrays in the list only taking the arrays who's [1] index position matches the button that was just pressed and create the third scrolling menu with buttons from the matching array's [2] index position. Third scrolling menu buttons = "Acts 9:4", John 14:6" ; "John 18:6", "Gal 3:13"
Once a button is pressed on the third scrolling menu, the third scrolling menu control script will start the gameplay and set the gameplay text to equal the array's [3] position string.
Now all the menu control scripts are automated and , to add a new level, I only need to add an array[4] to the list and all the menus, buttons and gameplay texts will automatically generate at runtime.
The question is, do I use a list of many arrays or a list of many instances of a class (with the 4 strings defined) or a dictionary of classes or something else?
Thanks so much if you have read all this and I appreciate any suggestions and the opportunity to learn...
Thanks :)
Danny
Hi :)
I want to create multiple string arrays with 4 strings each and then foreach through them all.
public string[] first = {"headerButtonText1", "subHeaderButtonText1", "levelButtoneText1", "textForGameplay1"}
public string[] second = {"headerButtonText2", "subHeaderButtonText2", "levelButtoneText2", "textForGameplay2"}
So, I want to now place these in a list or something so I can foreach through them all to pull data from them.
Like:
public List levels = new List(); //somehow add all the string[] arrays to the list
levels.Add(public string[] first); levels.Add(public string[] second);
// even better, create the arrays in the list in the first place. then, foreach (level[] in levels) { // if (I have not already created a button == level[0]) { make a button with buttonText = level[0]} }
This would continue with level[1], level[2] , etc for the following menu of buttons.
Thanks for any direction.
Solved :)
I used a jagged array (string [][]) and then used Array.IndexOf(Array,string) to cycle through them.
Thanks for the tough love.
If anyone would like to see the code, I'll be happy to share it.
Now I can add one array to the jagged array and all three scrolling menus are automated with out the need for me to make any changes on the three scrolling menu's control scripts; they read from the array on another script. The new additions don't need to be in order and it doesn't matter if I am adding a completely new topic. Nice :)
Your answer
Follow this Question
Related Questions
Optimal usage of resources - level numbers 0 Answers
Making a list of images within a scrollrect generated from prefabs tappable/clickable 1 Answer
Why is my Scrollrect content jittering? 1 Answer
How to connect several buttons while pressed? 0 Answers
How to AddListener() (from code) featuring an argument for multiple buttons? 0 Answers