OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: REED on 15 Jul 2008, 17:33:30
-
Hello
I am trying to make a variable equal a randomly assigned vehicle name out of 7 possibilities.
The vehicles are named cc1 to cc7
I am trying to make a script that would look similar to this
_cc=cc + (random 8);
or
_cc=str(cc(random 8))
But i have tried different layouts and tried the str command with no luck. Just wondering if someone can lend me a hand. Thanks :)
-
_name = format["cc%1", 1 + floor (random 7)];
-
You might also need a check in case, cc6 for example, is randomly chosen again.
Planck
-
Thank you for your help. I guess I was also wrong in my thinking that Random 8 would choose between 0-7 and never actually pick 8?edit* I see the +1 keeps it from picking 0 because i do not have a vehicle named 0
I will test and post back the results. I do appreciate your time in helping me :)
-
You asked about the str command in your original post. Format works fine, but you could use str in this case (just depends which method feels better for you):
_name = "cc" + str (1 + floor (random 7));
Incidentally, "random 8" gives a real number from 0.0 up to just less than 8.0. By using floor on that number, you get a random integer from 0 to 7 with equal likelyhood of each number.
-
Is there a way to get a random integer?
Thanx for the replies, as always.
Luke
-
No direct command, you'll have to use the code above to transform it into an integer.
-
Cheetah,
One word:
HOW? :o
Thanx for the replies, as always.
Luke
-
_integer = floor(random 7)+1;
Result: integer between 1 and 7.
-
Sorry Cheetah, the result is from 1 to 7 in that example :whistle:
-
Yeah I was too fast on that one.. it's the damn campaign mission's outro that makes me nuts :blink:
-
Thank you for your helpful posts, works great! :good: