OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: REED on 15 Jul 2008, 17:33:30

Title: How to combine a string & integer?
Post 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

Code: [Select]
_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  :)
Title: Re: How to combine a string & integer?
Post by: Mandoble on 15 Jul 2008, 18:09:41
Code: [Select]
_name = format["cc%1", 1 + floor (random 7)];
Title: Re: How to combine a string & integer?
Post by: Planck on 15 Jul 2008, 18:14:42
You might also need a check in case, cc6 for example, is randomly chosen again.


Planck
Title: Re: How to combine a string & integer?
Post by: REED on 15 Jul 2008, 18:51:14
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  :)
Title: Re: How to combine a string & integer?
Post by: Spooner on 15 Jul 2008, 23:02:05
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):
Code: [Select]
_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.
Title: Re: How to combine a string & integer?
Post by: Luke on 17 Jul 2008, 02:11:08
Is there a way to get a random integer?

Thanx for the replies, as always.

Luke
Title: Re: How to combine a string & integer?
Post by: Cheetah on 17 Jul 2008, 09:06:22
No direct command, you'll have to use the code above to transform it into an integer.
Title: Re: How to combine a string & integer?
Post by: Luke on 17 Jul 2008, 18:25:53
Cheetah,

One word:

HOW?  :o

Thanx for the replies, as always.

Luke
Title: Re: How to combine a string & integer?
Post by: Cheetah on 17 Jul 2008, 19:18:32
Code: [Select]
_integer = floor(random 7)+1;

Result: integer between 1 and 7.
Title: Re: How to combine a string & integer?
Post by: Spooner on 17 Jul 2008, 22:25:28
Sorry Cheetah, the result is from 1 to 7 in that example :whistle:
Title: Re: How to combine a string & integer?
Post by: Cheetah on 17 Jul 2008, 22:59:25
Yeah I was too fast on that one.. it's the damn campaign mission's outro that makes me nuts  :blink:
Title: Re: How to combine a string & integer?
Post by: REED on 29 Jul 2008, 14:14:06
Thank you for your helpful posts, works great!  :good: