GPC2 Language Reference

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

Re: GPC2 Language Reference

Postby Scachi » Tue Oct 30, 2018 6:20 pm

captain wrote:How do you do subroutines? I tried putting multiple combo_run in my main() and it BORKED the TitanTWO to hell.

This may be cause by using led or segment display within combos without a wait(0); behind those commands
or using those functions in main directly without toggle/event_.. actions.

Post your code and we should be able to help you.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: GPC2 Language Reference

Postby captain » Tue Oct 30, 2018 6:30 pm

Oh! I didn't realize that EVERY command needed a wait(x); behind it. I assumed that if wait was 0 that I could just leave it out. Facepalm. I'll put those back in and see if it works. But calling multiple combo_runs in main() should be okay, right? And it should loop through them forever, as I wrote it?
User avatar
captain
Staff Sergeant
Staff Sergeant
 
Posts: 12
Joined: Sat Oct 27, 2018 6:16 pm

Re: GPC2 Language Reference

Postby captain » Tue Oct 30, 2018 6:45 pm

Code: Select all
#pragma METAINFO("Suicide Squad Infected", 1, 09, "captain")
#include <ps4.gph>
 
bool keepalive = TRUE;
 
main {
    while (keepalive == TRUE){
        combo_run(ENTERTHEDRAGON);
        combo_run(WHACK);
        combo_run(SUICIDE);
        combo_run(STEPSPINWHACK);
    }
}
 
combo ENTERTHEDRAGON {
    /* select load out (then jump in game) */
    set_val(PS4_CROSS, 100);
    wait(50);
    set_val(PS4_CROSS, 0);
    wait(250);
}
combo WHACK {
        // whack x4
    set_val(PS4_R3, 100);
    wait(10);
    set_val(PS4_R3, 0);
    wait(50);
    set_val(PS4_R3, 100);
    wait(10);
    set_val(PS4_R3, 0);
    wait(50);   
    set_val(PS4_R3, 100);
    wait(10);
    set_val(PS4_R3, 0);
    wait(50);
    set_val(PS4_R3, 100);
    wait(10);
    set_val(PS4_R3, 0);
    wait(0);
}
combo SUICIDE {
    // suicide: throw smoke (or plant insertion flare), then cook grenade (or do nothing for 5 seconds)
    set_val(PS4_L2, 100);
    wait(50);
    set_val(PS4_L2, 0);
    wait(0);
    set_val(PS4_R2, 100);
    wait(5000);
    set_val(PS4_R2, 0);
    wait(0);
}
combo STEPSPINWHACK{            // step left, whack, and turn left
    set_val(STICK_2_X, -100);
    wait(50);
    set_val(STICK_2_X, 0);
    wait(0);
    set_val(PS4_CROSS, 100);
    wait(10);
    set_val(PS4_CROSS, 0);
    wait(0);
    set_val(STICK_1_X, -100);
    wait(500);
    set_val(STICK_1_X, 0);
    wait(0);
}


When I compile that without error, and transfer it to Memory Slot 5, it transfers over fine. But when I switch TitanTWO to "5" all the lights flash in a PANIC, the unit appears to power cycle, and it fortunately reverts back to "4" which is a simple combo_run (WHACK);
User avatar
captain
Staff Sergeant
Staff Sergeant
 
Posts: 12
Joined: Sat Oct 27, 2018 6:16 pm

Re: GPC2 Language Reference

Postby Scachi » Tue Oct 30, 2018 6:55 pm

The wait(0); is very important for using function inside of combos to ensure they are only run once. led_vmset and rumble calls from within a combo without wait(0); behind them may disconnect controller when used wireless or result in reboot of the T2 as they may overload the connection to the controller.

For a combo everything between two wait(...) calls is repeated until the wait time es reached.

Code: Select all
 
combo example1 {
  printf("write overflow"); // this printf will be called every 1ms at minimum for 100ms, not so good
  wait(100);
  printf("written once");
  wait(0);                       // this well be only written once
 
  set_val(BUTTON_14,100); // this will press the button_14 for 200ms
  wait(200);             
  wait(200);     // this will release the button_14 for 200ms
}


Your combos in your code are all running at the same time if this is what you want. But I can't see a problem that can cause trouble for the t2.
If you want to run them one after another you can create an additional combo and use the call command to start those.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: GPC2 Language Reference

Postby captain » Tue Oct 30, 2018 7:07 pm

Ah! I have a better understanding of wait(x); now! Thanks!

Apparently one problem is that " while (keepalive == TRUE){" is not working as I expected. When I remove that line, all subroutines do in fact run at the same time, and the T2 doesn't crash! What's the proper syntax for calling one subroutine after another, then repeating the loop?
User avatar
captain
Staff Sergeant
Staff Sergeant
 
Posts: 12
Joined: Sat Oct 27, 2018 6:16 pm

Re: GPC2 Language Reference

Postby Scachi » Tue Oct 30, 2018 7:07 pm

The while loop if the problem. It does run the code in it without ever leaving this loop, never being able to run the "main {} loop again. This causes the reboot of the T2.

This should do the same as your code, but running one after the other.
I removed the set_val(button,0); lines as the second wait directly after the press wait will do the same. This saves some space.
Those wait(0); after the button press are doing nothing in this case as far as I know.
Use a wait time >0 if you want to have the previous button released for some time before the next button press happens.

the "call" function does run the combo, waits for it to complete, then runs the next call command, waiting for this combo to complete, and so on until it reached the end of the combo looper. The main loop "if" statement will start the looper combo again after it has finished.

Code: Select all
#pragma METAINFO("Suicide Squad Infected", 1, 09, "captain")
#include <ps4.gph>
 
bool keepalive = TRUE;
 
main {
    if (keepalive == TRUE)  combo_run(looper);
}
 
combo looper {
        call(ENTERTHEDRAGON);
        call(WHACK);
        call(SUICIDE);
        call(STEPSPINWHACK);
}
 
combo ENTERTHEDRAGON {
    /* select load out (then jump in game) */
    set_val(PS4_CROSS, 100);
    wait(50);
    wait(250);
}
combo WHACK {
        // whack x4
    set_val(PS4_R3, 100);
    wait(10);
    wait(50);
    set_val(PS4_R3, 100);
    wait(10);
    wait(50);   
    set_val(PS4_R3, 100);
    wait(10);
    wait(50);
    set_val(PS4_R3, 100);
    wait(10);
    wait(0);
}
 
combo SUICIDE {
    // suicide: throw smoke (or plant insertion flare), then cook grenade (or do nothing for 5 seconds)
    set_val(PS4_L2, 100);
    wait(50);
    wait(0);
    set_val(PS4_R2, 100);
    wait(5000);
    wait(0);
}
combo STEPSPINWHACK{            // step left, whack, and turn left
    set_val(STICK_2_X, -100);
    wait(50);
    wait(0);
    set_val(PS4_CROSS, 100);
    wait(10);
    wait(0);
    set_val(STICK_1_X, -100);
    wait(500);
    wait(0);
}
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: GPC2 Language Reference

Postby captain » Tue Oct 30, 2018 9:27 pm

So wait(x); really means "do the previous command for x miliseconds". Interesting way of doing things. I also figured out that I need to do "nothing" after certain actions to allow the game to complete the action. It's nice to know that I can multiplex actions, but I don't know how to sync them. That'll have to be another lesson another time. :-)
User avatar
captain
Staff Sergeant
Staff Sergeant
 
Posts: 12
Joined: Sat Oct 27, 2018 6:16 pm

Previous

Return to Tutorials and FAQs

Who is online

Users browsing this forum: No registered users and 23 guests