Jump to content
Sign in to follow this  
Rexxenexx

Can you set an array from a switch?

Recommended Posts

Wondering if you can you set an array from a switch?

EX:


_array = switch (param1) do {
case 1: {["Bill",4]};case 2: {["Bob",130]};
};

_name = _array select 0;
_IQ = _array select 1;

I have something similar but it doesn't do anything, it doesn't even throw a script error. I used to have a bunch of switches to get variables just from the param1 selection. Ideas?

Share this post


Link to post
Share on other sites

You're close to it, mate.

private ["_array"];
switch (param1) do {
   case 1: {
       _array = ["Bill",4]
       };
   case 2: {
       _array = ["Bob",130]
   };
};

_name = _array select 0;
_IQ = _array select 1;

OT:

_IQ = 4 ?

ROFLMAO, nice one ;)

Share this post


Link to post
Share on other sites

Lol.

You won't believe it! It does work that way up top! :P Upon undoing @40 cases -splitting the statements so I can put them back into separate switches- I found out I deleted the end of the switch "};" ...FECES!!! It's working now. Oh man... I think I wasted an hour trying to find out why nothing was happening. :P

Share this post


Link to post
Share on other sites

Thats something i also like on ArmA 2. Although i'm already doin scripts for several years (!) theres something new i learn everyday. I didn't knew it can be done the way you did although when re-reading your code it's so obvious, it almost hurts. :D

Glad you sorted it out and indeed, those brackets can be <insert slang sentence here>.:p

Share this post


Link to post
Share on other sites

Another nice trick with switch case is that you can use it the other way (opposed to how it's usually used).

Common:

switch someVar do {

case 1: {};

case 2: {};

};

You can use it with more flexible conditions like this:

switch true do {

case (your condition here): {};

case (another condition here): {};

};

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×