how do i make an if true statement with variables

Godot Version

4.3

Question

how do i make an if true statement with variables

depends on what you need it for.
I recommend looking at tutorials or reading the docs to learn programming

in the simplest example, first you define a variable:


var my_variable_name_here : bool = false

then, in your function, use if to evaluate a boolean (can be true or false, if true it will execute the code contained within)


if my_variable == true:#if the condition is met the expression will evaluate to true
     print("true")
var my_var2 : float = 0.0

if my_var2 > 0.5:
    print(my_var2)#prints the contents of my_var2

some of the functions offered by godot are _ready and _process. you override these functions, meaning the engine will take their names and run them under certain circumstances.
these being, _ready is run when the node is added to the game the first time. this includes when the game/scene plays for the first time.
_process is run every frame. it will run during the frame, and execute all the code in order. then, the next frame of the game it will run again. this means it runs many times per second, so it is usually used for testing if the player pressed a button.

then, if you change your variable, it will stay changed, so all the code that uses it will evaluate the new value:


my_variable = false
if my_variable == true:
    print("true")
else:
   print("false")

the program will then print false because we changed the variable.
variables that belong to the script can be changed from any function.
there are also variables that belong to the function, if they are defined there, and those are reset every time the function runs again.