LSValmont 789 Posted October 22, 2019 Anyone knows why this is not working when inside a Damaged Eventhandler: Spoiler params ["_unit", "_selection", "_damage", "_source", "_projectile", "_hitIndex", "_instigator", "_hitPoint"]; _origDamage = 0; _headMultiplier = 1; _neckMultiplier = 1; _bodyMultiplier = 1; _legsMultiplier = 1; _handsMultiplier = 1; _overAllMultiplier = 1; switch (_projectile != "") do { case (_selection isEqualTo "face_hub"): {_origDamage = _unit getHitPointDamage "hitface"; _addedDamage = (_damage - _origDamage) * _headMultiplier; _finalDamage = _origDamage + _addedDamage;}; case (_selection isEqualTo "neck"): {_origDamage = _unit getHitPointDamage "hitneck"; _addedDamage = (_damage - _origDamage) * _neckMultiplier; _finalDamage = _origDamage + _addedDamage;}; case (_selection isEqualTo "head"): {_origDamage = _unit getHitPointDamage "hithead"; _addedDamage = (_damage - _origDamage) * _headMultiplier; _finalDamage = _origDamage + _addedDamage;}; case (_selection isEqualTo "pelvis"): {_origDamage = _unit getHitPointDamage "hitpelvis"; _addedDamage = (_damage - _origDamage) * _bodyMultiplier; _finalDamage = _origDamage + _addedDamage;}; case (_selection isEqualTo "spine1"): {_origDamage = _unit getHitPointDamage "hitabdomen"; _addedDamage = (_damage - _origDamage) * _bodyMultiplier; _finalDamage = _origDamage + _addedDamage;}; case (_selection isEqualTo "spine2"): {_origDamage = _unit getHitPointDamage "hitdiaphragm"; _addedDamage = (_damage - _origDamage) * _bodyMultiplier; _finalDamage = _origDamage + _addedDamage;}; case (_selection isEqualTo "spine3"): {_origDamage = _unit getHitPointDamage "hitchest"; _addedDamage = (_damage - _origDamage) * _bodyMultiplier; _finalDamage = _origDamage + _addedDamage;}; case (_selection isEqualTo "body"): {_origDamage = _unit getHitPointDamage "hitbody"; _addedDamage = (_damage - _origDamage) * _bodyMultiplier; _finalDamage = _origDamage + _addedDamage;}; case (_selection isEqualTo "arms"): {_origDamage = _unit getHitPointDamage "hitarms"; _addedDamage = (_damage - _origDamage) * _handsMultiplier; _finalDamage = _origDamage + _addedDamage;}; case (_selection isEqualTo "hands"): {_origDamage = _unit getHitPointDamage "hithands"; _addedDamage = (_damage - _origDamage) * _handsMultiplier; _finalDamage = _origDamage + _addedDamage;}; case (_selection isEqualTo "legs"): {_origDamage = _unit getHitPointDamage "hitlegs"; _addedDamage = (_damage - _origDamage) * _legsMultiplier; _finalDamage = _origDamage + _addedDamage;}; case (_selection isEqualTo ""): {_origDamage = damage _unit; _addedDamage = (_damage - _origDamage) * _overAllMultiplier; _finalDamage = _origDamage + _addedDamage;}; case (_selection isEqualTo "incapacitated"): {_origDamage = damage _unit; _finalDamage = _origDamage;}; default {}; }; private _damCoef = 0.9; _finalDamage = _finalDamage*_damCoef; hint format ["Final %1 Added %2 selection %3 Original %4", _finalDamage, _addedDamage, _selection, _origDamage]; _finalDamage hint is showing _selection body and _origDamage 0 telling me that anything inside the switch do is not working but it should! Share this post Link to post Share on other sites
POLPOX 765 Posted October 22, 2019 That is not how to use switch do. switch (_selection) do { case ("face_hub"): {/*something*/}; case ("neck"): {/*something*/}; /* more... */ }; Share this post Link to post Share on other sites
beno_83au 1362 Posted October 22, 2019 Or, more generically for the sake of examples: _num = selectRandom [1,2,3,4]; switch (_num) do { case 1: {hint "1 was selected."}; case 2: {hint "2 was selected."}; case 3: {hint "3 was selected."}; case 4: {hint "4 was selected."}; }; So yours should probably look like: if (_projectile == "") exitWith {}; switch (_selection) do { case "face_hub": {//code}; case "neck": {//code}; case "head": {//code}; }; 1 Share this post Link to post Share on other sites
4d4a5852 3 Posted October 22, 2019 switch works by comparing the condition to the different cases. So doing something like switch (true) do { case (a > 5): {...}; case (a == 2): {...}; default {}; }; is fine - see Example 3 But when only comparing a variable to strings there's no reason to abuse switch in such a way - i.e. just use its standard syntax. Additionally switch (_projectile != "") do { will resolve to false when _projectile is an empty string and therefore the first case which also resolves to false will be executed - i.e. move the check into a separate if-block. But the reason for the code not working is that _finalDamage isn't declared in the main scope before the switch, i.e. the value assigned to it within the switch-cases will be lost afterwards e.g. define/declare it at the beginning of the script. 2 Share this post Link to post Share on other sites
LSValmont 789 Posted October 22, 2019 5 hours ago, 4d4a5852 said: But the reason for the code not working is that _finalDamage isn't declared in the main scope before the switch, i.e. the value assigned to it within the switch-cases will be lost afterwards e.g. define/declare it at the beginning of the script. That did the trick! Thank you very much! 1 Share this post Link to post Share on other sites