GPC2 language reference

GPC2 script programming for Titan Two. Code examples, questions, requests.

Re: GPC2 language reference

Postby pablosscripts » Wed Sep 07, 2016 8:43 am

bonefisher wrote:I still didn't look at it no no no not me lol! Might be best if you take baby steps by writing small code first then progress into the full script. I'm waiting so I can see results working with short scripts and trying all the new goodies it can do.


Lol I couldn't resist. I'm going to tear into this like a bucket of KFC.
Setup: XIM Apex, T2, K780 keyboard, G Pro Wireless mouse, SteelSeries 4HD pad, DXRacer armrest, LucidSound LS30 headset, Netduma router, Ubiquiti UniFi AP LR

My R6 script: https://youtu.be/x-9NtxyySVM
User avatar
pablosscripts
Brigadier General
Brigadier General
 
Posts: 1976
Joined: Tue Nov 24, 2015 6:27 am

Re: GPC2 language reference

Postby bonefisher » Wed Sep 07, 2016 8:46 am

:joia: lol!
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am

Re: GPC2 language reference

Postby PaulaTheKoala » Wed Sep 07, 2016 11:17 am

pablogroup wrote:Hell yes!

I've made some progress.

This very simple comparison kept throwing an error:

Code: Select all
if(get_val(MOV_Y_AXIS) <= -97)


I noticed it worked fine when I removed the comparison:

Code: Select all
if(get_val(MOV_Y_AXIS))


It then dawned on me that it was because it wasn't comparing two int values, so I converted the button press value to an int:

Code: Select all
if((int) get_val(MOV_Y_AXIS) <= -97)


And it worked! I wish J2Kbr was here to say whether I'm on the right track or not, it feels like I'm hacking my script into oblivion here lol


I don't think casting to int would be a problem, I started doing this aswell but due to lots of lines in my script it was easier to change a few ints to fix32. :P

If you don't want to do lots of casting and keep your variables as int, you could always create and use your own function:

Code: Select all
int get_val2(uint8 input)
{
    return (int) get_val(input);
}
User avatar
PaulaTheKoala
Command Sergeant Major
Command Sergeant Major
 
Posts: 131
Joined: Wed Aug 26, 2015 3:45 am

Re: GPC2 language reference

Postby pablosscripts » Wed Sep 07, 2016 12:03 pm

PaulaTheKoala wrote:I started doing this as well but due to lots of lines in my script it was easier to change a few ints to fix32. :P


How do you do fix32? Bear in mind I'm not a programmer!
Setup: XIM Apex, T2, K780 keyboard, G Pro Wireless mouse, SteelSeries 4HD pad, DXRacer armrest, LucidSound LS30 headset, Netduma router, Ubiquiti UniFi AP LR

My R6 script: https://youtu.be/x-9NtxyySVM
User avatar
pablosscripts
Brigadier General
Brigadier General
 
Posts: 1976
Joined: Tue Nov 24, 2015 6:27 am

Re: GPC2 language reference

Postby PaulaTheKoala » Wed Sep 07, 2016 12:13 pm

pablogroup wrote:
PaulaTheKoala wrote:I started doing this as well but due to lots of lines in my script it was easier to change a few ints to fix32. :P


How do you do fix32? Bear in mind I'm not a programmer!


Add a f after the number, for example:

Code: Select all
main
{
   if (get_val(BUTTON_1) > 20f)
   {
        // do stuff
   }
}


Same applies for defining a variable:

Code: Select all
main
{
   fix32 some_variable = 20f;

   if (get_val(BUTTON_1) > some_variable)
   {
        // do stuff
   }
}
User avatar
PaulaTheKoala
Command Sergeant Major
Command Sergeant Major
 
Posts: 131
Joined: Wed Aug 26, 2015 3:45 am

Re: GPC2 language reference

Postby pablosscripts » Wed Sep 07, 2016 12:20 pm

PaulaTheKoala wrote:
pablogroup wrote:
PaulaTheKoala wrote:I started doing this as well but due to lots of lines in my script it was easier to change a few ints to fix32. :P


How do you do fix32? Bear in mind I'm not a programmer!


Add a f after the number, for example:

Code: Select all
main
{
   if (get_val(BUTTON_1) > 20f)
   {
        // do stuff
   }
}


Same applies for defining a variable:

Code: Select all
main
{
   fix32 some_variable = 20f;

   if (get_val(BUTTON_1) > some_variable)
   {
        // do stuff
   }
}


In that last example, do you still need the "fix32" there since you've already added an "f"?
Setup: XIM Apex, T2, K780 keyboard, G Pro Wireless mouse, SteelSeries 4HD pad, DXRacer armrest, LucidSound LS30 headset, Netduma router, Ubiquiti UniFi AP LR

My R6 script: https://youtu.be/x-9NtxyySVM
User avatar
pablosscripts
Brigadier General
Brigadier General
 
Posts: 1976
Joined: Tue Nov 24, 2015 6:27 am

Re: GPC2 language reference

Postby PaulaTheKoala » Wed Sep 07, 2016 12:33 pm

pablogroup wrote:In that last example, do you still need the "fix32" there since you've already added an "f"?


Yup, this is because we are declaring a new variable of type fix32 with the name 'some_variable' and a value of '20f'.

It basically goes like this:
<data type> <variable name> = <value>;

So If you wanted an integer:
Code: Select all
int some_variable = 20;


or fix32:
Code: Select all
fix32 some_variable = 20f;


or boolean:
Code: Select all
bool some_variable = FALSE;
User avatar
PaulaTheKoala
Command Sergeant Major
Command Sergeant Major
 
Posts: 131
Joined: Wed Aug 26, 2015 3:45 am

Re: GPC2 language reference

Postby pablosscripts » Wed Sep 07, 2016 12:45 pm

Cool thanks for that, I'm slowly building up my knowledge in C as I do this. It's a good learning experience:)

I was quite pleased that I managed to solve the int problem on my own!
Setup: XIM Apex, T2, K780 keyboard, G Pro Wireless mouse, SteelSeries 4HD pad, DXRacer armrest, LucidSound LS30 headset, Netduma router, Ubiquiti UniFi AP LR

My R6 script: https://youtu.be/x-9NtxyySVM
User avatar
pablosscripts
Brigadier General
Brigadier General
 
Posts: 1976
Joined: Tue Nov 24, 2015 6:27 am

Re: GPC2 language reference

Postby PaulaTheKoala » Wed Sep 07, 2016 12:50 pm

pablogroup wrote:Cool thanks for that, I'm slowly building up my knowledge in C as I do this. It's a good learning experience:)

I was quite pleased that I managed to solve the int problem on my own!


Glad to help, I generally deal with C# and Java (which IMO are pretty similar to C in some areas) so I have the basics but I'm still learning as well. :P
User avatar
PaulaTheKoala
Command Sergeant Major
Command Sergeant Major
 
Posts: 131
Joined: Wed Aug 26, 2015 3:45 am

Re: GPC2 language reference

Postby FCB77 » Wed Sep 07, 2016 10:00 pm

i tried to convert my old fifa16 script and after some trial and error it finally compiled without errors.
my old fifa script for T1 had a lot of commented code because it used all 100% T1 memory, now i uncommented the code for T2 and it says it is using only 14%
GPC: Memory usage: Static: 152 bytes (14.84%), Dynamic: 16 bytes (1.56%)
lol there is a lot of space in T2. :smile0202:
User avatar
FCB77
Command Sergeant Major
Command Sergeant Major
 
Posts: 138
Joined: Sun Feb 01, 2015 9:21 am

PreviousNext

Return to GPC2 Script Programming

Who is online

Users browsing this forum: midg3t2 and 114 guests