FluffypoopoLvl 55
- iPhone
If you think you shortening issue is bad I have to make the insides of the last time I copy and pasted locus into a doc work, but I will take this time to redesign locus’s layout and make it better then before
If you think you shortening issue is bad I have to make the insides of the last time I copy and pasted locus into a doc work, but I will take this time to redesign locus’s layout and make it better then before
I do have plans to make everything code so if it is deleted for no reason again I don’t have to go through this process again
if(mouseIsOver(gogglesBtnP1) && mouseWentDown("leftButton")) {
switch(itemsP1[0]) {
case "goggles": itemsP1[0] = "gogglesEquipped"; gogglesBtnP1.setAnimation("equipBtn"); break;
case "gogglesEquipped": itemsP1[0] = "goggles"; gogglesBtnP1.setAnimation("equipBtn"); break;
default: if(eggbucksP1 >= 500) { itemsP1[0] = "goggles"; eggbucksP1 -= 500; } break;
}
}
textSize(12);
textAlign(CENTER, CENTER);
// with this addition you should be able to get your text centered right the first time
text((itemsP1[0] === "goggles" ? "Equip": itemsP1[0] === "gogglesEquipped" ? "Unequip": ""), 42, 94);
not sure if you wanted to keep all the original code but i may have removed a few things, you could just add a setTimeout the switch statement if that is important i figured you put those in so it wouldn't trigger the other if statements
can you explain the ? operator thing?
the text center thing has a problem of where it wont center properly
pluto The ? operator is like a condensed if/else statement.
If I had this code:
var num = 1;
num ? console.log("This statement is true") : console.log("This statement is false");
It would return "This statement is true" because it's the same as:
var num = 1;
if(num){
console.log("This statement is true");
}else {
console.log("This statement is false");
}
You can also chain multiple of these statements together:
var age = 22;
age < 18 ? console.log("You are a Child") : age < 65 ? console.log("You are an adult") : console.log("You are a senior");
This would return "You are an adult". This statement is the same as:
var age = 22;
if(age < 18){
console.log("You are a child");
}else {
if(age < 65){
console.log("You are an adult");
}else {
console.log("You are a senior");
}
}
As you can see, it decreased the number of lines from 10 all the way down to just 2.
Unlike if/else however, the ? statements return values that you can use in your program.
For example, I can set variables to whatever the statement returns; In this small bit of code, it checks if you're a kid or not and sets the price accordingly.
var age = 9;
var ticketPrice = age < 18 ? "$5.00" : "$10.00";
console.log(ticketPrice);
//Returns $5.00
If you need more help with it there's some topics abt it on StackOverflow and on google, here's some documentation on it https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator
The line (itemsP1[0] === "goggles" ? "Equip": itemsP1[0] === "gogglesEquipped" ? "Unequip": "")
in Varrience's code basically means:
if(itemsP1[0] === "goggles"){
return "Equip";
}else {
if(itemsP1[0] === "gogglesEquipped"){
return "Unequip";
} else return "";
}
Just an easy way not to scar your eyes with an excessive amount of if else statements
He didn't.. type anything into a console..? He coded it into the app itself