🌳 Starting the Story Tree Node | myBetabox

🌳 Starting the Story Tree Node

Keyboard Guide

Starting the Story Tree Node

Stuck? Copy & Paste the Code into Repl.it

class TreeNode:
  def __init__(self, story_piece):

The Code Explained

A class is a way to create an object and give that object properties. For example, let’s say you want to create a class for summer shirts (the object). According to you, all summer shirts must have these properties:

  • Short sleeves
  • Bright colors
  • Cotton material

🌟 Classes create objects with the same properties and are written as class ClassName:

class TreeNode:

TreeNode is capitalized on the T and the N because that’s how Python recognizes it as a class. If it weren’t, it may be read as a variable instead.

The starting node is called the root node and this is where the story begins branching off into scenarios. Remember toΒ indent this line of code if it’s not lined up like in the video by using the tabΒ key.

 def __init__(self, story_piece):

We define a function by typing def and remember that the function syntax always use parentheses. You cannot use a function before defining it because the computer won’t understand what to do. It’s like if I asked you to “Defenestrate the collagenous tallow posthaste!” would you know what to do? Probably not, unless I explained it first.

🌟 Functions are packets of code that do a certain task and are always followed by ( ). Here we have a __init__() function.

Every time we start a class we will code an initialization function to get it started.

The parameters we are passing through the initialization function are self and story_piece.

🌟 Parameters are things that get passed into a function.

Think of it like if you have a function called washDishes() and the order was soap, rinse, then dry. Now all the dinner plates and cups that need to be cleaned will be passed through this function and will get soaped, rinsed, and dried. I could say, “Hey buddy! I need you to washDishes()” and you’d know what to do.