Page 1 of 1

Crash course to create your GPH Header file

PostPosted: Mon Apr 24, 2017 12:45 pm
by Prototype
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.

Re: Crash course to create your GPH Header file

PostPosted: Mon Apr 24, 2017 1:07 pm
by paname
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.

Re: Crash course to create your GPH Header file

PostPosted: Mon Apr 24, 2017 1:22 pm
by Prototype
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.

Re: Crash course to create your GPH Header file

PostPosted: Mon Apr 24, 2017 1:26 pm
by paname
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>

Re: Crash course to create your GPH Header file

PostPosted: Mon Apr 24, 2017 1:51 pm
by Prototype
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:

Re: Crash course to create your GPH Header file

PostPosted: Tue Apr 25, 2017 1:49 am
by antithesis
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.

Re: Crash course to create your GPH Header file

PostPosted: Tue Apr 25, 2017 2:37 pm
by J2Kbr
antithesis wrote:On that subject, can #include be called from anywhere in a T2 script?

yes, there is no restriction on this matter. :joia:

Re: Crash course to create your GPH Header file

PostPosted: Tue Apr 25, 2017 2:46 pm
by Prototype
Thanks for the tips guys, i'm going to begin to use Header files more efficiently!

Re: Crash course to create your GPH Header file

PostPosted: Wed Oct 17, 2018 1:16 pm
by xXSkyWalkerXx_1
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?

Re: Crash course to create your GPH Header file

PostPosted: Wed Oct 17, 2018 2:25 pm
by Scachi
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.