Efficient printf method?

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

Re: Efficient printf method?

Postby bonefisher » Tue Jul 25, 2017 9:46 am

Mine too! I just see the code don't understand it but learn something every day! :smile0517:
bonefisher
Lieutenant General
Lieutenant General
 
Posts: 5413
Joined: Thu Jan 29, 2015 10:49 am

Re: Efficient printf method?

Postby antithesis » Tue Jul 25, 2017 10:03 am

bonefisher wrote:Mine too! I just see the code don't understand it but learn something every day! :smile0517:

The training wheels are bolted back onto my GPC bike! I know what I want to do, but it's a little frustrating not knowing how to do it :sad panda:

The second part of this quest involves outputting those printf statements to a Raspberry Pi or Arduino screen. That's a much steeper learning curve before I get there...
Official Australian retailer for Titan One, Titan Two and XIM APEX at Mod Squad
User avatar
antithesis
Colonel
Colonel
 
Posts: 1912
Joined: Sat May 28, 2016 10:45 pm

Re: Efficient printf method?

Postby FCB77 » Tue Jul 25, 2017 3:52 pm

[quote="J2Kbr"]
The correct initialization of an array of strings is:
Code: Select all
main {
    char *SkillModes[] = {
        "Skill: None", "Skill: BallRoll", "Skill: BodyFeintCut", "Skill: ReversoStepOverCut", "Skill: HeelFlick2",
        "Skill: HeelFlick", "Skill: FakeAndGo", "Skill: Roulette", "Skill: Rainbow", "Skill: StopAndTurn",
        "Skill: Spin", "Skill: RonaldoChop", "Skill: BallRollFlick", "Skill: ElasticoChop", "Skill: BolasieFlick",
        "Skill: KnockOn", "Skill: StepOverCut", "Skill: FlickUP", "Skill: FakeShotStop", "Skill: FakeShotBallHop",
        "Skill: AdvRainbow", "Skill: ScoopTurn", "Skill: HocusPocusElastico"
    };
 


oh yeah char pointer, duh!,

instead of an array of string , is it possible to do an array of combos? and then do

combo_run(comboArray[comboIndex]);
User avatar
FCB77
Command Sergeant Major
Command Sergeant Major
 
Posts: 138
Joined: Sun Feb 01, 2015 9:21 am

Re: Efficient printf method?

Postby J2Kbr » Tue Jul 25, 2017 4:10 pm

is possible make an array of combos, but not possible use combo_run with it. If you look at the combo_run opcode, it has the combo address as argument, which should be determined at compile time.

However, it is possible re-implement combo_run, combo_stop, etc with GPC script and use the combo array like you proposed. :joia:
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: Efficient printf method?

Postby FCB77 » Tue Jul 25, 2017 4:48 pm

i tried it.
i thought crun command changed the combo value to 1 like in titan1.
maybe you can add __asm clause to run T2 assembly commands from gpc script :smile0517:

ArrayCmb[0] retuns the correct combo address.

Code: Select all
int ArrayCmb[] = {&Uno, &dos, &tres};
 
main{
 
 
 
    if (event_active(BUTTON_15))
    {
        printf("%04X", ArrayCmb[0]);
        printf("%04X", *ArrayCmb[0]);
        *ArrayCmb[0] = 1;
    }
}
 
combo Uno
{
    set_val(BUTTON_14, 100);
    wait(3000);
}
 
combo dos
{
    set_val(BUTTON_14, 100);
    wait(3000);
}
 
combo tres
{
    set_val(BUTTON_14, 100);
    wait(3000);
}
User avatar
FCB77
Command Sergeant Major
Command Sergeant Major
 
Posts: 138
Joined: Sun Feb 01, 2015 9:21 am

Re: Efficient printf method?

Postby J2Kbr » Wed Jul 26, 2017 12:06 pm

Cool. Below an example showing how the combo_* commands can be re-implemented and used with an arrays of combos. :smile0517:

Code: Select all
uint8 *ComboArray[] = {
    &ComboA,
    &ComboB,
    &ComboC,
    &ComboD,
    &ComboE,
};
 
init {
    comboRun(ComboArray[1]);
}
 
combo ComboA {}
combo ComboB { set_val(BUTTON_16, 100.0); wait(2000); }
combo ComboC {}
combo ComboD {}
combo ComboE {}
 
void comboRun(uint8 *c) {
    c[0] = 1;
}
 
void comboPause(uint8 *c) {
    c[0] = 0;
}
 
void comboStop(uint8 *c) {
    c[0] = 0;
    c[1] = 0;
    c[2] = 0;
    c[3] = 0;
}
 
void comboReset(uint8 *c) {
    comboStop(c);
    comboRun(c);
}
 
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: Efficient printf method?

Postby FCB77 » Wed Jul 26, 2017 3:47 pm

cool, will test it when i get back home.
User avatar
FCB77
Command Sergeant Major
Command Sergeant Major
 
Posts: 138
Joined: Sun Feb 01, 2015 9:21 am

Re: Efficient printf method?

Postby FCB77 » Thu Jul 27, 2017 9:05 pm

alright i already tested my code and your code.
now i see why my code was not working :innocent_smile_1:
both arrays had the correct combo pointers despite both being declared differently
i declared the array as
int []
and you as
uint8 * []

after reading your code i understood why my code didnt work.

i was writting 1 as an int
*ArrayCmb[0] = 1; // 1 written as an int

instead of a byte
*((int8*)ArrayCmb[0]) = 1; //1 written as a byte;


your solution is more elegant though :innocent_smile_1:
User avatar
FCB77
Command Sergeant Major
Command Sergeant Major
 
Posts: 138
Joined: Sun Feb 01, 2015 9:21 am

Previous

Return to GPC2 Script Programming

Who is online

Users browsing this forum: Majestic-12 [Bot] and 75 guests