A question about a specific script and about making scripts

GPC1 script programming for Titan One. Code examples, questions, requests.

A question about a specific script and about making scripts

Postby ThisIsAnAcccountYo » Sat Apr 25, 2015 7:42 pm

So I am brand new to the T1 and I've don't know a single thing about scripting. I found this script http://www.consoletuner.com/gpclib/?s=192 on the gtuner search and I think it's pretty cool. However it only (that I can tell) toggles between blue and red. I'd like to be able to toggle between the 4 main controller colors (the ones assigned to different controller "slots" on the PS4) or even more color options if possible. Is that possible? How do determine what color is what and which ones you could use, and how would you go about writing/scripting that? I assigned the script to slot one and tested it out with the T1 hooked up to my computer. If I toggle the LED to red and switch back to 0 (I want to be on default so I don't accidentally change the color while playing) it reverts back to the default blue. Is there a way make save the color change stay between slots?

I'd like to try dabbling in making my own scripts. I'll probably just mess around with basic stuff for now like setting a button to turn off the controller, nothing like rapid fire type stuff that are in game packs. Are there any guides for what means what and how to write it? I haven't seen anything really in the forums so far. I saw the visual scripting tab on Gtuner but I don't understand it. Is there a tutorial for that?

Also if anyone knows of any interesting DS4 scripts I'd love to hear about them. When I searched on Gtuner for "DS4" and it didn't turn up much (though I'm not sure what all there could be).

Thanks!
User avatar
ThisIsAnAcccountYo
Master Sergeant
Master Sergeant
 
Posts: 28
Joined: Mon Apr 20, 2015 8:34 pm

Re: A question about a specific script and about making scri

Postby J2Kbr » Sun Apr 26, 2015 3:04 pm

ThisIsAnAcccountYo wrote:Is there a way make save the color change stay between slots?

Yes, there is. You can use persistent variables:
http://www.consoletuner.com/kbase/persi ... iables.htm

You can load the saved value on the init block, in the page linked above there is an example of that.

ThisIsAnAcccountYo wrote:Are there any guides for what means what and how to write it?

Very nice you are willing to learn the GPC scripting language. A good starting point the the language reference:
http://www.consoletuner.com/kbase/gpc_l ... erence.htm

Also check the Online Library, there you can learn from many documented codes from our users:
http://www.consoletuner.com/gpclib/

The Online Library is also accessible from Gtuner software. :)

ThisIsAnAcccountYo wrote:I saw the visual scripting tab on Gtuner but I don't understand it. Is there a tutorial for that?

The Visual Scripting can be a very nice way to learn the GPC language! you can drag and drop the Visual blocks and then generate the correspondent script.
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Re: A question about a specific script and about making scri

Postby perfecthuntr » Sun Apr 26, 2015 6:45 pm

ThisIsAnAcccountYo wrote:I'd like to be able to toggle between the 4 main controller colors (the ones assigned to different controller "slots" on the PS4) or even more color options if possible. Is that possible? How do determine what color is what and which ones you could use, and how would you go about writing/scripting that?

Take a look at the script that I just uploaded on the GPC library, here, and see if that will work for you. Here's a copy and paste of the script as well.
Code: Select all
/* =============================================================================================================================================
* Controller:           DualShock 4
* GPC Author:           PerfectHuntr
**/


/* ---------------------------------------------------------------------------------------------------------------------------------------------
* LED COLOR DEFINITIONS FOR PS4
* fSetLED(0,0,0,0);
// Off
* fSetLED(1,0,0,0); // Blue
* fSetLED(0,1,0,0); // Red
* fSetLED(0,0,1,0); // Green
* fSetLED(0,0,0,1); // Pink
* fSetLED(1,0,1,0); // Cyan
* fSetLED(0,1,1,0); // Amber
* fSetLED(1,1,1,1); // White
**/

/* ---------------------------------------------------------------------------------------------------------------------------------------------
* MAIN SCRIPT
**/

main {
    if (event_press(PS4_TOUCH))     { fSetLED(0,0,0,0); }   // TOUCH    = Off
    if (event_press(PS4_SQUARE))    { fSetLED(1,0,0,0); }   // SQUARE   = Blue
    if (event_press(PS4_TRIANGLE))  { fSetLED(0,1,0,0); }   // TRIANGLE = Red
    if (event_press(PS4_CIRCLE))    { fSetLED(0,0,1,0); }   // CIRCLE   = Green
    if (event_press(PS4_CROSS))     { fSetLED(0,0,0,1); }   // CROSS    = Pink
    if (event_press(PS4_LEFT))      { fSetLED(1,0,1,0); }   // LEFT     = Cyan
    if (event_press(PS4_UP))        { fSetLED(0,1,1,0); }   // UP       = Amber
    if (event_press(PS4_RIGHT))     { fSetLED(1,1,1,1); }   // RIGHT    = White
    if (event_press(PS4_DOWN))      { combo_run(Rainbow); } // DOWN     = Rainbow
}

/* ---------------------------------------------------------------------------------------------------------------------------------------------
* COMBOS
**/

// Rainbow LED combo for PS4
combo Rainbow {
    fSetLED(0,1,0,0); // Red
    wait(500);
    fSetLED(0,1,1,0); // Amber
    wait(500);
    fSetLED(0,0,1,0); // Green
    wait(500);
    fSetLED(1,0,0,0); // Blue
    wait(500);
    fSetLED(1,0,1,0); // Cyan
    wait(500);
    fSetLED(0,0,0,1); // Pink
    wait(500);
    fSetLED(1,1,1,1); // White
    wait(500);
    fSetLED(0,0,0,0); // Off
    wait(500);
}

/* ---------------------------------------------------------------------------------------------------------------------------------------------
* FUNCTIONS
**/

// LED function for PS4
function fSetLED(a, b, c, d) {
    set_led(LED_1, a);
    set_led(LED_2, b);
    set_led(LED_3, c);
    set_led(LED_4, d);
}
ConsoleTuner Support Team
User avatar
perfecthuntr
Major
Major
 
Posts: 897
Joined: Wed Jan 14, 2015 8:35 am
Location: Tennessee

Re: A question about a specific script and about making scri

Postby ThisIsAnAcccountYo » Sun Apr 26, 2015 8:44 pm

J2Kbr wrote:
ThisIsAnAcccountYo wrote:Is there a way make save the color change stay between slots?

Yes, there is. You can use persistent variables:
http://www.consoletuner.com/kbase/persi ... iables.htm

You can load the saved value on the init block, in the page linked above there is an example of that.


I looked at that but it's all gibberish to me haha. How would you apply that to Perfecthunter's script to make whatever LED is set stay on when I switch back to slot 0?
User avatar
ThisIsAnAcccountYo
Master Sergeant
Master Sergeant
 
Posts: 28
Joined: Mon Apr 20, 2015 8:34 pm

Re: A question about a specific script and about making scri

Postby perfecthuntr » Sun Apr 26, 2015 9:26 pm

ThisIsAnAcccountYo wrote:
J2Kbr wrote:You can use persistent variables:
http://www.consoletuner.com/kbase/persi ... iables.htm

You can load the saved value on the init block, in the page linked above there is an example of that.


I looked at that but it's all gibberish to me haha. How would you apply that to Perfecthunter's script to make whatever LED is set stay on when I switch back to slot 0?

I don't think you can actually make the LED stay the same color when you go to slot 0. That slot does not run any GPC scripts, it just makes it so that whatever controller you're using has it's inputs translated to whatever console you're using (if your OUTPUT PROTOCOL is set to AUTOMATIC). You could, however, make the LED stay the same color when switching between custom scripts using the persistent variables. There are 16 of them that can be used regardless of the memory slot you're on.

If you are using GamePacks though, those have code to change the LED depending on a number of parameters and will, therefore, not keep your LED color the same.

If you are using your own codes, let me know so I can write two example scripts for you.
ConsoleTuner Support Team
User avatar
perfecthuntr
Major
Major
 
Posts: 897
Joined: Wed Jan 14, 2015 8:35 am
Location: Tennessee

Re: A question about a specific script and about making scri

Postby ThisIsAnAcccountYo » Sun Apr 26, 2015 11:40 pm

perfecthuntr wrote:
ThisIsAnAcccountYo wrote:
J2Kbr wrote:You can use persistent variables:
http://www.consoletuner.com/kbase/persi ... iables.htm

You can load the saved value on the init block, in the page linked above there is an example of that.


I looked at that but it's all gibberish to me haha. How would you apply that to Perfecthunter's script to make whatever LED is set stay on when I switch back to slot 0?

I don't think you can actually make the LED stay the same color when you go to slot 0. That slot does not run any GPC scripts, it just makes it so that whatever controller you're using has it's inputs translated to whatever console you're using (if your OUTPUT PROTOCOL is set to AUTOMATIC). You could, however, make the LED stay the same color when switching between custom scripts using the persistent variables. There are 16 of them that can be used regardless of the memory slot you're on.

If you are using GamePacks though, those have code to change the LED depending on a number of parameters and will, therefore, not keep your LED color the same.

If you are using your own codes, let me know so I can write two example scripts for you.


I don't use gamepacks and for not I don't intend to. All I want is to have a slot with script to change the LED color, a slot programmed with a button to turn off the controller (which you already made a quick script for me on an earlier post), and a blank slot that is just all normal controls (like 0 is). and be able to cycle between the LED changer and normal controls while keeping the color. If that would be trickier then I could use just one slot with a script where swiping up on the touch pad cycles through all the LED colors (except off) and have everything else be normal, that way I wouldn't need to worry about the colors carrying over to other slots.

I haven't started writing or messing with codes on my own as I'll be quite busy the next week or two and I won't have time to start learning. I did try change the power off button to PS instead of up on the one script and try adjusting the numbers on your LED codes (ie "(2,0,0,0)" instead of "(1,0,0,0) but it either did nothing or was a color you already had set up.
User avatar
ThisIsAnAcccountYo
Master Sergeant
Master Sergeant
 
Posts: 28
Joined: Mon Apr 20, 2015 8:34 pm

Re: A question about a specific script and about making scri

Postby perfecthuntr » Mon Apr 27, 2015 3:05 am

ThisIsAnAcccountYo wrote:All I want is to have a slot with script to change the LED color, a slot programmed with a button to turn off the controller (which you already made a quick script for me on an earlier post), and a blank slot that is just all normal controls (like 0 is). and be able to cycle between the LED changer and normal controls while keeping the color.

Here's a simpler script that cycles through the LED colors with X and TRIANGLE, so you could load that onto Slot 1. For your slot that has normal controls, you can simply use a "blank" script that simply has nothing inside the main loop. Load this one onto Slot 2 since it has the LED recall functionality.

LED Color Changer
Code: Select all
/* =============================================================================================================================================
* Controller:           DualShock 4
* GPC Author:           PerfectHuntr
**/


/* ---------------------------------------------------------------------------------------------------------------------------------------------
* LED COLOR DEFINITIONS FOR PS4
* fSetLED(0,0,0,0);
// Off
* fSetLED(1,0,0,0); // Blue
* fSetLED(0,1,0,0); // Red
* fSetLED(0,0,1,0); // Green
* fSetLED(0,0,0,1); // Pink
* fSetLED(1,0,1,0); // Cyan
* fSetLED(0,1,1,0); // Amber
* fSetLED(1,1,1,1); // White
**/

/* -----------------------------------------------------------------------------
 *  VARIABLES
**/

int a, b, c, d, i, change;

/* -----------------------------------------------------------------------------
 *  INITIALIZATION
**/

init {
    a = get_pvar(PVAR_1, 0, 1, 0);
    b = get_pvar(PVAR_2, 0, 1, 0);
    c = get_pvar(PVAR_3, 0, 1, 0);
    d = get_pvar(PVAR_4, 0, 1, 0);
    if      (a == 0 && b == 1 && c == 0 && d == 0) { i = 0; }
    else if (a == 0 && b == 1 && c == 1 && d == 0) { i = 1; }
    else if (a == 0 && b == 0 && c == 1 && d == 0) { i = 2; }
    else if (a == 1 && b == 0 && c == 0 && d == 0) { i = 3; }
    else if (a == 1 && b == 0 && c == 1 && d == 0) { i = 4; }
    else if (a == 0 && b == 0 && c == 0 && d == 1) { i = 5; }
    else if (a == 1 && b == 1 && c == 1 && d == 1) { i = 6; }
    color(i);
}

/* ---------------------------------------------------------------------------------------------------------------------------------------------
* MAIN SCRIPT
**/

main {
    if (event_press(PS4_TRIANGLE))   { i = i+1; change = 1; }
    else if (event_press(PS4_CROSS)) { i = i-1; change = 1; }
    if      (i < 0) { i = 6; }
    else if (i > 6) { i = 0; }
    if (change) { change = 0; color(i); }
}

/* ---------------------------------------------------------------------------------------------------------------------------------------------
* FUNCTIONS
**/

// Color Lookup
function color(a) {
    if      (i == 0) { fSetLED(0,1,0,0); } // Red
    else if (i == 1) { fSetLED(0,1,1,0); } // Amber
    else if (i == 2) { fSetLED(0,0,1,0); } // Green
    else if (i == 3) { fSetLED(1,0,0,0); } // Blue
    else if (i == 4) { fSetLED(1,0,1,0); } // Cyan
    else if (i == 5) { fSetLED(0,0,0,1); } // Magenta
    else if (i == 6) { fSetLED(1,1,1,1); } // White
}

// LED function for PS4
function fSetLED(a, b, c, d) {
    set_led(LED_1, a);
    set_led(LED_2, b);
    set_led(LED_3, c);
    set_led(LED_4, d);
    set_pvar(PVAR_1, a);
    set_pvar(PVAR_2, b);
    set_pvar(PVAR_3, c);
    set_pvar(PVAR_4, d);
}


"Blank" Script with LED Color Recall
Code: Select all
/* =============================================================================================================================================
* Controller:           DualShock 4
* GPC Author:           PerfectHuntr
**/


/* ---------------------------------------------------------------------------------------------------------------------------------------------
* LED COLOR DEFINITIONS FOR PS4
* fSetLED(0,0,0,0);
// Off
* fSetLED(1,0,0,0); // Blue
* fSetLED(0,1,0,0); // Red
* fSetLED(0,0,1,0); // Green
* fSetLED(0,0,0,1); // Pink
* fSetLED(1,0,1,0); // Cyan
* fSetLED(0,1,1,0); // Amber
* fSetLED(1,1,1,1); // White
**/

/* -----------------------------------------------------------------------------
 *  INITIALIZATION
**/

init {
    fSetLED(get_pvar(PVAR_1, 0, 1, 0),
            get_pvar(PVAR_2, 0, 1, 0),
            get_pvar(PVAR_3, 0, 1, 0),
            get_pvar(PVAR_4, 0, 1, 0));
}

/* ---------------------------------------------------------------------------------------------------------------------------------------------
* MAIN SCRIPT
**/

main {
}

/* ---------------------------------------------------------------------------------------------------------------------------------------------
* FUNCTIONS
**/

// LED function for PS4
function fSetLED(a, b, c, d) {
    set_led(LED_1, a);
    set_led(LED_2, b);
    set_led(LED_3, c);
    set_led(LED_4, d);
}


ThisIsAnAcccountYo wrote:I did try change the power off button to PS instead of up on the one script and try adjusting the numbers on your LED codes (ie "(2,0,0,0)" instead of "(1,0,0,0) but it either did nothing or was a color you already had set up.

On the Dual Shock 4, the LED codes other than 1 and 0 don't work. You have to use a combination of 1's and 0's to produce different colors. If you want to blink the LED, then it can be done with the set_ledx() command, but currently that only supports one of the 4 main colors: blue, red, green, magenta. I've made a feature request to @J2Kbr to extend that functionality so that we could blink multiple LEDs at the same time (anything but DS4) or have various colors on the DS4 blink.

To change the power off button to PS, you can use this in the main loop:
Code: Select all
if (get_val(PS4_PS) && get_ptime(PS4_PS) > 1500) { set_val(PS4_PS, 0); turn_off(); }

That will make it so that you hold down the PS button for longer than 1.5 seconds and it will turn off the controller.
ConsoleTuner Support Team
User avatar
perfecthuntr
Major
Major
 
Posts: 897
Joined: Wed Jan 14, 2015 8:35 am
Location: Tennessee

Re: A question about a specific script and about making scri

Postby ThisIsAnAcccountYo » Mon Apr 27, 2015 6:35 am

I still don't know jack about this coding/scripting stuff, but I managed to finagle enough to slightly modify your scripts. Having 3 separate slots to toggle through seemed like a bit of a headache, so I combined the LED color switcher and the power off onto one script that wouldn't be triggered during normal gameplay/unintentionally. I changed the color change inputs from single buttons to a button combo (triangle and circle together goes one way, square and cross go the other, and made the power off press time longer.

However once I tested it out in gameplay I realized that pressing square/cross and triangle/circle still performs those buttons in gameplay. I wanted to change the led color inputs to swiping like this other guy's script http://www.consoletuner.com/gpclib/?s=192, but it was was too complicated for me to just cut and paste bits in. I'd like to use a modified version of his inputs so swiping up "goes up" in the colors and swiping down goes down. Would you be able to help me do that?

Here's my modified version (I only modified the "Main" section):
Code: Select all
/* =============================================================================================================================================
* Controller:           DualShock 4
* GPC Author:           PerfectHuntr
**/


/* ---------------------------------------------------------------------------------------------------------------------------------------------
* LED COLOR DEFINITIONS FOR PS4
* fSetLED(0,0,0,0);
// Off
* fSetLED(1,0,0,0); // Blue
* fSetLED(0,1,0,0); // Red
* fSetLED(0,0,1,0); // Green
* fSetLED(0,0,0,1); // Pink
* fSetLED(1,0,1,0); // Cyan
* fSetLED(0,1,1,0); // Amber
* fSetLED(1,1,1,1); // White
**/

/* -----------------------------------------------------------------------------
 *  VARIABLES
**/

int a, b, c, d, i, change;

/* -----------------------------------------------------------------------------
 *  INITIALIZATION
**/

init {
    a = get_pvar(PVAR_1, 0, 1, 0);
    b = get_pvar(PVAR_2, 0, 1, 0);
    c = get_pvar(PVAR_3, 0, 1, 0);
    d = get_pvar(PVAR_4, 0, 1, 0);
    if      (a == 0 && b == 1 && c == 0 && d == 0) { i = 0; }
    else if (a == 0 && b == 1 && c == 1 && d == 0) { i = 1; }
    else if (a == 0 && b == 0 && c == 1 && d == 0) { i = 2; }
    else if (a == 1 && b == 0 && c == 0 && d == 0) { i = 3; }
    else if (a == 1 && b == 0 && c == 1 && d == 0) { i = 4; }
    else if (a == 0 && b == 0 && c == 0 && d == 1) { i = 5; }
    else if (a == 1 && b == 1 && c == 1 && d == 1) { i = 6; }
    color(i);
}

/* ---------------------------------------------------------------------------------------------------------------------------------------------
* MAIN SCRIPT
**/

main {
    if((event_press(PS4_TRIANGLE)) && (event_press(PS4_CIRCLE))) { i = i+1; change = 1; }
    else if((event_press(PS4_SQUARE)) && (event_press(PS4_CROSS))) { i = i-1; change = 1; }
    if      (i < 0) { i = 6; }
    else if (i > 6) { i = 0; }
    if (change) { change = 0; color(i); }
    if (get_val(PS4_PS) && get_ptime(PS4_PS) > 3000) { set_val(PS4_PS, 0); turn_off(); }
}

/* ---------------------------------------------------------------------------------------------------------------------------------------------
* FUNCTIONS
**/

// Color Lookup
function color(a) {
    if      (i == 0) { fSetLED(0,1,0,0); } // Red
    else if (i == 1) { fSetLED(0,1,1,0); } // Amber
    else if (i == 2) { fSetLED(0,0,1,0); } // Green
    else if (i == 3) { fSetLED(1,0,0,0); } // Blue
    else if (i == 4) { fSetLED(1,0,1,0); } // Cyan
    else if (i == 5) { fSetLED(0,0,0,1); } // Magenta
    else if (i == 6) { fSetLED(1,1,1,1); } // White
}

// LED function for PS4
function fSetLED(a, b, c, d) {
    set_led(LED_1, a);
    set_led(LED_2, b);
    set_led(LED_3, c);
    set_led(LED_4, d);
    set_pvar(PVAR_1, a);
    set_pvar(PVAR_2, b);
    set_pvar(PVAR_3, c);
    set_pvar(PVAR_4, d);
}


Thanks so much for your help!
User avatar
ThisIsAnAcccountYo
Master Sergeant
Master Sergeant
 
Posts: 28
Joined: Mon Apr 20, 2015 8:34 pm

Re: A question about a specific script and about making scri

Postby perfecthuntr » Wed Apr 29, 2015 11:50 pm

ThisIsAnAcccountYo wrote:However once I tested it out in gameplay I realized that pressing square/cross and triangle/circle still performs those buttons in gameplay. I wanted to change the led color inputs to swiping like this other guy's script http://www.consoletuner.com/gpclib/?s=192, but it was was too complicated for me to just cut and paste bits in. I'd like to use a modified version of his inputs so swiping up "goes up" in the colors and swiping down goes down. Would you be able to help me do that?


That script is pretty rough-looking. I am not really sure what's going on with that thing. It's not very descriptive and uses random variable names like w, x, and z. I also don't know if the script is doing everything correctly there. This would take a lot of work to get correct. What if we changed it so the button combinations had to be held down for a certain period of time before anything happened (similar to how the gamepacks use the menu system)?
ConsoleTuner Support Team
User avatar
perfecthuntr
Major
Major
 
Posts: 897
Joined: Wed Jan 14, 2015 8:35 am
Location: Tennessee

Re: A question about a specific script and about making scri

Postby ThisIsAnAcccountYo » Thu Apr 30, 2015 4:24 pm

perfecthuntr wrote:
ThisIsAnAcccountYo wrote:However once I tested it out in gameplay I realized that pressing square/cross and triangle/circle still performs those buttons in gameplay. I wanted to change the led color inputs to swiping like this other guy's script http://www.consoletuner.com/gpclib/?s=192, but it was was too complicated for me to just cut and paste bits in. I'd like to use a modified version of his inputs so swiping up "goes up" in the colors and swiping down goes down. Would you be able to help me do that?


That script is pretty rough-looking. I am not really sure what's going on with that thing. It's not very descriptive and uses random variable names like w, x, and z. I also don't know if the script is doing everything correctly there. This would take a lot of work to get correct. What if we changed it so the button combinations had to be held down for a certain period of time before anything happened (similar to how the gamepacks use the menu system)?


Yeah even with my non-existent knowledge of scripting, it looked like a lot of mess to me. Do you know a cleaner way to turn swiping the touch pad one way an input? Also I'm not quite sure I understand your alternative. Is there a way to make it so a button combo doesn't make any "normal input"?

Are you saying it's possible to make it so when triangle/circle or square/cross are pressed simultaneously that the game won't receive an triangle or circle input? If so, that could work. I mean it's honestly not any big deal as it is right now. It's just that the touchpad isn't used for anything and it's ideal to use for color switching.

Either way I very much appreciate your help!
User avatar
ThisIsAnAcccountYo
Master Sergeant
Master Sergeant
 
Posts: 28
Joined: Mon Apr 20, 2015 8:34 pm

Next

Return to GPC1 Script Programming

Who is online

Users browsing this forum: No registered users and 93 guests