Scripting Tutorials by Elvish

Tutorials, How-tos and FAQs for the Titan One device.

Scripting Tutorials by Elvish

Postby Elvish » Wed Aug 26, 2015 2:46 am

So I want to make a couple tutorials to help people get scripting on their own (If they want to learn)
Over the next few weeks I plan on recording some Youtube videos and going over some simple scripting examples as well as type up some text based tutorials. Note: anyone who contributes to this post will be added into the contributors section at the bottom of this first post, I will add your information or corrections into the other posts. However I will just list the contributors here as to save ourselves from a great deal of clutter in the tutorial part of the post.

The Titan 1 has great documentation. The GPC language documentation can be found in the below link.
https://www.consoletuner.com/kbase/gpc_language_reference.htm?mw=MjQw&st=MA==&sct=MA==&ms=AAAA

People make mistakes! Please if you notice I said something wrong or left out something important let me know!

Contributors: Elvish, perfecthuntr, UK_Wildcats_Fans
Last edited by Elvish on Wed Nov 18, 2015 4:16 am, edited 3 times in total.
User avatar
Elvish
Captain
Captain
 
Posts: 531
Joined: Tue Jun 09, 2015 4:57 am

Re: Scripting Tutorials by Elvish

Postby Elvish » Wed Aug 26, 2015 2:46 am

WHAT IS A VARIABLE?!

Variable defined by Google: "a data item that may take on more than one value during the runtime of a program."
Variable defined by Elvish: A variable is something the programmer names and assigns values to.

Naming Conventions:
You can give a variable almost any name you want, with a few restrictions:
    1. It must not be the same as any key word(wait, int, function...) Any key words will appear blue in color
    2. It must not have the same name as any combo or variable
    3. It must not contain any spaces
It is a good idea to give a variable a name which describes what it is for. For example:
"Wait_B" would be a good name to define the wait time in between the press of a B button
While "RapidFire_On" would be a good name to define a variable that helps the user determine if rapid fire should be enabled or not. Note: I would use the word On in the variable name because I would declare this as a boolean type variable.

GPC has four types of variables Constant Variables, Modifiable Variables, Booleans, and Arrays.
    A Constant Variable can't be changed after it is created and is declared as such:
      define X = 7;
      Inside your entire script X will always be equal to 7. You CAN'T update this value! Often this is used inside of GPC scripting to represent buttons you want to use for inputs such as:
      define X = XB1_X;
      This way when you want to call a button later on in your script you KNOW that X will always be the X button on the Xbox One Controller.

    A Modifiable Variable can be changed after being created and is declared as such:
      int X = 7;
      Inside your code you can modify this value at any time. Up until you modify the value it X will return
      the value of 7. Anywhere inside your code you can update the value of X by typing:
      X = 10;
      Once you update the variable it will then always return 10. It no longer remembers it had a value of 7.
      It will now return 10 until you update it again.

    A Boolean is a variable which has two values, True or False. You declare it as such:
      int Script_Running = FALSE;
      Now any time you look at the variable it will say this is false. But you can update it to equate to true
      by typing:
      Script_Running = TRUE;
      A boolean would be the best way to determine if something should be on or off, such as in the case of a
      rapid fire script.
      This effect can be achieved via Modifiable Variables as well. A programmer could use 0 as off and 1 as on. Some people prefer to write their scripts in this way. Neither way is right or wrong, just different ways of achieving the same goal.


    An array is a variable type which I do not foresee many people using when it comes to GPC scripting.
      As such I will not be covering it at this time, but I will at some point down the road update this tutorial to include it as well.

    Note: I listed 4 types of variables. This is not accurate. Realistically there are 3 types of variables. I say that "define" and "int" are two types of variables. This is a lie! These two words are used to create variables, but they are not actually variables themselves.
    You can type:
    define RapidFire_On = FALSE;
    But that would mean you could NOT turn it on. Booleans and Arrays are two types of variables you want to be able to edit... so I would not use "define" when creating these two types of variables. This is why I explained the types of variables the way I did.
Last edited by Elvish on Wed Nov 18, 2015 4:17 am, edited 5 times in total.
User avatar
Elvish
Captain
Captain
 
Posts: 531
Joined: Tue Jun 09, 2015 4:57 am

Re: Scripting Tutorials by Elvish

Postby Elvish » Wed Aug 26, 2015 2:47 am

Flow Control!

My roommate and I like to joke about programming, our favorite line being “A computer will ALWAYS do what you tell it to but not necessary what you want it to do.” That is to say if you write a program it will do everything EXACTLY as you write it, and it will do it this way every single time until you change something.

Before we jump into Flow Control there is something else we need to cover first. Operators!
    Operators are what we will use to compare data. Why would we need to compare data you may be asking? Well… Do you want your code to run EVERY time?! I honestly would not know how to “run the code every time.” One of the two main problems with that statement is that a computer does not know time, in order for a computer to know time we have to define time for it. The other problem being the fact that it would still not make sense to “run every time” after we define time for the computer. “Running every time” is an incomplete thought! You need to say something like “run every time 1 second passes” or “run differently every 5 times you execute.” So we use operators to make comparisons like these. Remember an operator will return true or false after comparing something. This will be explained once we have covered all of the operators.

    1. Equal “==” True if something equals something else.
      Example: “3 == 3” returns true, while “3 == 5” returns false.
    2. Not Equal “!=” True if two things are not equal to each other.
      Example: “3 != 5” returns true, while “3 != 3” returns false

    3. Less than “<” True if a number is less than another.
      Example: “3 < 5” Returns true, while “5 < 3” returns false
    4. Greater than “>” True if a number is greater than another.
      Example: “5 > 3” Returns true, while “ 3 > 5” returns false
    Note: Both Less than and Greater than can add an equals sign to become Greater than or equal to OR Less than or equal to.
      Example #1: “5 >= 5” will return true. While 5 is not greater than 5, it is equal to it.
      Example #2: “5 >= 6” will return false. 5 Is not greater than or equal to 6.
    5. Not “!” This is used to see if one this is not another.
      Example: “!Running” (where Running is a Boolean variable) will return True if the value of Running is currently false, or false if the value of Running is currently true.
    6. And “&&” Will return true if two separate statements are true and false if one or both of them are not.
      Example #1: “x == 3 && x == 4” We know this will return false because x can't be equal to both 3 and 4.
      Example #2: “x == 3 && y == 6” This will return true if the current value of x is 3 and the current value of y is 6. But if x is not currently 3 or y is not currently 6 then this will return false.
    7. Or “||” Will return true if one statement is true or the other statement is true.
      Example: “x == 3 or x == 5” will return true if x is currently equal to 3 or currently equal to 5.
    8. Xor “^^” Will return true if only one of the statements is true.
      Example: “x == 4 ^^ y == 4” If the current value of x is 4 and the current value of y is 7 this will return true. BUT if the current value of x is 4 and the current value of y is 4 it will return false, both statements cant be true if you want to return true.

Phew! Glad that's all over ;) Now to actually get into Flow Control.

Flow Control defined by Google: "In computer science, control flow (or alternatively, flow of control) refers to the order in which the individual statements, instructions or function calls of an imperative or a declarative program are executed or evaluated."

Flow Control defined by Elvish: Flow control defines what order of operations will happen. Do you remember PEMDOS from primary school? (Please Excuse My Dear Aunt Sally, or Parenthesis Exponents Multiplication Division Addition Subtraction?) This is a perfect example of flow control. You work through things in the order in which they are supposed to happen.

Types of Flow Control
The User's Manual states there are 4 separate ways to control the flow of your script. Note: These should always all be lowercase when using them in your scripts.
    1. If
    2. Else
    3. Else If
    4. While

Note: There are four possible scenarios which you can have with your if statements.
    #1. Just an If statement
    #2. An If statement and an Else statement
    #3. An If statement and a (or many) Else if statement(s)
    #4. An If statement, a (or many) Else If statement(s), and an Else statement.
You may not have an else or an else if without an initial if statement and you cant put the else statement before the else if statement(s).
Personally I lump If, Else, and Else If into the same category because in my mind they are all one and the same. They rely on each other to exist.


Remember when I said that operators will return true or false? Good! Because now we are getting to that.

If:
    If is probably the most important flow control piece you will use while coding! Basically you say “If this one thing is true, then do this other thing.”
    Example: If your username is Elvish then say “Hello World!”
    So I would say “Hello World!” because my username is Elvish. The statement is TRUE.
    But if you read that statement you would NOT say “Hello World!” The statement would be FALSE, because your username is not Elvish.
      Example:
      Code: Select all
      if(3 == 3){
      x = 7;
      }

      3 is equal to 3, so this statement is true. This statement is true so it will then execute “x = 7;”
      Where as:
      Code: Select all
      if(3 == 4){
      x = 7;
      }

      3 is not equal to 4, so this statement is false. This statement is false so it will NOT execute “x = 7;”
      Note #1: The initial bracket can be placed on the line below the if(3 == 3) but I leave it where it is because I feel as though it is easier to read what is going on in the code.
      Note #2: When you want to run code every line of code MUST end with a semi colon. This is to say if you want to change the value of a variable or execute any kind of code. Your if block will not end in a semi colon nor will your if statement which in this case is “3 == 3”

Else If:
    This can ONLY be used after an if block, and you can use as many else if statements as you want. The else if block will ONLY be read by the Titan One if the initial if block is found to be false. Remember when I said If, Else if, and Else were all tied together? The following examples will show you what I mean!
      Example #1:
      Code: Select all
      if(3 == 5){
          x = 1;
      }
      else if(3 == 3){
          x = 7;
      }

      In this instance the Titan one would say, 3 is not equal to 5 so skip over the first if block. Then it would see that 3 is in deed equal to 3 and read the following else if block. Changing the value of x to 7.

      Example #2
      Code: Select all
      if(3 == 5){
          x = 1;
      }
      else if(3 == 3){
          x = 7;
      }
      else if(7 == 7){
          x = 10;
      }

      In this instance the Titan one would say, 3 is not equal to 5 so skip over the first if block. Then it would see that 3 is in deed equal to 3 and read the following else if block. Changing the value of x to 7. The Titan One wold then skip over the rest of the else if statements (and the final else statement if you have one) because it found something in the if, else if, else group that was true. The Titan One will ONLY look for one instance of the group where the statement is true then skip the rest of the group.

      In order to do more then one calculation you would have to add another group such as the following:
      Code: Select all
      if(3 == 5){
          x = 1;
      }
      else if(3 == 3){
          x = 7;
      }
      else if(7 == 7){
          x = 10;
      }

      if(3 == 7){
          x = 4;
      }
      else if(8 == 8){
          x = 2;
      }

      Now in this instance the value of x would turn out to be 2.
      In this instance the Titan one would say, 3 is not equal to 5 so skip over the first if block. Then it would see that 3 is indeed equal to 3 and read the following else if block. Changing the value of x to 7. The Titan One wold then skip over the rest of the else if statements (and the final else statement if you have one) because it found something in the if, else if, else group that was true. BUT then the Titan one would read the next if statement because it is a new group. It would say 3 is not equal to 7, skip! 8 is equal to 8! And then change the value of x to 2.

Else:
    This is the easiest to follow piece of flow control. If the if statement and none of the else if statements were true, run this. That is to say, the else block does not compare any data, it just runs when no other cases are found to be true.
      Example:
      Code: Select all
      if(3 == 7){
          x = 4;
      }
      else if(8 == 3){
          x = 2;
      }
      else if(3 == 9){
          x = 8;
      }
      else{
          x = 17;
      }

      In this instance x would come out to 17 because none of the if or else if statements were true, leaving the else block to be read and executed.

While:
    The while loop is one of the less used ways of creating flow control (at least when it comes to Titan One scripting) But it can be useful none the less!
    The while loop will be read until the requirement is met. For example I could say, go forward while the light is green. Once the light turns yellow you would stop going forward. But up until that light turns yellow you can go as far as you want!
      Example:
      Code: Select all
      int x = 0;
      int y = 0;

      while(x < 5){
          x = x + 1;
          y = y + 2;
      }

      This while loop would run 5 times. X starts out at 0, and every time the while block is run it will add 1 to x. Thus at the end of the calculation x will be 5 and y will be 10.
        Run #1: Totals: x=0 y=0. Check: Is x less then 5? YES! Add 1 to x and add 2 to y.
        Run #2: Totals: x=1 y=2. Check: Is x less then 5? YES! Add 1 to x and add 2 to y.
        Run #3: Totals: x=2 y=4. Check: Is x less then 5? YES! Add 1 to x and add 2 to y.
        Run #4: Totals: x=3 y=6. Check: Is x less then 5? YES! Add 1 to x and add 2 to y.
        Run #5: Totals: x=4 y=8. Check: Is x less then 5? YES! Add 1 to x and add 2 to y.
        Run #6: Totals: x=5 y=10.Check: Is x less then 5? NO! End the while loop.
      Note: The while loop will continue to run without re-starting the main loop. This will be explained in the next post where we start to tie these concepts together.
Last edited by Elvish on Sat Nov 28, 2015 7:00 pm, edited 2 times in total.
User avatar
Elvish
Captain
Captain
 
Posts: 531
Joined: Tue Jun 09, 2015 4:57 am

Re: Scripting Tutorials by Elvish

Postby Elvish » Wed Aug 26, 2015 2:50 am

To Do: Tie these two concepts together
User avatar
Elvish
Captain
Captain
 
Posts: 531
Joined: Tue Jun 09, 2015 4:57 am

Re: Scripting Tutorials by Elvish

Postby perfecthuntr » Wed Aug 26, 2015 5:01 am

Not bad! This is the kind of initiative that this community needs. We greatly appreciate what you're doing! Keep it up!!

Also, I'll add that all int variable types can be used for Boolean checks as well. Essentially "int x = 0;" is the exact same thing as "int x = FALSE;" and even just "int x;" as this defaults to x=0. And one more point -- "int x = <any number other than 0>;" is the same thing as "int x = TRUE;". This is something to keep in mind because some people only like to use 1 and 0 instead of TRUE and FALSE.
ConsoleTuner Support Team
User avatar
perfecthuntr
Major
Major
 
Posts: 897
Joined: Wed Jan 14, 2015 8:35 am
Location: Tennessee

Re: Scripting Tutorials by Elvish

Postby J2Kbr » Sun Aug 30, 2015 12:00 pm

I'm totally with perfecthuntr. Great initiative. We should link this topic in the tutorials section.
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20322
Joined: Tue Mar 18, 2014 1:39 pm

Re: Scripting Tutorials by Elvish

Postby UK_Wildcats » Mon Aug 31, 2015 3:05 pm

Awesomeness
User avatar
UK_Wildcats
Brigadier General
Brigadier General
 
Posts: 2243
Joined: Thu Jan 08, 2015 6:53 pm

Re: Scripting Tutorials by Elvish

Postby Elvish » Mon Aug 31, 2015 6:59 pm

Oh gosh I assumed this thread was deleted! I could not find it haha. I will be updating it more tonight. Thanks for stickying!
User avatar
Elvish
Captain
Captain
 
Posts: 531
Joined: Tue Jun 09, 2015 4:57 am

Re: Scripting Tutorials by Elvish

Postby UK_Wildcats » Mon Nov 09, 2015 8:48 pm

Cannot wait to see what else you add to this.
User avatar
UK_Wildcats
Brigadier General
Brigadier General
 
Posts: 2243
Joined: Thu Jan 08, 2015 6:53 pm

Re: Scripting Tutorials by Elvish

Postby UK_Wildcats » Tue Apr 05, 2016 3:29 pm

As part of Gtuner there are pre-defined variables that are linked to index tables for the Titan 1 firmware. It just makes it easier to develop scripts than using index numbers. For example, PS3_R1, PS4_R1, XB1_RB, XB360_RB and WII_RT will allow represent index 3 by Gtuner. Any of these will work for a script regardless of which console.

http://www.consoletuner.com/kbase/data_representation.htm?mw=MjQw&st=MA==&sct=MA==&ms=AAAA
User avatar
UK_Wildcats
Brigadier General
Brigadier General
 
Posts: 2243
Joined: Thu Jan 08, 2015 6:53 pm

Next

Return to Tutorials and FAQs

Who is online

Users browsing this forum: No registered users and 8 guests