Home   Help Search Login Register  

Author Topic: How to combine a string & integer?  (Read 1806 times)

0 Members and 1 Guest are viewing this topic.

Offline REED

  • Members
  • *
How to combine a string & integer?
« 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  :)

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: How to combine a string & integer?
« Reply #1 on: 15 Jul 2008, 18:09:41 »
Code: [Select]
_name = format["cc%1", 1 + floor (random 7)];

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: How to combine a string & integer?
« Reply #2 on: 15 Jul 2008, 18:14:42 »
You might also need a check in case, cc6 for example, is randomly chosen again.


Planck
I know a little about a lot, and a lot about a little.

Offline REED

  • Members
  • *
Re: How to combine a string & integer?
« Reply #3 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  :)
« Last Edit: 15 Jul 2008, 18:52:49 by REED »

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: How to combine a string & integer?
« Reply #4 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.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Re: How to combine a string & integer?
« Reply #5 on: 17 Jul 2008, 02:11:08 »
Is there a way to get a random integer?

Thanx for the replies, as always.

Luke
Pesky Human!!
Wort Wort Wort.

Offline Cheetah

  • Former Staff
  • ****
Re: How to combine a string & integer?
« Reply #6 on: 17 Jul 2008, 09:06:22 »
No direct command, you'll have to use the code above to transform it into an integer.
« Last Edit: 17 Jul 2008, 19:16:09 by Cheetah »
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Re: How to combine a string & integer?
« Reply #7 on: 17 Jul 2008, 18:25:53 »
Cheetah,

One word:

HOW?  :o

Thanx for the replies, as always.

Luke
Pesky Human!!
Wort Wort Wort.

Offline Cheetah

  • Former Staff
  • ****
Re: How to combine a string & integer?
« Reply #8 on: 17 Jul 2008, 19:18:32 »
Code: [Select]
_integer = floor(random 7)+1;

Result: integer between 1 and 7.
« Last Edit: 17 Jul 2008, 22:58:53 by Cheetah »
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: How to combine a string & integer?
« Reply #9 on: 17 Jul 2008, 22:25:28 »
Sorry Cheetah, the result is from 1 to 7 in that example :whistle:
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Cheetah

  • Former Staff
  • ****
Re: How to combine a string & integer?
« Reply #10 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:
« Last Edit: 17 Jul 2008, 23:01:09 by Cheetah »
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline REED

  • Members
  • *
Re: How to combine a string & integer?
« Reply #11 on: 29 Jul 2008, 14:14:06 »
Thank you for your helpful posts, works great!  :good: