Blue Eye Logo

Blue Eye Macro

Automation is freedom
It is currently Sun Aug 19, 2018 7:18 am

All times are UTC




Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [Consider It] Variables are your friend
Thanked: 6 time(s)  Unread post Posted: Fri Dec 23, 2011 12:55 pm 
VIP Contributor
VIP Contributor
User avatar



Joined: Mon Sep 12, 2011 8:36 pm
Posts: 1306
Location: Steins;Gate
Been thanked: 86 time(s)
Has thanked: 0 time(s)
Contribution Points: 15363
Image

Variables are your Friend

Requested by TLBunny. Thanks for making me unlazy in the middle of the holidays. :lol:

@TLBunny

Sure. I'll even consider making a full blown tutorial if this isn't up to your needs (I usually make tutorials anyhoo).

Though, to master the variables, you want to refresh yourself with some basic math principles. If you're sufficient with math, then you've already got half of this down. You'll simply have to learn it in terms of Blue Eye Macro syntax and the lessons here also apply to general programming. However, if the idea of math plummets you, you can take heed of my various ways of implementing these variables, cookie cut them into your own macro and you'll be fine as well.

I'll leave this as a quickie tutorial at that, let me know if you have additional questions.

The Variable Concept

If you have programming OR math experience and want to simply learn how to write it in Blue Eye Macro, then proceed to the first lesson. Otherwise, bare with me here.~

In Blue Eye Macro when you create a new variable, THAT variable (and the future ones you create) will still remain in your macro script from the moment you run the macro until the macro finishes it's job. However, please avoid using "Global Variable" when you see it as the purpose for it is left to the advanced users.

After you read up on the following lessons, I will come back and re-apply this example.

Lesson 1: How to Initialize Variables (a.k.a. writing them down)

Simply type Variable.Set("A", "B") where the following parameters do this:

A - Creates a variable name, you can call this out later encasing it in curly tips { }.
B - Gives your variable a value. It can be text or numbers.

This is the application to initialize variables via Code View:

Code:
Variable.Set("My Variable A", "1")
Variable.Set("My Variable B", "5")
Variable.Set("My Variable C", "10")
Variable.Set("My Variable D", "Blue Eye Macro Newbie")


Keep in mind, we will use this variable set throughout the tutorial.

I recommend you state your variables right in the beginning of your code. Placing them anywhere else and you could get run-time errors within the lines of "This variable does not exist"

If you're making your macro with functions in them, always make sure to initialize ALL your variables in the main (beginning) part of your code

Code:
begin
//Initialize all your variable sets here at the beginning
//This is considered the main as Blue Eye Macro will always start reading here
end

function("Function A")
//... and not in a function, not recommended.
function


That's it, literally!

Lesson 2: How to Call Out and Use Variables

To my knowledge with the Blue Eye Macro API, there are quite a few ways of putting your variables to good use.

Some of the methods are:

1) Variable.Evaluate (Math or Text) [We'll get to this in a moment]
2) Printing out the variables
3) Using if-statements attaching a variable.
4) Controlling loops using variables
5) Etc. Uses (I will simply compile a list of some of the handy Variable commands you should start experimenting with. I will exclude Regrex for the tutorial)

I will explain those in that particular order and will use a code example on how to implement said technique.

1) Variable.Evaluate (Math or Text)

The most handy function you'll ever come across in Blue Eye Macro's Variable command-set. You can literally add, subtract, multiply, divide all at once if you like, and you can combine variables in the mix. Let's say if you want it to add up the sums of Variables A, B, and C, (1 + 5 + 10), and in addition you want to add a 4 (So far, we got 1 + 5 + 10 + 4), we will get the result of 20.

This is how you write it in Blue Eye Macro Syntax:

Code:
//Evaluate Math
Variable.Evaluate (Math)("{My Variable A} + {My Variable B} + {My Variable C} + 4", "mysum")
//Evaluate Text
Variable.Evaluate (Text)("Current Rank: {My Variable D}", "myrank")


You can also experiment and use these signs as well:
Code:
+ is add
- is subtract
* is multiply
/ is divide
() is parenthesis

And lastly, { } with text between the curly brackets it means that you're using a variable inside the command.


Note that math goes in order of operations so be aware of that.

E.X.

This is right
1 + 6 / 3
1 + 2
3

This is WRONG
1 + 6 / 3
7 / 3
2.3333333333

2) Printing out the variables

This directs right into our previous example on (1). You have to use Variable.Evaluate (Math AND Text) FIRST before you are able to print out the variable into a Window or a text file, otherwise it will not display it properly.

To print out a variable (in this case, we will use "mysum" as an example). Go ahead and test it out for yourself:

Code:
begin
    Variable.Set("My Variable A", "1")
    Variable.Set("My Variable B", "5")
    Variable.Set("My Variable C", "10")
    Variable.Set("My Variable D", "Blue Eye Macro Newbie")

//Math Example
    Variable.Evaluate (Math)("{My Variable A} + {My Variable B} + {My Variable C} + 4", "mysum")
    Variable.Evaluate (Text)("{My Variable A} + {My Variable B} + {My Variable C} + 4 = {mysum}", "textresult")

//Text Example
    Variable.Evaluate (Text)("Current Rank: {My Variable D}", "textresult2")   

//Final results are displayed here
    Window.Display message box("{textresult}", "no")
    Window.Display message box("{textresult2}", "no")
end


When executing the program, it should say this in the window box:

"1 + 5 + 10 + 4 = 20". Press OK, a new window shows up.
"Current Rank: Blue Eye Macro Newbie". Press OK, macro ends.

That's all there is to it.

3) Using if-statements with your variable.

Let's say in this case, you want to check that the variable specified is equal to a particular number.
We will make our "Current Number" equal to 5, and compare it with an if-statement if the number is indeed, a 5.

Code:
begin
Variable.Set("Current Number", "5")
    if Variable.Is equal to("Current Number", "5")
            begin
                Window.Display message box("The current number is 5", "no")
            end
    if  Macro.Previous criteria was not met()
               begin
                   Window.Display message box("The current number is not 5", "no")
               end
end


When you execute it, "The current number is 5" should be displayed. Now, feel free to edit the first line and give Current Number a different number and run it again. You'll get the second message instead of the first one.

4) Controlling loops using variables

My favorite part. This is a nice example to go about this. We will use a counter method where we initialize one of our variables to zero and give it a name that's recognizable, like "Counter" in this case. We can either write this in an if-statement or a while (I recommend while)

Code:
begin
   Variable.Set("Counter", "0")
     while  Variable.Is less than (Math)("Counter", "5")
               begin
                    //Insert whatever commands and functions you want to go with it
                    Variable.Increment (Math)("Counter")
               end
end


Alternatively, you can simply use begin loop("5"), however with the variable approach, it's reserved for more complex coding and programmers would want to, let's say for every even amount in counter it wants to use "Function A" and for every odd amount in counter it will do a different process, "Function B".

Also, you'll see a Modulo command. Think of Modulo as "what the remainder number is".
Example: 2/2 is 1 remainder 0. Therefore the mod is 0.
2/3 is 0 remainder 3. Therefore the mod is 3.
14/6 is 2 remainder 2 (Think 6*2 = 12, you're missing 2 away from 14). Therefore, the mod is 2.

Code:
      begin
           Variable.Set("Counter, "0")
           Variable.Set("The Number", "1")
           while  Variable.Is less than (Math)("Counter", "10")
                begin
                     //Over here, you can also change variables and make one variable equal another variable.
                     //This is allowed, but make sure you know what you're doing first.
                     Variable.Set("CounterMod", "{Counter}")
                     if  Variable.Modulo is equal to("CounterMod", "2", "0")
                     //More Explanation on Modulo is equal to:
                     //First parameter requires you for a variable name
                     //Second parameter requires what number to divide by
                     //Third parameter requires what the result of the Modulo should be
                          begin
                               Function.Execute("Function A")
                          end
                     if  Macro.Previous criteria was not met()
                          begin
                               Function.Execute("Function B")
                          end
                     Variable.Increment (Math)("Counter")
                end
      end

function("Function A")
               begin
                    Variable.Add (Math)("The Number", "11")
               end
function

function("Function B")
               begin
                    Variable.Add (Math)("The Number", "1")
               end
function


What's handy to note here is the Variable can be accessible within the macro only. If you let's say, are running multiple macros, only then you should be concerned with the (Global) use.

5) Etc. Uses.

I will list some of the handy Variable commands you can use with your program. Don't forget to click inside the blank quotation marks for more details about them.

Code:
Variable.Increment (Math)("")
Variable.Decrement (Math)("")
Variable.Replace within text("", "", "")
Variable.Set random number("", "", "")
Variable.Set random text("", "", "")
Variable.To modulo (Math)("", "")
Variable.Evaluate (Math)("", "")
Variable.Evaluate (Text)("", "")
//If commands
          if  Variable.Does not contain text("", "")
               begin
               end
          if  Variable.Exists("")
               begin
               end
          if  Variable.Is greater than (Math)("", "")
               begin
               end
          if  Variable.Is less than (Math)("", "")
               begin
               end
          if  Variable.Is equal to("", "")
               begin
               end
          if  Variable.Is not equal to("", "")
               begin
               end
          if  Variable.Modulo is equal to("", "", "")
               begin
               end

Lesson 3: Predefined Variables In Action
viewtopic.php?p=18342#p18342

I will expand more on this soon.

Frequently Asked Questions

simba wrote:
I might start moving functions into separate macros and calling them from the main macro, but i'm not sure if that works with variables?


The short and simple version, yes, VARIABLES does work with FUNCTIONS. As long as you create that variable and run your macro, that variable will always remain on and will keep track of that value until the end of macro.

For a deeper understanding, I create an example for this user:

Critical wrote:
When you declare a variable in your macro, your variables will retain their values and those variables will change accordingly depending on how you script your macro. Even if your variable is inside a different function, your variable will be able to be accessed throughout exclusively to the macro you've created. This is a programming concept.

(Just be careful not to use "Global Variables", that's an entirely different concept and that's used with the intent and purpose of running multiple macros.)

Let's take a scenario here:

"You're looking if the current number is one. You want a new function to take care of adding your current number by one. There are two conditions:"

Code:
> If it is one, then prompt the user that the current number is one and add that number by one.
> If it is not one, them prompt the user to state that the current number is not one.


As a habit, you usually want to state your variables right in the beginning using Variable.Set(). Now, you want to create a new variable called number and we set it equal to 1.

Afterward, we will create a new function that will add a number if the number is equal to one. In pseudo-code, you would think of it this way as:

Code:
Function Title "Add"
-----------------------
Function START
   If the number = 1
        Then I will add by "1" to the current number, totaling me two
        Report back to user that "number = 1"
   If the number =/= 1
        Then I will report back to the user that number =/= 1
Function END


For the purpose of answering your question, we'll make our "main" already have a variable named "number" with the value of 1.
Using this example below as our reference, we will then study this line-by-line basis.

Pay attention to the order of how Blue Eye Macro will run this process:

Code:
 begin (1)
     Variable.Set("number", "1") (2) //Note: From now on, "number" will always be "1" unless a change comes up.
     Window.Display message box("Is the number currently one?", "no") (3)
     Function.Execute("Add") (4)
 end (15)

function("Add") (5)
     begin (6)
          if  Variable.Is equal to("number", "1") (7)*
          //Does the variable "number" exist? Yes.
          //Does "number" currently hold the value of "1"? Yes.
          //Blue Eye Macro confirms that this condition is met, therefore it moves to the next line.
               begin (8)
                    Variable.Add (Math)("number", "1") (9)
                    Window.Display message box("The number one has been detected, adding by one. The total sum is two.", "no") (10)
               end (11)
          if  Macro.Previous criteria was not met() (12)*
          //Did the last "if" statement failed it's condition?
          //Blue Eye Macro will check the last "if" statement's condition made
          //* 'if    Variable.Is equal to("number", "1") ' = Passed / Was Met
          //"The previous criteria WAS met" which is considered a success.
          //Therefore, it passes this line and all the other lines marked (X)
               begin (X)
                    Window.Display message box("The number was not one.", "no") (X)
               end (X)
     end (13)
function (14)


The important aspect to note are the ones marked in asterisk marks.

For additional information regarding Variables, I have also created a tutorial for it here: viewtopic.php?p=17803#p17803

_________________
Image
Code:
> Meanwhile at Blue Eye Macro...
> BEM Video Games Department - Moderator, Coder, Debugger, Math/Physics & Algorithm Enthusiast - USA
Current Project: Mod Duty


Top
 Profile  
Reply with quote  
 Post subject: Re: [Consider It] Variables are your friend
Thanked: 0 time(s)  Unread post Posted: Wed Dec 28, 2011 7:57 am 
Partner / Developer
Partner / Developer
User avatar



Joined: Mon Jan 18, 2010 11:51 am
Posts: 4523
Been thanked: 1188 time(s)
Has thanked: 132 time(s)
Contribution Points: 32836
Nicely written.

This should be helpful to many :)

_________________
Blue Eye - Developer / Moderator
Code:
Gigus


Please read the rules about contribution points - click here

Do you know everything about BE, the forum, licenses and contribution points?
Please take a minute to read this introduction & guidelines.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Consider It] Variables are your friend
Thanked: 0 time(s)  Unread post Posted: Wed Dec 28, 2011 2:31 pm 
VIP Contributor
VIP Contributor
User avatar



Joined: Mon Sep 12, 2011 8:36 pm
Posts: 1306
Location: Steins;Gate
Been thanked: 86 time(s)
Has thanked: 0 time(s)
Contribution Points: 15363
Why thank you. I'm considering doing more mini-series of breaking down each main API component to Blue Eye Macro. (Color naturally, is the most popular but will get quite a lengthy overhaul of a tutorial since a lot of people don't know how to do this, and I get asked this on a weekly basis.) :roll:

_________________
Image
Code:
> Meanwhile at Blue Eye Macro...
> BEM Video Games Department - Moderator, Coder, Debugger, Math/Physics & Algorithm Enthusiast - USA
Current Project: Mod Duty


Top
 Profile  
Reply with quote  
 Post subject: Re: [Consider It] Variables are your friend
Thanked: 0 time(s)  Unread post Posted: Wed Dec 28, 2011 5:40 pm 
Active User
Active User



Joined: Thu Feb 11, 2010 4:36 pm
Posts: 38
Been thanked: 0 time(s)
Has thanked: 3 time(s)
Contribution Points: 652
Very good article. Should be helpful to many.

Nice work.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Consider It] Variables are your friend
Thanked: 0 time(s)  Unread post Posted: Wed Dec 28, 2011 10:28 pm 
Partner / Developer
Partner / Developer
User avatar



Joined: Mon Jan 18, 2010 11:51 am
Posts: 4523
Been thanked: 1188 time(s)
Has thanked: 132 time(s)
Contribution Points: 32836
Critical wrote:
Why thank you. I'm considering doing more mini-series of breaking down each main API component to Blue Eye Macro. (Color naturally, is the most popular but will get quite a lengthy overhaul of a tutorial since a lot of people don't know how to do this, and I get asked this on a weekly basis.) :roll:


That would be pretty cool, perhaps I could link to those articles from within the documentation pages - That also makes it easier to use them as future references for answering questions.

_________________
Blue Eye - Developer / Moderator
Code:
Gigus


Please read the rules about contribution points - click here

Do you know everything about BE, the forum, licenses and contribution points?
Please take a minute to read this introduction & guidelines.


Top
 Profile  
Reply with quote  
 Post subject: Re: [Consider It] Variables are your friend
Thanked: 0 time(s)  Unread post Posted: Thu Dec 29, 2011 1:49 am 
VIP Contributor
VIP Contributor
User avatar



Joined: Mon Sep 12, 2011 8:36 pm
Posts: 1306
Location: Steins;Gate
Been thanked: 86 time(s)
Has thanked: 0 time(s)
Contribution Points: 15363
You have my permission when they release and when you think they are deemable and corrected for technicalities. :lol:

_________________
Image
Code:
> Meanwhile at Blue Eye Macro...
> BEM Video Games Department - Moderator, Coder, Debugger, Math/Physics & Algorithm Enthusiast - USA
Current Project: Mod Duty


Top
 Profile  
Reply with quote  
 Post subject: Re: [Consider It] Variables are your friend
Thanked: 0 time(s)  Unread post Posted: Fri Jan 06, 2012 10:49 am 
Silver Contributor
Silver Contributor
User avatar



Joined: Sun Feb 07, 2010 9:11 pm
Posts: 207
Been thanked: 5 time(s)
Has thanked: 19 time(s)
Contribution Points: 5596
Wow, that was a good post / tutorial. Well done!

And I guess it's also worth a thanks to @TLBunny for making you unlazy :p

When is your next holiday - so I can prepare some requests ^^ (joking). But I really enjoy those kind of posts!

_________________
Code:
Martin

Full-time Macroholic


Top
 Profile  
Reply with quote  
 Post subject: Re: [Consider It] Variables are your friend
Thanked: 0 time(s)  Unread post Posted: Fri Jan 06, 2012 10:53 am 
VIP Contributor
VIP Contributor
User avatar



Joined: Mon Sep 12, 2011 8:36 pm
Posts: 1306
Location: Steins;Gate
Been thanked: 86 time(s)
Has thanked: 0 time(s)
Contribution Points: 15363
Hahaha, oh you.

I just make tutorials and such to my own accord and by request (when presented and asked formally).

_________________
Image
Code:
> Meanwhile at Blue Eye Macro...
> BEM Video Games Department - Moderator, Coder, Debugger, Math/Physics & Algorithm Enthusiast - USA
Current Project: Mod Duty


Top
 Profile  
Reply with quote  
 Post subject: Re: [Consider It] Variables are your friend
Thanked: 0 time(s)  Unread post Posted: Sat Jan 07, 2012 10:40 am 
VIP Contributor
VIP Contributor
User avatar



Joined: Mon Sep 12, 2011 8:36 pm
Posts: 1306
Location: Steins;Gate
Been thanked: 86 time(s)
Has thanked: 0 time(s)
Contribution Points: 15363
Oh yes, there's also Pre-Defined Variables so I linked that on the guide at the bottom of my first post. If additional explanation is needed, I will write that down.

_________________
Image
Code:
> Meanwhile at Blue Eye Macro...
> BEM Video Games Department - Moderator, Coder, Debugger, Math/Physics & Algorithm Enthusiast - USA
Current Project: Mod Duty


Top
 Profile  
Reply with quote  
 Post subject: Re: [Consider It] Variables are your friend
Thanked: 0 time(s)  Unread post Posted: Thu Feb 09, 2012 2:35 pm 
VIP Contributor
VIP Contributor
User avatar



Joined: Mon Sep 12, 2011 8:36 pm
Posts: 1306
Location: Steins;Gate
Been thanked: 86 time(s)
Has thanked: 0 time(s)
Contribution Points: 15363
Expansion Pack: Expanded on a FAQ concerning if variables work through functions and how it works.

_________________
Image
Code:
> Meanwhile at Blue Eye Macro...
> BEM Video Games Department - Moderator, Coder, Debugger, Math/Physics & Algorithm Enthusiast - USA
Current Project: Mod Duty


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next

All times are UTC


You cannot post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group