Crash course to create your GPH Header file

Gtuner IV general support. Operation, questions, updates, feature request.

Crash course to create your GPH Header file

Postby prototype » Mon Apr 24, 2017 12:45 pm

Here is an example on how to use an header file to use several scripts in one, create a new gph file and paste that according to your gph file name at the top of your script:
Code: Select all
#ifndef My_Layout_
#define My_Layout_GPH_
 

And paste that at the end of your script:
Code: Select all
#endif /* My_Layout_GPH_ */
 


Code: Select all
#ifndef My_Layout_
#define My_Layout_GPH_
 
#include <keyboard.gph>
#include <mouse.gph>
 
main {
// For the keyboard
    if(key_status(KEY_A)) {
        set_val(BUTTON_15, 100);
    }
    if(key_status(KEY_B)) {
        set_val(BUTTON_15, 100);
    }
// For the mouse
    if(key_status(MBUTTON_1)) {
        set_val(BUTTON_15, 100);
    }
    if(key_status(MBUTTON_2)) {
        set_val(BUTTON_15, 100);
    }
}
 
#endif /* My_Layout_GPH_ */
 

You can create any script or function as gph and use it with any other script.

paste that according to your gph file name and location at the top of your script to use your header file:
Code: Select all
#include <C:/GtunerIVBeta/Layout/My_Layout.gph>
 
main {
 
}


If you see anything to add please comment.
Console tuner since my 1st controller.
Believe or dare, It's Titanic! :smile0517:
User avatar
prototype
Brigadier General
Brigadier General
 
Posts: 2919
Joined: Sun Dec 16, 2012 1:43 pm

Re: Crash course to create your GPH Header file

Postby paname » Mon Apr 24, 2017 1:07 pm

you can use something like:

Code: Select all
 
#include "include/My_Layout.gph"
 


to have a relative more portable path and put all your gph file in include directory (or any other , just change the name)

you should also have 2 type of variables:
- those you can restrict to a single gph file and as a good practice prefix them with the file name e.g.: layout_var1 layout_var2
- those you will use in multiple gph files

for the later it it better to define them in a common.gph file that you will #include first (the order matter)
also you should start to convert all the get_val() to get_actual() otherwise your script may act oddly depending on the order you call the include files.
these are emu personal tips after i "modularised" one of my script.
Last edited by paname on Mon Apr 24, 2017 1:23 pm, edited 1 time in total.
User avatar
paname
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 199
Joined: Wed Jan 07, 2015 3:02 pm

Re: Crash course to create your GPH Header file

Postby prototype » Mon Apr 24, 2017 1:22 pm

Yes that's what i usually do but it's easy to have those files in separated folders.
I forgot to specify that, thanks for your input.
Console tuner since my 1st controller.
Believe or dare, It's Titanic! :smile0517:
User avatar
prototype
Brigadier General
Brigadier General
 
Posts: 2919
Joined: Sun Dec 16, 2012 1:43 pm

Re: Crash course to create your GPH Header file

Postby paname » Mon Apr 24, 2017 1:26 pm

what i mean is you can do :

Code: Select all
#include "module1/file1.gph"
#include "module2/file2.gph"
#include "module3/file3.gph"


no need to put

Code: Select all
#include <C:/DD/DD//D//D/module1/file1.gph>
#include <C:/DD/DD//D//D/module2/file2.gph>
#include <C:/DD/DD//D//D/module3/file3.gph>
User avatar
paname
Sergeant Major of the Army
Sergeant Major of the Army
 
Posts: 199
Joined: Wed Jan 07, 2015 3:02 pm

Re: Crash course to create your GPH Header file

Postby prototype » Mon Apr 24, 2017 1:51 pm

I don't use so much header files and they are not all in my include folder but yes you can do both as you like :joia:
Console tuner since my 1st controller.
Believe or dare, It's Titanic! :smile0517:
User avatar
prototype
Brigadier General
Brigadier General
 
Posts: 2919
Joined: Sun Dec 16, 2012 1:43 pm

Re: Crash course to create your GPH Header file

Postby antithesis » Tue Apr 25, 2017 1:49 am

A relative path is simpler and more robust, but absolute will work.

Using includes (preferably relative) is definitely the way forward for compartmentalisation and code maintenance, and will greatly expedite script development.

Good candidates for headers are bindings, combos and functions that are typically recycled from script to script.

On that subject, can #include be called from anywhere in a T2 script? I'm still largely splashing around the T1 kiddy pool and have yet to dive into serious T2 scripting.
Official Australian retailer for Titan One, Titan Two and XIM APEX at Mod Squad
User avatar
antithesis
Colonel
Colonel
 
Posts: 1709
Joined: Sat May 28, 2016 10:45 pm

Re: Crash course to create your GPH Header file

Postby J2Kbr » Tue Apr 25, 2017 2:37 pm

antithesis wrote:On that subject, can #include be called from anywhere in a T2 script?

yes, there is no restriction on this matter. :joia:
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 17942
Joined: Tue Mar 18, 2014 1:39 pm

Re: Crash course to create your GPH Header file

Postby prototype » Tue Apr 25, 2017 2:46 pm

Thanks for the tips guys, i'm going to begin to use Header files more efficiently!
Console tuner since my 1st controller.
Believe or dare, It's Titanic! :smile0517:
User avatar
prototype
Brigadier General
Brigadier General
 
Posts: 2919
Joined: Sun Dec 16, 2012 1:43 pm

Re: Crash course to create your GPH Header file

Postby xXSkyWalkerXx_1 » Wed Oct 17, 2018 1:16 pm

When I try to include a headfile of my PC with:
Code: Select all
#include "DisplayPrinter.gph"


But when I enter the full path of this headerfile it works, what's the issue?
Check out my YouTube Channel: https://www.youtube.com/c/xXSkyWalkerXx1
& my website: https://skymodz.com
User avatar
xXSkyWalkerXx_1
Sergeant Major
Sergeant Major
 
Posts: 106
Joined: Thu Sep 13, 2018 11:05 am
Location: Germany

Re: Crash course to create your GPH Header file

Postby Scachi » Wed Oct 17, 2018 2:25 pm

The one without the path will only work if the header file is located in the same directory as your script you have this line in.
It works too if the header file is in the include directory of your gtuner software. But don't do that, that is bad practice.
This directory should only be used by the header files that comes with the gtuner software itself.

Take a look on relative paths for include files some way up in this thread or google for it.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 2242
Joined: Wed May 11, 2016 6:25 am
Location: Germany


Return to Gtuner IV Support (Titan Two)

Who is online

Users browsing this forum: No registered users and 19 guests