Really Easy Question

Gtuner Pro general support. Operation, questions, updates, feature request.

Really Easy Question

Postby Kirin_Dark » Mon Jul 30, 2018 3:17 pm

OK!

I'm a total noob at coding so I apologize in advance for looking stupid.

I'm trying to set a random value to either 100 OR-100, but nothing in between.

Essentially I want my PS4_RX to randomly hit either of it's extreme values with no gray area, Full Left or Full Right

I know I can randomize the intervals with irand, however I haven't found anything that works for selecting one of two defined values randomly

What I have so far:

Code: Select all
define StartButton = PS3_R3;
 
int run, Random, Random2;
 
main {
    Random = irand(650, 825);
    Random2 = irand(-100, 100);
 
        if(run > 0) {
            combo_run(Left_Right);
    } else {
            combo_stop(Left_Right);
    }
 
 
        if(event_press(StartButton)) {
        if(run == 1) {
            run = 0;
        } else {
            run = 1;
        }
    }
}
 
combo Left_Right {
    set_val(PS4_RX, 0);
    wait(Random);
    set_val(PS4_RX, Random2);
    wait(Random);
    set_val(PS4_RX, Random2);
}


This Selects a random value BETWEEN -100 and 100 but I only want it to use the extremes

Any guidance is appreciated!
User avatar
Kirin_Dark
Corporal
Corporal
 
Posts: 4
Joined: Mon Jul 30, 2018 3:02 pm

Re: Really Easy Question

Postby Scachi » Mon Jul 30, 2018 3:58 pm

My math is...
but you may want to use something like that to work around your problem
Code: Select all
define StartButton = PS3_R3;
 
int run, Random, Random2, R2;
 
main {
    Random = irand(650, 825);
    R2 = irand(0, 1);
    if (R2==0) {
        Random2=-100;
    } else {
        Random2=100;
   }
 
        if(run > 0) {
            combo_run(Left_Right);
    } else {
            combo_stop(Left_Right);
    }
 
 
        if(event_press(StartButton)) {
        if(run == 1) {
            run = 0;
        } else {
            run = 1;
        }
    }
}
 
combo Left_Right {
    set_val(PS4_RX, 0);
    wait(Random);
    set_val(PS4_RX, Random2);
    wait(Random);
    set_val(PS4_RX, Random2);
}
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Really Easy Question

Postby Kirin_Dark » Mon Jul 30, 2018 4:14 pm

Of course! An If/Else to toggle, reducing the scope to two integers instead of a range!

Works great thanks!
User avatar
Kirin_Dark
Corporal
Corporal
 
Posts: 4
Joined: Mon Jul 30, 2018 3:02 pm

Re: Really Easy Question

Postby Kirin_Dark » Thu Aug 02, 2018 2:26 am

OK! new problem. Using the above code works great for the intended application. however I tried to apply it to another situation where I want one of two buttons to be pressed and held for 50ms.
Code: Select all
 
define StartButton = PS4_R3;
 
int run, RandAttack, RA;
 
main {
        RandAttack = irand(0, 1);
        if (RandAttack==0) {
        RA=PS4_SQUARE;
    } else {
        RA=PS4_TRIANGLE;
    }
 
    if(run > 0) {
            combo_run(Attack);
    }
    else {
            combo_stop(Attack);
    }
 
    if(event_press(StartButton)) {
        if(run == 1) {
            run = 0;
        } else {
            run = 1;
        }
    }
}
 
combo Attack {
    set_val(RA, 100);
    wait(100);
    set_val(PS4_SQUARE, 0);
    set_val(PS4_TRIANGLE, 0);
    wait(150);
    set_val(RA, 100);
    wait(100);
    set_val(PS4_SQUARE, 0);
    set_val(PS4_TRIANGLE, 0);
    wait(150);
    set_val(RA, 100);
    wait(100);
    set_val(PS4_SQUARE,0);
    set_val(PS4_TRIANGLE, 0);
    wait(150);
}
 
 

So what I'm trying to do is set either the Triangle OR the Square to 100, have it wait for at least 50ms, then because it's random set BOTH to 0 to reset them. However what I'm finding is with this string:
Code: Select all
    set_val(RA, 100);
    wait(100);
    set_val(PS4_SQUARE, 0);
    set_val(PS4_TRIANGLE, 0);
I'm getting multiple button presses within the "wait time."
Attachments
TitanOne_Test.png
TitanOne_Test.png (35.92 KiB) Viewed 1523 times
User avatar
Kirin_Dark
Corporal
Corporal
 
Posts: 4
Joined: Mon Jul 30, 2018 3:02 pm

Re: Really Easy Question

Postby J2Kbr » Thu Aug 02, 2018 6:03 am

The code below (based on above script) will press TRIANGLE or SQUARE for 50ms, wait 1 second and loop back.
Code: Select all
define StartButton = PS4_R3;
 
int run, RA;
 
main {
    if(event_press(StartButton)) {
        run = !run;
        if(run) {
            if(irand(0, 1)) {
                RA = PS4_TRIANGLE;
            } else RA = PS4_SQUARE;
        }
    }
 
    if(run) {
        combo_run(Attack);
    } else combo_stop(Attack);
}
 
combo Attack {
    set_val(RA, 100);
    wait(50);
    wait(1000);
    if(irand(0, 1)) {
        RA = PS4_TRIANGLE;
    } else RA = PS4_SQUARE;
}
 
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: Really Easy Question

Postby Kirin_Dark » Sun Aug 05, 2018 3:08 am

Ok, so I'm seeing these codes work. But, when I try to mix them up and really customize my code I'm hitting a wall. Is there a resource that I can read what the different arguments do and why? I really appreciate the codes y'all have posted, but I need to know the How and Why so that I'm not coming back here constantly to get new revisions. Thanks in advance!
User avatar
Kirin_Dark
Corporal
Corporal
 
Posts: 4
Joined: Mon Jul 30, 2018 3:02 pm


Return to Gtuner Pro Support

Who is online

Users browsing this forum: mizamori and 62 guests