Understanding Variables

@JMichaelTX - My replies here should be in another thread, but I can't remember how to start a new topic from here and link it to this topic, so can you do that? I'm thinking it should be a topic like "Understanding Variables". Thanks.


Don't let variables scare you. You use them all the time in real life, you just don't realize it.

Let's say you like to buy Coke (the drink) from a vending machine. Your "routine" is this:

Put $1 in the vending machine, press the Coke button, and take your drink.

But it doesn't always cost $1, right? It varies from machine to machine. So the cost of a can of Coke is variable. In other words, it is a variable, and you don't know its value until you get to the vending machine.

So, really, your Coke-buying routine is this:

Put CostOfCoke in the vending machine, press the Coke button, and take your drink.

So when it's time to go get a Coke, you look at the price, and let's say it's $1.25. So you "set" CostOfCoke to $1.25, and "perform" the routine:

Put CostOfCoke $1.25 in the vending machine, press the Coke button, and take your drink.

This is what you do in real life.

Extra Credit, or Dan takes an analogy too far:

Of course, as anyone who has coded much in KM can tell you, the "routine" isn't that simple. It's really:

Put CostOfCoke in the vending machine.
Press the button.
Pause 2 seconds, or even better, Pause Until Coke Can is delivered.
Take your drink.

Well, that's not really right. It's more like:

If CostOfCoke is greater than ChangeInMyPocket then Abort Macro.
If OutOfCoke is true, then Abort Macro.
Put CostOfCoke in the vending machine.
Press the button.
Pause Until Coke Can is delivered.
If TimedOut:

Execute Macro CurseAndShakeMachine.
Execute Macro LookForReturnedMoney.
Abort Macro

Take your drink, thankful that this friggin' macro finally works right.

And finally:

Forget how the above code works, and when it breaks, CurseAndShakeMachine, because that's a universal routine.

3 Likes

I got a lump in my throat and was moved to tears by your commitment to having this work for me (and I’d say love) that your post represents. It was also a serious LOL :joy:! What total FUN AND USEFULNESS!!! Ya’ll are really good people!

:pray::pray::pray:

Yes, this is the best forum if good people I’ve ever been a part of. Its fun to give, when I’ve received so much here.

Or maybe call it “Fear of the Walking Variables🧟‍♂️”; “Variables for Dummies🤪”; or just CODING :scream:!

“Understanding Variables” could be “Understanding Variables🧐”

:smile:

One might also want to visit this KM Wiki Article:

Variables