Note: Use 2 screens to record… Hi I’m Title Pending, Welcome to Jebdia’s and my course for Godot and Rakugo for Beginners. Our complete course, will end with creating a First Person Shooter in Godot with story elements using the Rakugo Library for Godot. Also, there’s a homework link below, so you can practice what you should learn from this unit yourself, and you can ask questions of either Jebedia or myself in the discord link below. Welcome to Lesson 2 Variables and Logic Operators We have taken the time to write out scripts for each lesson. You can find the script in a link in the description of this video. Also, at times I may show the script I’m reading from, and sometimes go off script, so please forgive me. Also, in the description, this lesson has time stamps and headers. Feel free to skip ahead or review.(Show moc timestamps in the description.) Our goal today is to use variables and functions to simply turn something “on” or “off”. I’m going to go over the basics of Variables and Logic Operators. These are the simplest things to understand in any programing language. We chose GDscript as many believe it is easier for beginners to learn then C#, but C# is another wonderful language the Godot Engine supports. If you are still curious many developers weighed in on a facebook discussion and I also made a vid about the discussion in case you don’t use facebook. You can see a link to the discussion and related video below. Like natural human language, there are many programming languages (i.e. code). However, A Machine language (i.e. code) is simpler than a human one. There are no variables such as idioms, cultural norms or political parties, etc. It is literally literal. If something doesn't make logical sense, it simply does nothing. However, given this, programming languages do contain logic, conditions, and arguments that may annoy you at times. 1. What does “extends” do? First, let’s look at the start of a GD script… extends will relate to the type node your linking the gdscript to. You can link or extend to other nodes you’ve made, but in this case we are extending to a spatial node. If you are unfamiliar with nodes you can check the link to the the official Godot docs in the description below. https://docs.godotengine.org/en/3.1/getting_started/step_by_step/scenes_and_nodes.html #Note to self: Point with mouser Okay, we are clicking on the 3D tab on the top. As you can see, I’ve pre-constructed a 3D scene with 3 switches that affect the animation of the cube in the scene. I understand, for a beginner, things like how to use the lights might seem a little hard. Have no fear, you can download this file from the link below, and ask questions of both of us in Jebediah's Club Discord. https://discord.gg/n3dt32U However, things like lights and importing models is a topic for another day as we are focused on Variables and Logic Operators for this Unit. Looking at this example scene, you can see that the Spatial Node is the main node (i.e. parent) and the other nodes (i.e. children) are under the Spatial node in the scene tree. This means, we can pretty much program, code and script from the Spatial Node and affect all the other nodes. Again, the Spatial node is the Parent, and all nodes under it are children like a family tree. So clicking back on the Script tab on the top, you can see the first line is extends Spatial. Again, Spatial being the type of node we are scripting for in GDscript. After that we can see some base variables I’ve set up. 2. Variables X+2=3 This math above should be pretty easy to figure out. X should be 1. Of course X, could be a lot of other things like (Y-10) or something, but let’s consider that X is equal to one. X is a variable in the equation, just like 2 and 3. So in GDscript “var x = 1” would be how you could represent the variable. Variables come before functions: Here’s our simple variables for this unit. var a = false var b = false var c = false This means when the scene and nodes load, these variables will start as “false”. Now of course you can have other variables later that represent states, like speed or health, but these variables are super simple. Note they will be used in A Boolean value. A Boolean value simply means a variable that is “on” or “off”, “true” or “false”. 3. Functions What is a Function: https://www.kidscodecs.com/programming-functions/ What’s under a function: Expressions/ "statements"/ "equations" or you can call all of it "code". A function is our logic operator. X+2=3 is a basic function. You have the equation X+2, and a desired output of 3. For us, we will now create a function that checks if something is “on” or “off”. Okay let’s look at the code: Note to self: Delete and retype things to highlight what you are talking about... func _process(delta): What is delta? Andrew Wilkes responded in the official Godot Facebook group If you are curious about delta in Godot, you can check out Andrew’s site, link below in description https://gdscript.com/godot-timing-tutorial. Next if Input.is_action_just_pressed("switch_a"): I’m going to delete this, now when I retype this you’ll see that there are auto text option. Godot is good at giving little bits of code. The code itself, is related to pressing a key. Note: let me quickly show you how to set up a key. You click on Project/Project Settings/Input Map and hit the plus button on the right side. Scrolling down, you can see I ‘ve already added the button. Now back to the code. “a = !a” a= true !a= false $Switch/SpotLight.visible = !$Switch/SpotLight.visible #So take a look at the scene tree, you'll see that this relates to the order of the tree. As you can see we start with Switch, then we go to SpotLight. It’s like looking for a file in a directory, but in this case it’s a node within a node. Also notice that we use here forward slash(Web, Linux, Mac) and not backslash(Windows). The node closest to the main node, is first, and then the node order just follows. “.” the dot or period will then state if the spotlight is visible or invisible. anim($Switch/CSGMesh/AnimationPlayer, a) “anim” relates to the animation player and indeed the () prathereses will again be a node order that tell Godot what node to go to, and what AnimationPlayer to use. # This entire line refers to the bottom function "func anim(anim, value):" whereas a(value) it plays "On" animation if a == true and plays "off" animation if a ==false . $CSGMesh_Cube/BlockAni.play ("switch_a") Finally, this will play the animation “switch_a”. “Return” will run this function if the godot engine understands the code after the button is pressed. For the other switches, I just copy and paste and then change the variables. We will cover the animation suite in a later vid, but you can always Google the Godot Animation player, and I’ll put links to animation tutorials if you’d like to get started a little sooner. Also note: I did something a little different to combine animations which I will cover later when I talk about the animation tree. Finally we need to have one function to play the animation one when switch_a is “on” and “off”. For this we just need a conditional statement. func anim(anim, value): in the () is the animation name and the value: if value: anim.play("On") Check to see if the animation is playing. else: anim.play("off") Will turn off the animation player. Recap: And that’s about it. I hope anyone using this learned how to setup variables as vars. how to set up functions. how to set up booleens and how to set up if/else statements. We have a general plan where we want to take this course, but please put a comment below and give us feedback so we can help develop the course for beginners. And of course, like and subscribe to help our content reach others. Production Notes: Have slides with really simple code concepts. Do a seperate video about importing files.