Help : Rand fuction
7 posts
• Page 1 of 1
Help : Rand fuction
Hi, need help with the Rand function please.
Documentation says :
"Generate a random decimal number between 0.0 and 1.0"
But I want to Generate a random decimal number from 1-10 to choose of 10 different combos by random. How to Do that?
Thanks
Documentation says :
- Code: Select all
fix32 rand();
"Generate a random decimal number between 0.0 and 1.0"
But I want to Generate a random decimal number from 1-10 to choose of 10 different combos by random. How to Do that?
Thanks
-
A1rookie - Staff Sergeant
- Posts: 13
- Joined: Mon Sep 10, 2018 5:26 pm
Re: Help : Rand fuction
This should help you:
- Code: Select all
// example: irand(40, 120); <- random value between 40 and 120, including min and max value itself
#define irand(a,b) (((int)(rand() * (fix32)(b+1 - a))) + a)
init {
printf("rand: %d", irand(1,10));
}
main {
}
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Help : Rand fuction
Know it was Titan one but as I didn't See it in t2 Documentation I thought it's gone. Thank you
-
A1rookie - Staff Sergeant
- Posts: 13
- Joined: Mon Sep 10, 2018 5:26 pm
Re: Help : Rand fuction
irand itself is gone, not available on the T2.
The macro above, the line with # at the beginning, mimics the irand function of the T1.
The macro above, the line with # at the beginning, mimics the irand function of the T1.
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Help : Rand fuction
Ahh okay. Yes I see now.Thank you very much . Offtopic :I always wondered, if I use one Button to trigger a combo, and press Button again, while the executed combo is already und running, will the running combo be disturbed by the trigger, or will it finish like normal? If it would not wait to finish, how to Script on t2 to Block the trigger until the combo is finished?
Because there is no :
Because there is no :
- Code: Select all
! Combo_running
-
A1rookie - Staff Sergeant
- Posts: 13
- Joined: Mon Sep 10, 2018 5:26 pm
Re: Help : Rand fuction
The combo will only be started if it is not running already.
To check if a combo is active you can do
if (comboA)
or for testing if it is not running
if (!comboA)
Example: this will restart the combo after it has finished when you are still holding down R1/RB,
there won't be two instances of comboA active.
To check if a combo is active you can do
if (comboA)
or for testing if it is not running
if (!comboA)
Example: this will restart the combo after it has finished when you are still holding down R1/RB,
there won't be two instances of comboA active.
- Code: Select all
bool last;
main {
if ( get_val(BUTTON_4)) combo_run(comboA); // R1 / RB
if (comboA != last) {
last=comboA;
if ( comboA ) printf("active");
if ( !comboA ) printf("not active");
}
}
combo comboA {
printf("combo started");
wait(0);
set_val(BUTTON_9,100); // L3/LS
wait(1000);
wait(1000);
}
-
Scachi - Brigadier General
- Posts: 3044
- Joined: Wed May 11, 2016 6:25 am
- Location: Germany
Re: Help : Rand fuction
Perfect, everything is working as expected.thank you very much
-
A1rookie - Staff Sergeant
- Posts: 13
- Joined: Mon Sep 10, 2018 5:26 pm
7 posts
• Page 1 of 1
Return to GPC2 Script Programming
Who is online
Users browsing this forum: No registered users and 72 guests