Really Easy Question
6 posts
• Page 1 of 1
Really Easy Question
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:
This Selects a random value BETWEEN -100 and 100 but I only want it to use the extremes
Any guidance is appreciated!
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!
-
Kirin_Dark - Corporal
- Posts: 4
- Joined: Mon Jul 30, 2018 3:02 pm
Re: Really Easy Question
My math is...
but you may want to use something like that to work around your problem
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);
}
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Really Easy Question
Of course! An If/Else to toggle, reducing the scope to two integers instead of a range!
Works great thanks!
Works great thanks!
-
Kirin_Dark - Corporal
- Posts: 4
- Joined: Mon Jul 30, 2018 3:02 pm
Re: Really Easy Question
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.
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
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);
- Attachments
-
- TitanOne_Test.png (35.92 KiB) Viewed 1526 times
-
Kirin_Dark - Corporal
- Posts: 4
- Joined: Mon Jul 30, 2018 3:02 pm
Re: Really Easy Question
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
-
J2Kbr - General of the Army
- Posts: 20323
- Joined: Tue Mar 18, 2014 1:39 pm
Re: Really Easy Question
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!
-
Kirin_Dark - Corporal
- Posts: 4
- Joined: Mon Jul 30, 2018 3:02 pm
6 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 57 guests