Topic: Programming Like you Speak.

I posted a link to a tutorial I made on how to understand computer programming. And to deduce the idea down even further I want to post on how to PROGRAM LIKE YOU SPEAK.

In the tutorial I said a program is like a RECIPE. A recipe has ingredients and instructions on how to use those ingredients to make a meal. The ingredients of programming are VARIABLES. The instructions of programming are called STATEMENTS. And a FUNCTION is a collection of STATEMENTS. For example, when you say "BAKE" you are saying, "Press Bake on the stove." And when you say "PRESS," you are really saying, ''Take your finger and apply force to a button that reads "Press."

Variables are named like NOUNS(person,place,thing, or idea) and functions are named like VERBS(Action words)

This is just how programming works. In LUA (the scripting language for Maratis) a function looks like this:

Bake()

And a variable looks like this

button =

But you have to MAKE THE INSTRUCTIONS for the Bake() function. When you type Bake() you want something to happen.

So how do you program like you speak? Just think about what parts of your sentence are nouns, and which are verbs.

Hmm, let's think of a game scenario:

--SCENARIO
Joey is locked inside of a room. There is a small window above him that lets in a bit of light, and an old chair leaning against a table on a wall. Is there a key in the room? Is there anything else that could help him escape this dark room?
--END SCENARIO

Well, we have a lot of information in this scenario. And in fact, this could be a complete (however small it may be) game.
Let's see what NOUNS we have:

joey =
room =
door =
light =
window =
chair =
table =
wall =
key =

Let's figure out some actions Joey either has taken, is taking, or could take:

Search()
Escape()
LookAtWindow()
GrabChair()
TurnOnLight()

That's good enough so far. We can use BOOLEANS to give objects STATES. For example we could set the light to OFF or ON. We could set the door to OPEN or CLOSED. It's done like this:

closed = true
on = false
scared = false

Later on, if something happens, we could then change the ''on" variable to true. And if the on variable is true, we can cause another function to happen. The way this is done is with CONDITIONAL STATEMENTS.

Conditional statements help control the FLOW of actions so that things don't happen at the same time. Example:

if closed = false then
     Escape()
end

So if we later set closed to false, then Joey can escape.

Conditional statements control the GAMEPLAY of the game.

Here is another use:

if scared=true then
     LookAtWindow()
end

--More to come when I think of it...

Last edited by Tutorial Doctor (2013-10-13 04:33:25)