- Home /
Integer in if statement, scripting help
Hello, I am new to integers, and I have searched all over the web and i cant find how to properly read an int in an if statement. I want to read the current gear and read the RPM and if its over the threshold and the gear is 0 or 1 ect it subtracts from the realRPM so that the rpm gauge shows a lower RPM on entry to the next gear.
Here is the code:
public var currentGear : int = 0;
public var rawRPM:float;
public var realRPM:float;
function Update {
realRPM=(1000+(rawRPM*17.5));// - ((currentGear)*(3000));
if (realRPM > 7000 && currentGear += 0) {
realRPM - 3500; //This will set 1 gear start at 4500RPMs
}
if (realRPM > 6800 && currentGear = 1) {
realRPM - 3200; //This will set 2 gear start at 4500RPMs
}
if (realRPM > 6500 && currentGear = 2) {
realRPM - 3000; //This will set 3 gear start at 4500RPMs
}
if (realRPM > 6500 && currentGear = 3) {
realRPM - 3000; //This will set 4 gear start at 4500RPMs
}
if (realRPM > 6500 && currentGear = 4) {
realRPM - 3000; //This will set 5 gear start at 4500RPMs
}
if (realRPM > 6500 && currentGear = 5) {
realRPM - 3000; //This will set 6 gear start at 4500RPMs
}
}
}
//This is just a snippet from my carMotor script.
Thank you so much!
I was playing with the first if statement, not trying to do anything different from the rest of the if statements!
Answer by PAEvenson · Jun 27, 2013 at 01:32 PM
in your if statements you are setting currentgear = to a value rather than checking against it ( == ). This might fix your issues:
if (realRPM > 7000 && currentGear == 0) {
realRPM - 3500; //This will set 1 gear start at 4500RPMs
}
if (realRPM > 6800 && currentGear == 1) {
realRPM - 3200; //This will set 2 gear start at 4500RPMs
}
if (realRPM > 6500 && currentGear == 2) {
realRPM - 3000; //This will set 3 gear start at 4500RPMs
}
if (realRPM > 6500 && currentGear == 3) {
realRPM - 3000; //This will set 4 gear start at 4500RPMs
}
if (realRPM > 6500 && currentGear == 4) {
realRPM - 3000; //This will set 5 gear start at 4500RPMs
}
if (realRPM > 6500 && currentGear == 5) {
realRPM - 3000; //This will set 6 gear start at 4500RPMs
}
Thank you SO much, But i have one more error? its the subtraction of the realRP$$anonymous$$ ex (realRP$$anonymous$$ - 3000;) this is giving me an error too?
AH! Yes fixed it :D You need to put (realRP$$anonymous$$ -= 3000;)
for subtract: x -= y for addition: x += y for just equals: ==
Chears thank you PAEvenson!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Int and Javascript help 2 Answers
How to Implement System.StringBuilder into JavaScript? 2 Answers
Detect OnTriggerEnter with tags 0 Answers
Speed Pill... Variable referencing and adjusting temporarily 3 Answers