Math bad/sad times

This here is like ‘the sweet’ part of logic… At University however, things get pretty nasty, at least for me with DeMorgan and math implications and all that stuff… It looks like this…

A = true
B || C = true
D && E = false
((A || B) && (C || D)) = true

(A∧(B∨C)∧¬(D∧E))∧((A∨B)∧(C∨D))

This thing “¬” is the NOT
This “^” is the AND
This “v” is thr OR
I suffered a lot with all these… :’(
or
(SinceIFailedTheCourse) => ((ISufferedALot) ^ (gotTraumatizaedByMath)) → true

think my head started hurting and eyes glazed over after that line :frowning:
sometimes the math can just boggle the brain (well mine anyway heh)

1 Like

I’m surprised how nobody mentioned the following:

  1. If the first part of AND statement is false the 2nd part does not get to run
  2. If the first part of OR statement is true the 2nd part does not get to run

that essentially means that in this lecture one can micro-optimize the code by writing:

if is_on_floor() and Input.is_action_just_pressed("jump"):
	velocity.y = -jump_force

Instead of:

if Input.is_action_just_pressed("jump") and is_on_floor():
	velocity.y = -jump_force

as the Input action is not even checked if the character is not on floor (as it doesn’t even need to be checked until the character lands on floor)

Its also true for the if - elif - else statements, the first “true” if will run no matter what, so you can write this:

	if is_on_floor() == false:
		velocity.y += gravity * delta
	elif Input.is_action_just_pressed("jump"):
		velocity.y = -1 * jump_force
	velocity.y = clampf(velocity.y, -500, 500)

But I don’t know if its a good code, if you change the if order or add more ifs it can cause problems…

Privacy & Terms