How do I make the mobile back button close a modal without returning to the previous page? - modal-dialog

On mobile, my modals cover the whole screen. They look exactly like whole new web pages. This leads to users getting confused. They expect to be able to press the back button and have the modal close. Instead the back button takes them back what they perceive as two steps.
I'm a novice at coding, so Javascript is all I've used for this, and even saying that feels like overselling my ability. I'm hoping you guys can help me figure this out.
Here's the code I used:
// Modals
// Modal Contact
function OpenModalContact () {
document.getElementById("Modal-Contact").style.display = "block";
}
// Modal-1 to 20
{
var modal1 = document.getElementById('Modal-01');
var modal2 = document.getElementById('Modal-02');
var modal3 = document.getElementById('Modal-03');
var modal4 = document.getElementById('Modal-04');
var modal5 = document.getElementById('Modal-05');
var modal6 = document.getElementById('Modal-06');
var modal7 = document.getElementById('Modal-07');
var modal8 = document.getElementById('Modal-08');
var modal9 = document.getElementById('Modal-09');
var modal10 = document.getElementById('Modal-10');
var modal11 = document.getElementById('Modal-11');
var modal12 = document.getElementById('Modal-12');
var modal13 = document.getElementById('Modal-13');
var modal14 = document.getElementById('Modal-14');
var modal15 = document.getElementById('Modal-15');
var modal16 = document.getElementById('Modal-16');
var modal17 = document.getElementById('Modal-17');
var modal18 = document.getElementById('Modal-18');
var modal19 = document.getElementById('Modal-19');
var modal20 = document.getElementById('Modal-20');
var modalContact = document.getElementById('Modal-Contact');
// Get the button that opens the modal
var Modalbtn01 = document.getElementById("ModalBtn01");
var Modalbtn02 = document.getElementById("ModalBtn02");
var Modalbtn03 = document.getElementById("ModalBtn03");
var Modalbtn04 = document.getElementById("ModalBtn04");
var Modalbtn05 = document.getElementById("ModalBtn05");
var Modalbtn06 = document.getElementById("ModalBtn06");
var Modalbtn07 = document.getElementById("ModalBtn07");
var Modalbtn08 = document.getElementById("ModalBtn08");
var Modalbtn09 = document.getElementById("ModalBtn09");
var Modalbtn10 = document.getElementById("ModalBtn10");
var Modalbtn11 = document.getElementById("ModalBtn11");
var Modalbtn12 = document.getElementById("ModalBtn12");
var Modalbtn13 = document.getElementById("ModalBtn13");
var Modalbtn14 = document.getElementById("ModalBtn14");
var Modalbtn15 = document.getElementById("ModalBtn15");
var Modalbtn16 = document.getElementById("ModalBtn16");
var Modalbtn17 = document.getElementById("ModalBtn17");
var Modalbtn18 = document.getElementById("ModalBtn18");
var Modalbtn19 = document.getElementById("ModalBtn19");
var Modalbtn20 = document.getElementById("ModalBtn20");
// Get the <span> element that closes the modal
var span1 = document.getElementById("CloseModal-01");
var span2 = document.getElementById("CloseModal-02");
var span3 = document.getElementById("CloseModal-03");
var span4 = document.getElementById("CloseModal-04");
var span5 = document.getElementById("CloseModal-05");
var span6 = document.getElementById("CloseModal-06");
var span7 = document.getElementById("CloseModal-07");
var span8 = document.getElementById("CloseModal-08");
var span9 = document.getElementById("CloseModal-09");
var span10 = document.getElementById("CloseModal-10");
var span11 = document.getElementById("CloseModal-11");
var span12 = document.getElementById("CloseModal-12");
var span13 = document.getElementById("CloseModal-13");
var span14 = document.getElementById("CloseModal-14");
var span15 = document.getElementById("CloseModal-15");
var span16 = document.getElementById("CloseModal-16");
var span17 = document.getElementById("CloseModal-17");
var span18 = document.getElementById("CloseModal-18");
var span19 = document.getElementById("CloseModal-19");
var span20 = document.getElementById("CloseModal-20");
var spanContact = document.getElementById("CloseModalContact");
// When the user clicks on the button, open the modal
ModalBtn01.onclick = function() {
modal1.style.display = "block";
}
ModalBtn02.onclick = function() {
modal2.style.display = "block";
}
ModalBtn03.onclick = function() {
modal3.style.display = "block";
}
ModalBtn04.onclick = function() {
modal4.style.display = "block";
}
ModalBtn05.onclick = function() {
modal5.style.display = "block";
}
ModalBtn06.onclick = function() {
modal6.style.display = "block";
}
ModalBtn07.onclick = function() {
modal7.style.display = "block";
}
ModalBtn08.onclick = function() {
modal8.style.display = "block";
}
ModalBtn09.onclick = function() {
modal9.style.display = "block";
}
ModalBtn10.onclick = function() {
modal10.style.display = "block";
}
ModalBtn11.onclick = function() {
modal11.style.display = "block";
}
ModalBtn12.onclick = function() {
modal12.style.display = "block";
}
ModalBtn13.onclick = function() {
modal13.style.display = "block";
}
ModalBtn14.onclick = function() {
modal14.style.display = "block";
}
ModalBtn15.onclick = function() {
modal15.style.display = "block";
}
ModalBtn16.onclick = function() {
modal16.style.display = "block";
}
ModalBtn17.onclick = function() {
modal17.style.display = "block";
}
ModalBtn18.onclick = function() {
modal18.style.display = "block";
}
ModalBtn19.onclick = function() {
modal19.style.display = "block";
}
ModalBtn20.onclick = function() {
modal20.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
spanContact.onclick = function() {
modalContact.style.display = "none";
}
span1.onclick = function() {
modal1.style.display = "none";
}
span2.onclick = function() {
modal2.style.display = "none";
}
span3.onclick = function() {
modal3.style.display = "none";
}
span4.onclick = function() {
modal4.style.display = "none";
}
span5.onclick = function() {
modal5.style.display = "none";
}
span6.onclick = function() {
modal6.style.display = "none";
}
span7.onclick = function() {
modal7.style.display = "none";
}
span8.onclick = function() {
modal8.style.display = "none";
}
span9.onclick = function() {
modal9.style.display = "none";
}
span10.onclick = function() {
modal10.style.display = "none";
}
span11.onclick = function() {
modal11.style.display = "none";
}
span12.onclick = function() {
modal12.style.display = "none";
}
span13.onclick = function() {
modal13.style.display = "none";
}
span14.onclick = function() {
modal14.style.display = "none";
}
span15.onclick = function() {
modal15.style.display = "none";
}
span16.onclick = function() {
modal16.style.display = "none";
}
span17.onclick = function() {
modal17.style.display = "none";
}
span18.onclick = function() {
modal18.style.display = "none";
}
span19.onclick = function() {
modal19.style.display = "none";
}
span20.onclick = function() {
modal20.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modalContact) {
modalContact.style.display = "none";
}
if (event.target == modal1) {
modal1.style.display = "none";
}
if (event.target == modal2) {
modal2.style.display = "none";
}
if (event.target == modal3) {
modal3.style.display = "none";
}
if (event.target == modal4) {
modal4.style.display = "none";
}
if (event.target == modal5) {
modal5.style.display = "none";
}
if (event.target == modal6) {
modal6.style.display = "none";
}
if (event.target == modal7) {
modal7.style.display = "none";
}
if (event.target == modal8) {
modal8.style.display = "none";
}
if (event.target == modal9) {
modal9.style.display = "none";
}
if (event.target == modal10) {
modal10.style.display = "none";
}
if (event.target == modal11) {
modal11.style.display = "none";
}
if (event.target == modal12) {
modal12.style.display = "none";
}
if (event.target == modal13) {
modal13.style.display = "none";
}
if (event.target == modal14) {
modal14.style.display = "none";
}
if (event.target == modal15) {
modal15.style.display = "none";
}
if (event.target == modal16) {
modal16.style.display = "none";
}
if (event.target == modal17) {
modal17.style.display = "none";
}
if (event.target == modal18) {
modal18.style.display = "none";
}
if (event.target == modal19) {
modal19.style.display = "none";
}
if (event.target == modal20) {
modal20.style.display = "none";
}
}
}
// Close modal on ESC key press
document.addEventListener("keydown", function(event) {
if (event.keyCode === 27 &&
(document.querySelector("#Modal-Contact").style.display === "block" ||
document.querySelector("#Modal-01").style.display === "block" ||
document.querySelector("#Modal-02").style.display === "block" ||
document.querySelector("#Modal-03").style.display === "block" ||
document.querySelector("#Modal-04").style.display === "block" ||
document.querySelector("#Modal-05").style.display === "block" ||
document.querySelector("#Modal-06").style.display === "block" ||
document.querySelector("#Modal-07").style.display === "block" ||
document.querySelector("#Modal-08").style.display === "block" ||
document.querySelector("#Modal-09").style.display === "block" ||
document.querySelector("#Modal-10").style.display === "block" ||
document.querySelector("#Modal-11").style.display === "block" ||
document.querySelector("#Modal-12").style.display === "block" ||
document.querySelector("#Modal-13").style.display === "block" ||
document.querySelector("#Modal-14").style.display === "block" ||
document.querySelector("#Modal-15").style.display === "block" ||
document.querySelector("#Modal-16").style.display === "block" ||
document.querySelector("#Modal-17").style.display === "block" ||
document.querySelector("#Modal-18").style.display === "block" ||
document.querySelector("#Modal-19").style.display === "block" ||
document.querySelector("#Modal-20").style.display === "block" ))
{
document.querySelector("#Modal-Contact").style.display = "none";
document.querySelector("#Modal-01").style.display = "none";
document.querySelector("#Modal-02").style.display = "none";
document.querySelector("#Modal-03").style.display = "none";
document.querySelector("#Modal-04").style.display = "none";
document.querySelector("#Modal-05").style.display = "none";
document.querySelector("#Modal-06").style.display = "none";
document.querySelector("#Modal-07").style.display = "none";
document.querySelector("#Modal-08").style.display = "none";
document.querySelector("#Modal-09").style.display = "none";
document.querySelector("#Modal-10").style.display = "none";
document.querySelector("#Modal-11").style.display = "none";
document.querySelector("#Modal-12").style.display = "none";
document.querySelector("#Modal-13").style.display = "none";
document.querySelector("#Modal-14").style.display = "none";
document.querySelector("#Modal-15").style.display = "none";
document.querySelector("#Modal-16").style.display = "none";
document.querySelector("#Modal-17").style.display = "none";
document.querySelector("#Modal-18").style.display = "none";
document.querySelector("#Modal-19").style.display = "none";
document.querySelector("#Modal-20").style.display = "none";
}
});
// Close modal on back button for mobile
document.addEventListener("backbutton", function(event) {
if
(document.querySelector("#Modal-Contact").style.display === "block" ||
document.querySelector("#Modal-01").style.display === "block" ||
document.querySelector("#Modal-02").style.display === "block" ||
document.querySelector("#Modal-03").style.display === "block" ||
document.querySelector("#Modal-04").style.display === "block" ||
document.querySelector("#Modal-05").style.display === "block" ||
document.querySelector("#Modal-06").style.display === "block" ||
document.querySelector("#Modal-07").style.display === "block" ||
document.querySelector("#Modal-08").style.display === "block" ||
document.querySelector("#Modal-09").style.display === "block" ||
document.querySelector("#Modal-10").style.display === "block" ||
document.querySelector("#Modal-11").style.display === "block" ||
document.querySelector("#Modal-12").style.display === "block" ||
document.querySelector("#Modal-13").style.display === "block" ||
document.querySelector("#Modal-14").style.display === "block" ||
document.querySelector("#Modal-15").style.display === "block" ||
document.querySelector("#Modal-16").style.display === "block" ||
document.querySelector("#Modal-17").style.display === "block" ||
document.querySelector("#Modal-18").style.display === "block" ||
document.querySelector("#Modal-19").style.display === "block" ||
document.querySelector("#Modal-20").style.display === "block" )
{
document.querySelector("#Modal-Contact").style.display = "none";
document.querySelector("#Modal-01").style.display = "none";
document.querySelector("#Modal-02").style.display = "none";
document.querySelector("#Modal-03").style.display = "none";
document.querySelector("#Modal-04").style.display = "none";
document.querySelector("#Modal-05").style.display = "none";
document.querySelector("#Modal-06").style.display = "none";
document.querySelector("#Modal-07").style.display = "none";
document.querySelector("#Modal-08").style.display = "none";
document.querySelector("#Modal-09").style.display = "none";
document.querySelector("#Modal-10").style.display = "none";
document.querySelector("#Modal-11").style.display = "none";
document.querySelector("#Modal-12").style.display = "none";
document.querySelector("#Modal-13").style.display = "none";
document.querySelector("#Modal-14").style.display = "none";
document.querySelector("#Modal-15").style.display = "none";
document.querySelector("#Modal-16").style.display = "none";
document.querySelector("#Modal-17").style.display = "none";
document.querySelector("#Modal-18").style.display = "none";
document.querySelector("#Modal-19").style.display = "none";
document.querySelector("#Modal-20").style.display = "none";
event.preventDefault();
}
});
I've incorporated this, event.preventDefault(); but it doesn't seem to work
I hoped it would prevent the back button from doing it's default behaviour.
I've seen a post on here about something like this:
https://stackoverflow.com/a/49954532/18237477
But I'm unable to incorporate that solution into my code. Their code probably works but I don't understand it. I don't know how to merge that code into mine.

Related

how to set func with boolean?

I'm stuck validating textfields on the form screen. I don't want to allow requests to be thrown even if one of the textfields is empty. I want to show warning message for empty textfield. If all conditions are met, I would like to submit a request.
func isValid() -> Bool {
if nameTextField.text?.isEmpty == false {
nameWarningLabel.isHidden = true
nameTextField.layer.borderColor = R.color.rgb_222_222_222()?.cgColor
}
else {
nameWarningLabel.isHidden = false
nameTextField.layer.borderColor = R.color.rgb_249_36_23()?.cgColor
}
if surnameTextField.text?.isEmpty == false {
surnameWarningLabel.isHidden = true
surnameTextField.layer.borderColor = R.color.rgb_222_222_222()?.cgColor
}
else {
surnameWarningLabel.isHidden = false
surnameTextField.layer.borderColor = R.color.rgb_249_36_23()?.cgColor
}
if cellPhoneTextField.text?.isEmpty == false {
phoneWarningLabel.isHidden = true
cellPhoneTextField.layer.borderColor = R.color.rgb_222_222_222()?.cgColor
}
else {
phoneWarningLabel.isHidden = false
cellPhoneTextField.layer.borderColor = R.color.rgb_249_36_23()?.cgColor
}
if isChecked == true {
agreementCheckBoxButton.layer.borderColor = R.color.rgb_222_222_222()?.cgColor
}
else {
agreementCheckBoxButton.layer.borderColor = R.color.rgb_249_36_23()?.cgColor
}
if isChecked == true || (nameTextField.text?.count ?? 0) > 2 || (surnameTextField.text?.count ?? 0) > 2 || (cellPhoneTextField.text?.count ?? 0) < 10 {
return true
}
else {
return false
}
}
If this function returns true or false, I will send a request to the
service.
I am sharing the code block with you below
Create a BOOL variable within your function. Set the default value to true, and when it runs into an else condition, set it to false. Finally, at the end of your function, return the value of your BOOL variable. If all of the positive conditions are met, it will return the default value of true, otherwise return false.
func isValid() -> Bool {
//Declare Variable
var sendRequest:Bool = true
//Check Name Text Field
if nameTextField.text?.isEmpty == false {
nameWarningLabel.isHidden = true
nameTextField.layer.borderColor = R.color.rgb_222_222_222()?.cgColor
} else {
nameWarningLabel.isHidden = false
nameTextField.layer.borderColor = R.color.rgb_249_36_23()?.cgColor
sendRequest = false
}
//Check Surname Text Field
if surnameTextField.text?.isEmpty == false {
surnameWarningLabel.isHidden = true
surnameTextField.layer.borderColor = R.color.rgb_222_222_222()?.cgColor
} else {
surnameWarningLabel.isHidden = false
surnameTextField.layer.borderColor = R.color.rgb_249_36_23()?.cgColor
sendRequest = false
}
//Check Cell Phone Text Field
if cellPhoneTextField.text?.isEmpty == false {
phoneWarningLabel.isHidden = true
cellPhoneTextField.layer.borderColor = R.color.rgb_222_222_222()?.cgColor
} else {
phoneWarningLabel.isHidden = false
cellPhoneTextField.layer.borderColor = R.color.rgb_249_36_23()?.cgColor
sendRequest = false
}
//Check Agreement Check Box
if isChecked == true {
agreementCheckBoxButton.layer.borderColor = R.color.rgb_222_222_222()?.cgColor
} else {
agreementCheckBoxButton.layer.borderColor = R.color.rgb_249_36_23()?.cgColor
sendRequest = false
}
//Return Variable
return sendRequest
}

Using Toggle in a password field in jetpack compose

I am trying to use toggle in a password field. This is my code so far but for some reason it wont work. How can I achieve toggling a password as in this image? Much appreciated!
Image: https://gyazo.com/5ad35b44dc955e0846c68f61ec9630b0
Column(
modifier = Modifier.padding(20.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
val username = remember { mutableStateOf(TextFieldValue()) }
val password = remember { mutableStateOf("") }
var revealPassword: MutableState<Boolean> =
remember { mutableStateOf(false) } // To reveal the password with toggle
Text(text = "Sign in", style = TextStyle(fontSize = 40.sp, fontFamily = FontFamily.Cursive))
Text(
text = "here",
style = TextStyle(fontSize = 40.sp, fontFamily = FontFamily.Cursive)
)
// PASSWORD
Spacer(modifier = Modifier.height(20.dp))
OutlinedTextField(
value = password.value,
onValueChange = { newText ->
password.value = newText
},
visualTransformation = if (revealPassword.value) {
VisualTransformation.None
} else {
PasswordVisualTransformation()
},
trailingIcon = {
if (revealPassword.value) {
IconButton(onClick = {
(I changed this!! -->) revealPassword.Value = false
}) { Icon(imageVector = Icons.Filled.Visibility, contentDescription = null) }
} else {
IconButton(onClick = {
(I changed this!! -->) revealPassword.Value = true }) {
Icon(imageVector = Icons.Filled.VisibilityOff, contentDescription = null)
}
}
},
label = { Text(text = "Password") },
singleLine = true,
leadingIcon = { Icon(imageVector = Icons.Default.Lock, contentDescription = null) },
modifier = Modifier
.fillMaxWidth(180F),
)
You have given revealPassword = true in both onClick().
Change the first one to revealPassword = false
Complete code
#Composable
fun TogglePassword() {
val password = remember {
mutableStateOf("")
}
var revealPassword: MutableState<Boolean> = remember {
mutableStateOf(false)
} // To reveal the password with toggle
OutlinedTextField(
value = password.value,
onValueChange = { newText ->
password.value = newText
},
visualTransformation = if (revealPassword.value) {
VisualTransformation.None
} else {
PasswordVisualTransformation()
},
trailingIcon = {
if (revealPassword.value) {
IconButton(
onClick = {
revealPassword.value = false
},
) {
Icon(imageVector = Icons.Filled.Visibility, contentDescription = null)
}
} else {
IconButton(
onClick = {
revealPassword.value = true
},
) {
Icon(imageVector = Icons.Filled.VisibilityOff, contentDescription = null)
}
}
},
label = {
Text(text = "Password")
},
singleLine = true,
leadingIcon = {
Icon(imageVector = Icons.Default.Lock, contentDescription = null)
},
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
)
}
You are setting boolean wrong.
And I think it is cleaner to control VisualTransformation above.
#Composable
fun PasswordTextField() {
var masked by remember {
mutableStateOf(false)
}
var password by remember {
mutableStateOf("")
}
val visualTransformation by remember(masked) {
if (masked)
mutableStateOf(PasswordVisualTransformation())
else
mutableStateOf(VisualTransformation.None)
}
OutlinedTextField(
value = password,
onValueChange = { newText ->
password = newText
},
visualTransformation = visualTransformation,
trailingIcon = {
if (masked) {
IconButton(onClick = {
masked = false
}) { Icon(imageVector = Icons.Filled.VisibilityOff, contentDescription = null) }
} else {
IconButton(onClick = { masked = true }) {
Icon(imageVector = Icons.Filled.Visibility, contentDescription = null)
}
}
},
label = { Text(text = "Password") },
singleLine = true,
modifier = Modifier
.fillMaxWidth(.1f),
)
}

Quite new to Swift : can't get my classes to interact

I have this code:
class Lion
{
var name:String = "Default"
var isAlive : Bool = false
func eat(cow:Cow)
{
cow.isAlive = false
print("Cow \(cow) was eaten by \(name)")
}
}
var lion1 = Lion()
lion1.name = "Mufasa"
lion1.isAlive = true
var lion2 = Lion()
lion1.name = "Simba"
lion1.isAlive = true
var lion3 = Lion()
lion1.name = "Scar"
lion1.isAlive = true
class Cow
{
var name:String = "Default"
var isAlive : Bool = false
func giveMilk ()
{
print("cow \(name) is now giving milk")
}
func die ()
{
print("Cow \(name) is now dead")
}
}
var cow1 = Cow()
cow1.name = "Moo1"
cow1.isAlive = true
var cow2 = Cow()
cow2.name = "Moo2"
cow2.isAlive = true
var cow3 = Cow()
cow3.name = "Moo3"
cow3.isAlive = true
var cow4 = Cow()
cow4.name = "Moo4"
cow4.isAlive = true
var cow5 = Cow()
cow5.name = "Moo5"
cow5.isAlive = true
var cow6 = Cow()
cow6.name = "Moo6"
cow6.isAlive = true
var cow7 = Cow()
cow7.name = "Moo7"
cow7.isAlive = true
var cow8 = Cow()
cow8.name = "Moo8"
cow8.isAlive = true
var cow9 = Cow()
cow9.name = "Moo9"
cow9.isAlive = true
var cow10 = Cow()
cow10.name = "Moo10"
cow10.isAlive = true
class Cat
{
var name:String = "Default"
func eatMouse (mouse : Mouse)
{
print("Mouse \(mouse) was eaten")
}
func getMilk (cow:Cow)
{
if cow.isAlive == true
{
cow.giveMilk()
}else{
print("A dead cow cannot provide milk")
}
}
}
var cat1 = Cat()
cat1.name = "Meow1"
var cat2 = Cat()
cat2.name = "Meow2"
class Mouse
{
var name:String = "Default"
func die ()
{
print("Mouse \(name) is dead")
}
}
var mouse1 = Mouse()
mouse1.name = "Micky"
var mouse2 = Mouse()
mouse2.name = "Mini"
var mouse3 = Mouse()
mouse3.name = "Rattata"
var mouse4 = Mouse()
mouse4.name = "Splinter"
When I run via Xcode , it tells me Cow, Mouse and Cat are "Use of undeclared type "class name" .
For the life of me, I can't figure it out ( Quite new so don't bash me).
After establishing the classes I am supposed to have the system run several different scenarios where mouse is dead, cat eats mouse, lion eats cow etc'.
This works. Try to move class definitions ahead of others.
class Mouse
{
var name:String = "Default"
func die ()
{
print("Mouse \(name) is dead")
}
}
class Cow
{
var name:String = "Default"
var isAlive : Bool = false
func giveMilk ()
{
print("cow \(name) is now giving milk")
}
func die ()
{
print("Cow \(name) is now dead")
}
}
class Lion
{
var name:String = "Default"
var isAlive : Bool = false
func eat(cow:Cow)
{
cow.isAlive = false
print("Cow \(cow) was eaten by \(name)")
}
}
var lion1 = Lion()
lion1.name = "Mufasa"
lion1.isAlive = true
var lion2 = Lion()
lion1.name = "Simba"
lion1.isAlive = true
var lion3 = Lion()
lion1.name = "Scar"
lion1.isAlive = true
var cow1 = Cow()
cow1.name = "Moo1"
cow1.isAlive = true
var cow2 = Cow()
cow2.name = "Moo2"
cow2.isAlive = true
var cow3 = Cow()
cow3.name = "Moo3"
cow3.isAlive = true
var cow4 = Cow()
cow4.name = "Moo4"
cow4.isAlive = true
var cow5 = Cow()
cow5.name = "Moo5"
cow5.isAlive = true
var cow6 = Cow()
cow6.name = "Moo6"
cow6.isAlive = true
var cow7 = Cow()
cow7.name = "Moo7"
cow7.isAlive = true
var cow8 = Cow()
cow8.name = "Moo8"
cow8.isAlive = true
var cow9 = Cow()
cow9.name = "Moo9"
cow9.isAlive = true
var cow10 = Cow()
cow10.name = "Moo10"
cow10.isAlive = true
class Cat
{
var name:String = "Default"
func eatMouse (mouse : Mouse)
{
print("Mouse \(mouse) was eaten")
}
func getMilk (cow:Cow)
{
if cow.isAlive == true
{
cow.giveMilk()
}else{
print("A dead cow cannot provide milk")
}
}
}
var cat1 = Cat()
cat1.name = "Meow1"
var cat2 = Cat()
cat2.name = "Meow2"
var mouse1 = Mouse()
mouse1.name = "Micky"
var mouse2 = Mouse()
mouse2.name = "Mini"
var mouse3 = Mouse()
mouse3.name = "Rattata"
var mouse4 = Mouse()
mouse4.name = "Splinter"

GameObject activates too soon

EDIT
So it's in here, of this I have no doubt, but why? NextOne.active = true; is firing off regardless of whether the action button is being pressed.
if(Input.GetButtonDown("Action") && Op_3 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.panic +=1;
print("1 works");
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
NextOne.active = true;
}
else if(Input.GetButtonDown("Action") && Op_4 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.insanity +=1;
print("2 works");
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
NextOne.active = true;
}
The way that I'm reading this, if action button is pressed AND Opt 3 OR Opt 4 are active then the following should happen:
An audio clip is played Insanity OR Panic are increased by 1 in the Playerhealth script A message is printed in the console Options 3 & 4 are deactivated NextOne is activated.
So what am I not seeing here? Why is NextOne activating with or without action being pressed? Is my syntax wrong?
END EDIT
Let me tell you what my script is supposed to do:
Some text appears. A question with an A/B choice appears. You choose A or B. This activates a GameObject which has a similar script on it. That script immediately disables the script you were just one. You answer another A/B question. (this time from the new script, since the old one has been deactivated) Once you answer the second question (only one on the new script) a third GameOBject activates, with another, similar script again, with the same results. It's a chain. So basically it goes
GameObject 1 is active at start of scene. (Script1) A/B choice is made GameObject 1 is deactivated GameObject 2 is activated(Script2) New A/B choice is made GameObject3 is activated(Script3) and so on.
It should be a simple on / off switch script, but here 's what's happening:
When the player makes the first decision instead of going from GameObject 1 to GameObject 2 the script is bypassing 2 and going straight to 3. Here is the script from 1 to 2:
//boolean variables
var Speaking : boolean = false;
var Entered : boolean = false;
var Speaking2 : boolean = false;
var Entered2 : boolean = false;
var Speaking3 : boolean = false;
var Entered3 : boolean = false;
var Speaking4 : boolean = false;
var Entered4 : boolean = false;
var Op_1 : boolean = false;
var Op_2 : boolean = false;
var Op_3 : boolean = false;
var Op_4 : boolean = false;
//speaking variables
var speakername : String;
var theselines : String;
var theselines2 : String;
var theselines3 : String;
var theselines4 : String;
var theselines5 : String;
var these2lines : String;
var these2lines2 : String;
var these2lines3 : String;
var these2lines4 : String;
var these2lines5 : String;
var these3lines : String;
var these3lines2 : String;
var these3lines3 : String;
var these3lines4 : String;
var these3lines5 : String;
var these4lines : String;
var these4lines2 : String;
var these4lines3 : String;
//other variables
var Background : GameObject;
var Option_1_Unselected : GameObject;
var Option_2_Unselected : GameObject;
var Option_1_SELECTED : GameObject;
var Option_2_SELECTED : GameObject;
var NextOne : GameObject;
var MouseLookScript : MouseLook;
public var guiSkin : GUISkin;
var OptionsSound : AudioClip;
var MoveSound : AudioClip;
var Playerhealthscript : Playerhealth;
function Start () {
Entered = true;
}
function Continued(){
yield WaitForSeconds(0.25);
Entered = false;
Speaking = false;
Entered2 = true;
}
function Continued2(){
yield WaitForSeconds(0.25);
Entered2 = false;
Speaking2 = false;
Entered3 = true;
}
function Continued3(){
yield WaitForSeconds(0.25);
Entered3 = false;
Speaking3 = false;
Entered4 = true;
}
function OnGUI(){
if(Entered){
Background.active = true;
MouseLookScript.enabled = false;
Speaking = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(500,345,400,175), theselines);
GUI.Label(Rect(500,380,400,175), theselines2);
GUI.Label(Rect(500,415,400,175), theselines3);
GUI.Label(Rect(500,455,400,175), theselines4);
GUI.Label(Rect(500,495,400,175), theselines5);
if(Input.GetButtonDown("Action")){
Continued();
}
}
if(Entered2){
Speaking2 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(500,345,400,175), these2lines);
GUI.Label(Rect(500,380,400,175), these2lines2);
GUI.Label(Rect(500,415,400,175), these2lines3);
GUI.Label(Rect(500,455,400,175), these2lines4);
GUI.Label(Rect(500,495,400,175), these2lines5);
if(Input.GetButtonDown("Action")){
Continued2();
}
}
if(Entered3){
Speaking3 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(500,345,400,175), these3lines);
GUI.Label(Rect(500,380,400,175), these3lines2);
GUI.Label(Rect(500,415,400,175), these3lines3);
GUI.Label(Rect(500,455,400,175), these3lines4);
GUI.Label(Rect(500,495,400,175), these3lines5);
if(Input.GetButtonDown("Action")){
Continued3();
}
}
//Question_1
if(Entered4)
{
Speaking4 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(415,345,400,175), these4lines);
GUI.Label(Rect(415,380,400,175), these4lines2);
GUI.Label(Rect(415,415,400,175), these4lines3);
Option_1_SELECTED.active = true;
Option_2_Unselected.active = true;
Option_1_Unselected.active = false;
Option_2_SELECTED.active = false;
Op_1 = true;
Op_2 = false;
if(Input.GetAxis("Vertical") < -.5)
{
Option_1_SELECTED.active = false;
Option_2_Unselected.active = false;
Option_1_Unselected.active = true;
Option_2_SELECTED.active = true;
Op_1 = false;
Op_2 = true;
print("this works");
}
if(Input.GetButtonDown("Action") && Op_1 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.panic +=1;
print("1 works");
Option_1_SELECTED.active = false;
Option_2_Unselected.active = false;
Option_1_Unselected.active = false;
Option_2_SELECTED.active = false;
NextOne.active = true;
}
else if(Input.GetButtonDown("Action") && Op_2 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.insanity +=1;
print("2 works");
Option_1_SELECTED.active = false;
Option_2_Unselected.active = false;
Option_1_Unselected.active = false;
Option_2_SELECTED.active = false;
NextOne.active = true;
}
}
}
That should do the trick I think, so I believe that the problem resides somewhere in the script for 2 to 3. Below is the script for 2 to 3.
#pragma strict
//boolean variables
var Speaking5 : boolean = false;
var Entered5 : boolean = false;
var Op_3 : boolean = false;
var Op_4 : boolean = false;
//speaking variables
var speakername : String;
var these5lines : String;
var these5lines2 : String;
var these5lines3 : String;
//other variables
var Background : GameObject;
var Option_3_Unselected : GameObject;
var Option_4_Unselected : GameObject;
var Option_3_SELECTED : GameObject;
var Option_4_SELECTED : GameObject;
var OldOne : GameObject;
var NextOne : GameObject;
var MouseLookScript : MouseLook;
public var guiSkin : GUISkin;
var OptionsSound : AudioClip;
var MoveSound : AudioClip;
var Playerhealthscript : Playerhealth;
function Start () {
OldOne.active = false;
NextOne.active = false;
Entered5 = true;
}
function OnGUI(){
if(Entered5)
{
Speaking5 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(415,345,400,175), these5lines);
GUI.Label(Rect(415,380,400,175), these5lines2);
GUI.Label(Rect(415,415,400,175), these5lines3);
Option_3_SELECTED.active = true;
Option_4_Unselected.active = true;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
Op_3 = true;
Op_4 = false;
if(Input.GetAxis("Vertical") < -.5)
{
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = true;
Option_4_SELECTED.active = true;
Op_3 = false;
Op_4 = true;
print("this works");
}
if(Input.GetButtonDown("Action") && Op_3 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.panic +=1;
print("1 works");
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
NextOne.active = true;
}
else if(Input.GetButtonDown("Action") && Op_4 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.insanity +=1;
print("2 works");
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
NextOne.active = true;
}
}
}
Got it! My son pointed out that all I needed to do was add an integer every time a question was answered, then make that integer a condition to go on to the next question.
#pragma strict
//boolean variables
var Speaking5 : boolean = false;
var Entered5 : boolean = false;
var Op_3 : boolean = false;
var Op_4 : boolean = false;
var Question : int = 0;
//speaking variables
var speakername : String;
var addhealth : String;
var addhealth2 : String
var these5lines : String;
var these5lines2 : String;
var these5lines3 : String;
//other variables
var Background : GameObject;
var Option_3_Unselected : GameObject;
var Option_4_Unselected : GameObject;
var Option_3_SELECTED : GameObject;
var Option_4_SELECTED : GameObject;
var OldOne : GameObject;
var NextOne : GameObject;
var MouseLookScript : MouseLook;
public var guiSkin : GUISkin;
var OptionsSound : AudioClip;
var MoveSound : AudioClip;
var Playerhealthscript : Playerhealth;
function Update(){
if(Question >= 1)
{
NextOne.active = true;
}
}
function Start () {
OldOne.active = false;
//NextOne.active = false;
Entered5 = true;
}
function OnGUI(){
if(Entered5)
{
Speaking5 = true;
GUI.skin = guiSkin;
GUI.Label(Rect(410,295,400,175), speakername);
GUI.Label(Rect(415,345,400,175), these5lines);
GUI.Label(Rect(415,380,400,175), these5lines2);
GUI.Label(Rect(415,415,400,175), these5lines3);
Option_3_SELECTED.active = true;
Option_4_Unselected.active = true;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
Op_3 = true;
Op_4 = false;
if(Input.GetAxis("Vertical") < -.5)
{
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = true;
Option_4_SELECTED.active = true;
Op_3 = false;
Op_4 = true;
print("this works");
}
if(Input.GetButtonDown("Action") && Op_3 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.panic +=1;
print("1 works");
Question += 1;
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
}
else if(Input.GetButtonDown("Action") && Op_4 == true)
{
AudioSource.PlayClipAtPoint(OptionsSound, transform.position);
Playerhealthscript.insanity +=1;
print("2 works");
Question += 1;
Option_3_SELECTED.active = false;
Option_4_Unselected.active = false;
Option_3_Unselected.active = false;
Option_4_SELECTED.active = false;
}
}
}

karma test case for url redirecting

Karma test case run through Istanbul.
$scope.processChkBoxes = function(listOptions){
var urlAltered = false;
$scope.myData.data = '{}';
url = URLHolder;
$scope.myData.loadDataFlg = true;
$scope.myData.noDataFlg = false;
if(listOptions[0] == true){
Iif(urlAltered == true){
url = url + "&showSubCust=true";
}else{
url = url + "?showSubCust=true";
urlAltered = true;
}
}
if(listOptions[1] == true){
Eif(urlAltered == true){
url = url + "&showSettled=true";
}else{
url = url + "?showSettled=true";
urlAltered = true;
}
}
if(listOptions[2] == true){
Eif(urlAltered == true){
url = url + "&showPendingVeh=true";
}else{
url = url + "?showPendingVeh=true";
urlAltered = true;
}
}
Iif(listOptions[3] == true){
if(urlAltered == true){
url = url + "&showActiveVeh=true";
}else{
url = url + "?showActiveVeh=true";
urlAltered = true;
}
}
VehicleListService.getVehicleList(url).then(function(data){
$scope.myData.data = data;
Iif($scope.myData.data ==undefined){
$scope.myData.noDataFlg = true;
}
$scope.myData.loadDataFlg = false;
});
};
$scope.search = function() {
$scope.gridApi.grid.refresh();
but its not showing full coverage.
Can any one help on this by writing a test case