- Home /
combine words of different scenes in a list or array; have each word link to a page
Hello everyone. I would like to ask a few questions. Basically i am creating an educational puzzle game (form words).
My first question is that how do i combine all the words formed in each level into one scene? For example, player form 6 words in level1, form 8 words in level2 etc.. So i will have a scene called "Revision" that allow player to refresh their memory on what words they have form in each level. Refer to the image for more details. http://imageshack.us/photo/my-images/41/revisionk.png/
Second, whenever player finish level1, they will be proceed to level1Complete which will show them what words they have form in level1. Then i am intending to create a link that will direct them to an "explanation" page which will explain what the individual word mean? So how could i do about it??
hi sister$$anonymous$$y, i will be more careful with my title of the question next time. Thank you for the feedback :)
hello almo, thank you for editing the title for me. Sorry guys, i will be careful of it the next time and read properly all the rules.
THAN$$anonymous$$ YOU.
more detail on this question to be found here: http://answers.unity3d.com/questions/146501/how-to-link-words-from-different-scene.html Greetz, $$anonymous$$y.
Answer by SisterKy · Jul 21, 2011 at 03:09 PM
1 one GameObject 'Manager' with don't destroy on load and and one var level01Words : List;
for each Level and a function FeedWord
that takes level : int
and word : String
as Parameters. The Function then tests what level it got as input (you can do it with if-statements, but I'd rather search for switch/case). depending on level, add the word to the appropriate levelWords-List.
2 one empty GameObject in each Scene that cares for the word-creation.
needs a variable to store the reference to the 'Manager'-Script. Search the reference in Start()
. (to get the reference, google gameObject.Find
and GetComponent
and/or 'access variables from another script' or something).
when the word is done, feed it to Manager by calling it's 'FeedWord'Function.
3 the same empty GameObject can have RevisionControl. This needs to reference the ManagerScript and read its Lists, then display them as buttons.
Edit: Oh, well.... -.- here's the code then....
//ManagerScript.js:
var level01Words : List. = new List.(); var level02Words : List. = new List.(); // an new List of Strings is created and assigned to 'lvl01Words'. // this List is currently empty.
function Awake () { DontDestroyOnLoad(transform.gameObject); // have this GameObject survive throughout all scenes. }
/ what the following function does we need a function that will later feed the Words into the empty Lists
we create a function that take two 'Parameters' Parameters are like variables, just that they exist only inside their function. we have to say, of what type these Parameters are for some weird reason, they are separated by ',' insteat of ';' when we call the function, we have to give the appropriate variables in the right order (can't call: FeedWord(someString, someInt); but call: FeedWord(someInt, someString); when calling the function, the values are assigned to the parameter-variable so inside the function FeedWord the variable 'level' has now the value 'someInt' and 'word' has now the value of 'someString' and the function will process that...
**/
function FeedWord (level : int, word : String) { switch (level) { case 1: level01Words.Add(word); break; case 2: level02Words.Add(word); break; default: print("we are neither in lvl 1 nor 2...?"); break; } }
~~~~~~~~~~~~~~~~~~~~~~
//WordCreation.js
var level : int; // set this value in the editor (level1 = '1', level2 = '2' etc.) private var newWord : String; private var managerScript : ManagerScript; // the variable managerScript references the path to a Instance (=Copy) // of your self-defined Class 'ManagerScript'
function Start() { managerScript = gameObject.Find("Manager").GetComponent(ManagerScript); // if possible, reference-paths are always stored in function Start
// depending on how you create the word, you might want to call // function CreateWord in function Start, in function Update or from another Button etc. / CreateWord(); just commented out for demonstration. Once the CreateWord-Function works propperly (= you have added the code that actually creates a word), you have to remove the */
managerScript.FeedWord(level,"Word1"); managerScript.FeedWord(level,"Word2"); managerScript.FeedWord(level,"Word3");
}
function CreateWord () { // do stuff to create your word. When it's done:
//newWord = the newly created word.
managerScript.FeedWord(level, newWord); // adds newWord to the list of level-x-Words in Manager.js }
~~~~~~~~~~~~~~~~~~~~~~~~~~~
//RevisionControl.js
var level : int; // again, set in editor to respective value. // for final revision, set this to any other value. (e.g. '100') private var manager : ManagerScript;
function Start () { manager = gameObject.Find("Manager").GetComponent(ManagerScript); }
function OnGUI () { switch (level) { case "1": DisplayButtons(manager.level01Words); break; case "2": DisplayButtons(manager.level02Words); break; default: // Default assumes we are in final revision and displays ALL words: DisplayButtons(manager.level01Words); DisplayButtons(manager.level02Words); break; } }
function DisplayButtons (levelWords : List.) { for (var i : int = 0; i< levelWords.Count; i++) // create a new variable 'i : int' to use it inside the loop // take 'element 0' (= the first word in the List) and do what is inside the loop, // then take the next element, do what's inside the loop, // ... and so on, until you are through with all elements { if (GUI.Button (Rect((10 + (level-1)*60), (10 + i*30), 50, 20), levelWords[i]))
/ what this last line of code does:
(10+(level-1)*60) sets the x-value of the topleft corner of the new button. if 'level' is 1, then this position is at (10+(1-1)*60) = 10. so all words of level1 draw in the first column at x-position = 10. if 'level' is 2, then this position is at (10+(2-1)*60) = 70. so all words of level2 draw in the second column at x-pos = 70.
(10+i*30) sets the y-value of the topleft corner of the new button. i = the first, second or third etc Word in the List we are currently checking. If i = 0 (=first word), then this pos is at (10+0*30) = 10. So all first words always draw in the top row at y-pos = 10. If i = 1 (=second word), then this pos is at (10+1*30) = 40. So all second words always draw in the second row at y-pos = 40.
levelWords[i]: if i = 0 that's the first Word of the current String-List. if i = 1 that's the second Word and so on.
**/
// if this button we just created gets clicked, do:
{
// load the explaination-page depending on what 'theWord' is
}
} }
Greetz, Ky.
I would appreciate if you could provide a proper code-syntax. Need it badly as i can't seem to get the logic. Sorry and thank you.
edited. hrm. 1hr of work...... =/
I did it very verbose, so you should be able to learn a lot from this.
...don't ask for something like that again.
Greetz, $$anonymous$$y.
"Second, whenever player finish level1, they will be proceed to level1Complete which will show them what words they have form in level1. Then i am intending to create a link that will direct them to an "explanation" page which will explain what the individual word mean? So how could i do about it??" -> this question are being ignored :(
my RevisionControl.js does both level1Complete and a final revision control, so it's an answer to question 2, too.
When you assign '1' for level : int, it's level1Complete-revision.
When you assign '3892' for level: int, it's finalRevision
Please accept and vote for my answer that I regain editing-powers at 2000 Rep.
Greetz, $$anonymous$$y.
if(GUI.Button(blahblah)) { Application.LoadLevel(levelWords[i]); }
The explanation-scene you want to load needs to have the EXACT SA$$anonymous$$E NA$$anonymous$$E as the word the user created. Then this should work.
Please accept my answer.
Greetz, $$anonymous$$y.
Answer by SisterKy · Jul 18, 2011 at 08:29 PM
Have one GameObject that won't be destroyed on load, with a Script that stores the Strings in a List. Use custom unity google search ( http://www.google.com/cse/home?cx=002470491425767499270:iugs1ezlsfq ). Search for loadlevel, dontdestroyonload, Array / List and String. Good Luck.
Greetz, Ky.
Answer by missypooh · Jul 19, 2011 at 06:21 AM
//revisionControl->create empty object and attach to it on the scene "level1"
static var lvlStringList :String[];
function Awake ()
{
DontDestroyOnLoad (transform.gameObject);
}
function Update ()
{
}
//displayLevelsWord script that are attached to the scene "revision"
var level1Words : Transform;
var level2Words : Transform;
var level3Words : Transform;
var level4Words : Transform;
var level5Words : Transform;
var level6Words : Transform;
var level7Words : Transform;
var level8Words : Transform;
var level9Words : Transform;
var level10Words : Transform;
function Update ()
{
level1Words.guiText.text +=revisionControl.lvlStringList+ "\n";
// maybe i don't know how to use the array of string, it display nothing on the scene.
}
I have try coding it but somehow it doesn't work properly. I don't really know how to use the arraylist or array of string.
Please do not post followup questions as answers. I fixed up your code formatting, in future please use the '010101' button to format your code properly so people can read it.
hello Petroz, Thank you for helping me. I am really sorry. Just start using this yesterday. So not very familiar. Noted. Will be very careful with it. So anyway how do i go about solving the problem??
Next to search field in the upper right corner is Topic called FAQ. Please read it before posting your further questions. "Please help me" is not a question btw.. Community is generously giving help, making communities life easier with good posts is very appreciated.
hi synapsemassage, thank you for the feedback. Will take note of it when i post question and my question title :)
Arrays and Lists: http://www.unifycommunity.com/wiki/index.php?title=Which_$$anonymous$$ind_Of_Array_Or_Collection_Should_I_Use%3F
You have to use something along the line of lvlStringList.Add(level1Words.guiText.text + "\n");
(if you use a List)
Or something like levelStringList[0]=level1Words.guiText.text + "\n";
if you use an array.
Greetz, $$anonymous$$y.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Is it possible to convert c# generic List<> to normal arrays? 1 Answer
How do I find a local variables index in a foreach loop? 1 Answer
How do I animate properties in a List? 0 Answers
Storing away monsters 1 Answer