- Home /
Switch cases malfunction?
In my script(below) the 2 vars alpha and pageNumber have a system where they change based on which button you click. But now it doesn't change anymore- they used to go up and down but now they stay at 1.
Can you take a look at my script and help me figure out what needs to be changed to make those 2 vars change?
(for some reason, my whole script doesn't show on safari)
thanks for any help!
"Tutorial" Script:
var firstMessage : String; var secondMessage : String; var thirdMessage : String; var fourthMessage : String; var fifthMessage : String; var sixthMessage : String; var seventhMessage : String; var buttonWidth : int; var buttonHeight : int; var X : int; var Y : int; var alpha : int; var beta : int; var Rect1 : Rect; var Rect2 : Rect; var pagePosition : Rect; var nextRect : Rect; var backRect : Rect; var windowRect : Rect = Rect((Screen.width / 2) - (buttonWidth / 2), (Screen.height / 2) - (buttonHeight / 2), buttonWidth, buttonHeight); var windowRect2 : Rect = Rect((Screen.width / 2) - (buttonWidth / 2), (Screen.height / 2) - (buttonHeight / 2), buttonWidth, buttonHeight); private var showGUI : boolean = false; private var firstTime : boolean = true; private var ShowDefault : boolean = true; private var ShowSecond : boolean = false; private var ShowThird : boolean = false; private var ShowFourth : boolean = false; private var ShowFifth : boolean = false; private var ShowSixth : boolean = false; private var ShowSeventh : boolean = false; private var ShowNext : boolean = false; private var msgToDisplay : String; private var pageNumber : int; private var pageToDisplay : int;
function Awake() { pageNumber = 0; alpha = 1; showGUI = false; FMoveAround.Takeinput = false; msgToDisplay = firstMessage; firstTime = true; } function Update() { switch(pageNumber) { case -1: pageNumber = 0; break; case 0: pageToDisplay = 1; break; case 1: pageToDisplay = 2; break; case 2: pageToDisplay = 3; break; case 3: pageToDisplay = 4; break; case 4: pageToDisplay = 5; break; case 5: pageToDisplay = 6; break; case 6: pageToDisplay = 7; break; case 7: pageNumber = 6; break; } switch(alpha) { case 0: alpha = 1; break; case 1: msgToDisplay = firstMessage; FMoveAround.Takeinput = false; break; case 2: msgToDisplay = secondMessage; FMoveAround.Takeinput = true; break; case 3: msgToDisplay = thirdMessage; FMoveAround.Takeinput = true; break; case 4: msgToDisplay = fourthMessage; FMoveAround.Takeinput = true; break; case 5: msgToDisplay = fifthMessage; FMoveAround.Takeinput = true; break; case 6: msgToDisplay = sixthMessage; FMoveAround.Takeinput = true; break; case 7: msgToDisplay = seventhMessage; FMoveAround.Takeinput = false; break; case 8: showGUI = true; FMoveAround.Takeinput = false; break; } }
function DoMyWindow (windowID : int) { GUI.skin.label.wordWrap = true; GUI.Label(pagePosition, "Page " + pageToDisplay); GUI.Label(Rect2, msgToDisplay); GUI.Label(Rect1, "Date, Time: " + System.DateTime.Now); if(GUI.Button(nextRect, "Next")) { alpha++; pageNumber++; } if(GUI.Button(backRect, "Back")) { alpha--; pageNumber--; } GUI.DragWindow (); } var Rect3 : Rect; var Rect4 : Rect; function DoMyWindowQuit(windowID : int) { GUI.skin.button.wordWrap = true; if(GUI.Button(Rect3, "Level 1-->")) { Application.LoadLevel("Level1"); } if(GUI.Button(Rect4, "<--Back")) { alpha = 7; showGUI = false; } }
function OnGUI() { if(!showGUI) { windowRect = GUI.Window(0, windowRect, DoMyWindow, "Tutorial 1"); } if(showGUI) { windowRect2 = GUI.Window(1, windowRect2, DoMyWindowQuit, "Finished learning from the tutorial?"); } }
theres no other script changing the value of alpha or page number, they can be different than one, i changed it in edit mode and playmode, but it always starts on 1 which is good but it never changes on its own (when you press the buttons) which is bad; this script did work before but now it doesn't for some reason unkown to me.
Rewrite this to use arrays ins$$anonymous$$d of a ton of separate variables, right now it's way too long.
ok, i'm working on converting the string to an array, but im confused about arrays, i've used the "for(var in array)" technique but i don't truly know about arrays, could you explain arrays and how to increase the value of an array? i'm going to ask a new question explaining this... i know virtually nothing about arrays.
It's not all showing up on your iPod I think what you mean by safari. Use a computer, it will show the entire script.