I’m trying to make a script in the (beta) Trackmania 2 game.
(It’s an ugly kindof mix between JavaScript, HTML, C, and… other stuff I couldn’t imagine in my worst nightmare).
The scripting engine doesn’t seem to know the “and” or “&&” (if I try myVar && 16 the nice error raised is “boolean operation awaits a boolean”)
I’d like to do something like:
if (Var && 1) {
// Bit North => trace north
}
if (Var && 2) {
// Bit East => trace east
}
if (Var && 4) {
// Bit South => trace south
}
if (Var && 8) {
// Bit West => trace West
}
Any idea how I could do this if the compiler doesn’t know bitfield operations?
“Bitwise and” is usually
&, not&&. (&&is usually a “logical and”.) “Bitwise and” is&in C and JavaScript, two languages you mentioned. In fact,&&appears to be “logical and” bassd on the error message you got. The solution might simply be to useIf you really don’t have bitwise ops, it can still be done. Keep in mind that a 4 bit number can be expressed as:
If you have exponentiation, division, integer truncation and modulus, you could use the following to see if to find out if bit
xis set:If you don’t have exponentiation, it can be replaced with a lookup table.
If you don’t have modulus,
i % 2can be replaced with( (i/2) - int(i/2) )*2