Home   Help Search Login Register  

Author Topic: Using strings in arrays  (Read 744 times)

0 Members and 1 Guest are viewing this topic.

Offline DarkAngel

  • Members
  • *
  • The night is my friend.
    • DarkAngels Missions
Using strings in arrays
« on: 15 Jul 2003, 12:57:56 »
Hey guys,

I'm devising a mission where your chopper has been shot down and one of your men has been seriously injured. I've already got a loop in which his condition gradually worsens, what I want to do now is set it up so that he "speaks" (using SideChat) one of a number of pre-selected phrases each time his SetDammage is increased.

At the moment the routine looks like:


#complaintloop
; insert different phrases so it gets interesting.
_chatArray = ["SIR, I'M BLEEDING HERE","DAMN, THIS HURTS.","SIR, AM I GOING TO MAKE IT"]
_chat = random 3
_woundedguy sidechat _ChatArray select _chat
goto "loop"

("loop" being the main loop where his condition worsens)

Doesn't seem to work, though. Does anyone know why this is?

Thanks,
DarkAngel
"Moondark" in Beta Testing

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Using strings in arrays
« Reply #1 on: 15 Jul 2003, 13:23:38 »
random returns a number between 0 and the number specified.    

I can't remember how array things are counted, does it start from 0 for the first one or 1, not sure.

In either case, you still have a problem.    random 3 could return

0    (which won't work if the counting starts at 1)
1.29837     (dunno what happens there)
3      (which won't work if the counting starts at 0)

You need to discover what the counting system is.    You probably also need to convert your random number to a whole number.    There is a handy little item in the FAQ which explains how to do this.

Plenty of reviewed ArmA missions for you to play

Offline Igor Drukov

  • Contributing Member
  • **
  • Conscientious Subjector
Re:Using strings in arrays
« Reply #2 on: 15 Jul 2003, 15:05:45 »
Try this :
Code: [Select]
_chatArray = ["SIR, I'M BLEEDING HERE","d**n, THIS HURTS.","SIR, AM I GOING TO MAKE IT"]

_rand=random ((count _chatArray)-1)+0.5
_rand=_rand - (_rand % 1)

_woundedguy sidechat (_chatArray select _rand)