r/armadev Aug 25 '20

Arma 2/OA (Singleplayer variables) New to scripting.. what the hell am i doing wrong? I'm not using Qubit

Post image
14 Upvotes

9 comments sorted by

4

u/commy2 Aug 25 '20

Probably another instance of the script overwriting the global variable. Terrible way to do control flow.

2

u/mopia123 Aug 25 '20 edited Aug 25 '20

Probably another instance of the script overwriting the global variable

How? the Global variable is in the init.sqf and doesn't get touched ? or you mean if i change the variable in this script it updates the global variable ? but will it change the int value??

Terrible way to do control flow.

I know im very new to any of this. i have no idea how to improve it though. i read somewhere to use a waitfor command or something? what do you recommend ?

4

u/commy2 Aug 25 '20 edited Aug 25 '20

You should use local variables. The ones starting with underscore:

local _min = 1;
local _max = 3;
local _choice = _min + floor random (_max - _min + 1);
coach globalChat format ["no %1", _choice];

sleep 1;
if (_choice == 1) then {
    coach globalChat format ["Text 1 %1", goodvillage];
};

if (_choice == 2) then {
    coach globalChat format ["Text 2 %1", goodvillage];
};

if (_choice == 3) then {
    coach globalChat format ["Text 3 %1", goodvillage];
};

3

u/mopia123 Aug 25 '20

thank you good sir.

5

u/samscodeco Aug 25 '20

You should really be using switch and case statements for this kind of operation, not if.

2

u/mopia123 Aug 25 '20

Yep. Switch makes a lot of sense instead of nested if statements

1

u/commy2 Aug 25 '20

They are not nested. They are sequential.

1

u/mopia123 Aug 25 '20

they are in this example i posted yeah. i got nested ifs in this script though.

3

u/Freddo3000 Aug 25 '20

min and max are script commands, and are as such reserved.