Page 6 of 7

Re: GPC2 Language Reference

PostPosted: Wed Jul 19, 2017 4:18 am
by antithesis
Thanks for the explanation J2K and thanks for the link paname.

Have you given any thought to additional aliases that provide more context than fix32 and int32? It's not necessary (I still don't get the difference between fix32 and int32), but it does dumb stuff down a bit for noobs.

Re: GPC2 Language Reference

PostPosted: Wed Jul 19, 2017 4:25 am
by pablosscripts
antithesis wrote:Thanks for the explanation J2K and thanks for the link paname.

Have you given any thought to additional aliases that provide more context than fix32 and int32? It's not necessary (I still don't get the difference between fix32 and int32), but it does dumb stuff down a bit for noobs.


Cool idea:) I'll add it to github!

Re: GPC2 Language Reference

PostPosted: Mon Jul 24, 2017 3:17 pm
by J2Kbr
Additional aliases are very easy to implement. I am open for suggestions :)

Re: GPC2 Language Reference

PostPosted: Mon Jul 24, 2017 5:57 pm
by pablosscripts
Ok just added this to github:

https://github.com/J2Kbr/GtunerIV/issues/165

Antithesis, if you have any suggestions now would be the time!

Re: GPC2 Language Reference

PostPosted: Tue Oct 17, 2017 10:46 am
by Shaag7
I was looking through the forums for all available datatypes explanation but wasn't successful.
I understand most of them, but I'm looking for following to have in Language Reference:
1. fix32 explanation(found some info in this thread)?
2. fix32 operations (i.e. I have adjustable antirecoil script, init value is i.e. 34, but when I printf the variable it gives me totally different number)?
3. is there any datatype to store alphanumerical strings (for display_overlay functions)?

There is snippet of my antirecoil adjustment for better explanation of my issue with fix32 operations:
Code: Select all
 
fix32 f_Recoil2               = 34.0;
...
if (l_AntiRecoil2 && !l_AntiRecoil3 && is_active(b_ADS) && !is_active(b_Fire) && i_WeaponType == 2) {
        if (event_active(b_Up)) {
            f_Recoil2 = f_Recoil2 - 1.0;
            printf("f_Recoil2:%d", f_Recoil2);
            }
        if (event_active(b_Down)) {
            f_Recoil2 = f_Recoil2 + 1.0;
            printf("f_Recoil2:%d", f_Recoil2);
            }
    }

I would like to add caps for adjustments like this, but due to my low know-how of this datatype and its operations / conversions, I'm stuck:
Code: Select all
        if (f_Recoil2 > 100) { f_Recoil2 = 100; }
        if (f_Recoil2 < -100) { f_Recoil2 = -100; }

Re: GPC2 Language Reference

PostPosted: Tue Oct 17, 2017 11:36 am
by J2Kbr
Shaag7 wrote:1. fix32 explanation(found some info in this thread)?

fix32 are number with decimal component. It is similar to float type in C. paname precisely explained the fix32 variable type here:
viewtopic.php?p=48931#p48931

Shaag7 wrote:2. fix32 operations (i.e. I have adjustable antirecoil script, init value is i.e. 34, but when I printf the variable it gives me totally different number)?

to print a fix32 use the %f format tag:
Code: Select all
printf("f_Recoil2:%f", f_Recoil2);

A list of all supported format tags can be found here:
https://www.consoletuner.com/wiki/index ... =t2:printf

Shaag7 wrote:3. is there any datatype to store alphanumerical strings (for display_overlay functions)?

The char type can be used to store string, example:
Code: Select all
char my_string[] = "My String";


However, for the display_overlay() function you need use an array with the bitmask of the characters:
Code: Select all
#pragma METAINFO("Display Overlay", 1, 0, "Example")
 
#include <display.gph>
 
main {
    combo_run(ShowString);
}
 
combo ShowString {
    const uint8 disp[] = { 0, _M_, _y_, 0, _S_, _t_, _r_, _i_, _n_, _g_ };
    static uint8 i;
 
    display_overlay(disp[i], 1000);
    if(++i >= sizeof(disp)) i = 0;
    wait(0);
 
    wait(980);
}
 

Re: GPC2 Language Reference

PostPosted: Tue Oct 17, 2017 11:43 am
by Shaag7
Thank you for fast response :smile0517: .
I haven't known that 'char' is supported.

When you (or someone other wise enough) have time, can we get full list of datatypes and their usage in Reference?
Thanks again :-)

Re: GPC2 Language Reference

PostPosted: Sat Jan 27, 2018 8:12 pm
by roidman
For noobs, where can we find references to simple things? I am having trouble with declaring a variable and then inverting it under a condition.

bool a = false;

if(....)
a=!a

does not work... I looked at the language reference and did not see anything there. I am surprised and impressed that some of you can do such in depth coding in this language, at this stage of documentation.

Edit: Declaring as int works, still it would be nice to get that documentation soon.

Re: GPC2 Language Reference

PostPosted: Sat Jan 27, 2018 10:57 pm
by Sillyasskid
roidman wrote:bool a = false;

if(....)
a=!a

does not work...


I'm assuming you initialized bool a. inside the main code block, like so:
Code: Select all
main{
bool a = FALSE;
if(...)
a=!a;
}

If this is correct?, then of course its not going to work lol. Because the main code block gets called every ms. and bool a is continuously going to be called, and assigned FALSE.

Here are a few ways to get around this.

You could make "bool a", a global variable instead, This is the ideal solution.
Example 1
Code: Select all
bool a = FALSE;
main{
if(...)
a=!a;
}


Another solution, would be to just declare bool a by it self. Don't assign it a value. when you place it in the main code block.
Example 2
Code: Select all
main{
bool a;
if(...)
a=!a;
}


A third solution, which is equivalent to the above example. Is to declare your variable as a static bool. A static type can be assigned a value, and you wont have to worry about the value being re-assigned every time the main code block is called. As it will remember its last state.
Example 3
Code: Select all
main{
static bool a = FALSE;
if(...)
a=!a;
}

although just keep in mind, static bool a = FALSE; is equivalent to just declaring bool a; by it self.
A static bool variable initialized in the main code block is beneficial, if you want to assign the value TRUE; So If you want to assign it FALSE, just stick with Example 2.

Re: GPC2 Language Reference

PostPosted: Tue Oct 30, 2018 6:18 pm
by captain
How do you do subroutines? I tried putting multiple combo_run in my main() and it BORKED the TitanTWO to hell. I mean seriously frakked it up. I had to HARD RESET the damn thing with two-button-holds and power cycling BS just to get it to work again at all. :-(

Here's what I'm talking about:

main {
while (keepalive = TRUE){
combo_run(DOSHIT);
combo_run(DOBETTERSHIT);
}
}