Home   Help Search Login Register  

Author Topic: i.e side WEST and a number converted into "WEST"  (Read 4028 times)

0 Members and 1 Guest are viewing this topic.

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
i.e side WEST and a number converted into "WEST"
« on: 14 Feb 2009, 21:01:53 »
In my detect dead body script I want to make it possible to set a variable (LAGGY_FindBody_checkaccidents) to true or false concerning accepting if the dead unit was killed even by accident or just fire.

My script earlier dealt with checking the config side of the dead unit and the unit that finds a dead body, but since I now want the script to care about the "current" side of the finding unit I have to convert a number into a string or text. This I can't get working.

The "side" of the dead unit still needs to be a number based on config, since all dead units become civilian.

Let's see:

Code: [Select]
if ((LAGGY_BodyAndFinderCombo select 0 == EAST) AND (LAGGY_BodyAndFinderCombo select 1 == EAST)) then
{
   hint "OPFOR corpse detected by OPFOR unit";
       };

This is the script that checks for different combinations.

Then the eventhandler:

Code: [Select]
_deadguy = _this select 0;
_killer = _this select 1;
_numsidedeadguy = getNumber (configFile >> "CfgVehicles" >> typeOf _deadguy  >> "side");

if (_numsidedeadguy == 0) then {_deadguyside = EAST};
if (_numsidedeadguy == 1) then {_deadguyside = WEST};
if (_numsidedeadguy == 2) then {_deadguyside = GUER};
if (_numsidedeadguy == 3) then {_deadguyside = CIV};

_killerside = side _killer;

sleep 1;

if (! (LAGGY_FindBody_checkaccidents) AND (_deadguyside == _killerside)) exitWith {};

while { _deadguyside != _killerside AND ! (alive _deadguy) } do
{
_finders = nearestObjects [vehicle _deadguy, ["AllVehicles"], LAGGY_FindBody_searchradius];
   if (count _finders > 1) then
   {
      {
         if (_x != vehicle _deadguy AND (alive _x)) then
         {
            if ((_x knowsAbout vehicle _deadguy > 0) AND (_x knowsAbout vehicle _deadguy >= LAGGY_FindBody_awareness)) then
            {
               _searcherside = side _x; call compile format ["LAGGY_BodyAndFinderCombo = [%1, %2]",  _deadguyside,_searcherside]; publicVariable "LAGGY_BodyAndFinderCombo"; sleep 5;
            };
         };
      } forEach _finders;
   };
sleep 2;
};

It doesn't work and I get NO error messages.

Laggy

« Last Edit: 14 Feb 2009, 21:03:28 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: i.e side WEST and a number converted into "WEST"
« Reply #1 on: 14 Feb 2009, 21:06:20 »
Does it make a difference if you use quotes or not?

i.e.  "EAST" instead of EAST.


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

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: i.e side WEST and a number converted into "WEST"
« Reply #2 on: 14 Feb 2009, 21:11:54 »
Did tests with a trigger:

Condition: side player == WEST
This works as wanted.

Condition: side player == "WEST"
ArmA says when "okaying the trigger": Generic error in expression.
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: i.e side WEST and a number converted into "WEST"
« Reply #3 on: 14 Feb 2009, 21:14:13 »
Never mind the trigger, what about in a script?

Probably no difference, but would be good to check.

EDIT: Ignore me, I forgot they are names of sides in the game, unless you specified a string somewhere.


Planck
« Last Edit: 14 Feb 2009, 21:19:54 by Planck »
I know a little about a lot, and a lot about a little.

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: i.e side WEST and a number converted into "WEST"
« Reply #4 on: 14 Feb 2009, 21:18:24 »
Code: [Select]
...
               _searcherside = side _x; call compile format ["LAGGY_BodyAndFinderCombo = [%1, %2]",  _deadguyside,_searcherside]; publicVariable "LAGGY_BodyAndFinderCombo"; sleep 5;...


LAGGY_BodyAndFinderCombo will contain something like [0, "WEST"].
try { return true; } finally { return false; }

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: i.e side WEST and a number converted into "WEST"
« Reply #5 on: 14 Feb 2009, 21:20:06 »
So the number "1" converted into "WEST" solution doesnt work?

The reason I ask this question is because of my wanted solution:

if (! (LAGGY_FindBody_checkaccidents) AND (_deadguyside == _killerside)) exitWith {};

I want to solve the == issue and unless I can convert a number into a string that reads as "side", the script will be more complicated and powerhungry.

Laggy
« Last Edit: 14 Feb 2009, 21:26:00 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: i.e side WEST and a number converted into "WEST"
« Reply #6 on: 14 Feb 2009, 21:26:35 »
If it is "1", wouldn't:

if (_numsidedeadguy == 1)

fail?

Unless you converted it to a number first.


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

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: i.e side WEST and a number converted into "WEST"
« Reply #7 on: 14 Feb 2009, 21:29:26 »
I used to have:

Code: [Select]
if ((LAGGY_BodyAndFinderCombo select 0 == 0) AND (LAGGY_BodyAndFinderCombo select 1 == 0)) then
{
   hint "OPFOR corpse detected by OPFOR unit";
};

This worked perfectly well, now when I want the script to be able to read:

Code: [Select]
if ((LAGGY_BodyAndFinderCombo select 0 == EAST) AND (LAGGY_BodyAndFinderCombo select 1 == EAST)) then
{
   hint "OPFOR corpse detected by OPFOR unit";
};

It doesn't work.
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: i.e side WEST and a number converted into "WEST"
« Reply #8 on: 14 Feb 2009, 22:02:44 »
Uhm, wait a minute... LAGGY_BodyAndFinderCombo will contain two strings!

So you send two strings ...
Code: [Select]
call compile format ["LAGGY_BodyAndFinderCombo = [%1, %2]",  _deadguyside,_searcherside];
publicVariable "LAGGY_BodyAndFinderCombo";
... but you expect two sides:
Code: [Select]
LAGGY_BodyAndFinderCombo select 0 == EAST
Why do you use call compile format at all? Why don't you simply send two sides?

Code: [Select]
LAGGY_BodyAndFinderCombo = [_deadguyside,_searcherside];
publicVariable "LAGGY_BodyAndFinderCombo";
try { return true; } finally { return false; }

Offline laggy

  • Members
  • *
  • "Behold a pale horse"
Re: i.e side WEST and a number converted into "WEST"
« Reply #9 on: 14 Feb 2009, 22:35:51 »
I see your point, but the old script works, regardless.
I'm not sure that this conversion works though.

Code: [Select]
if (_numsidedeadguy == 0) then {_deadguyside = EAST};
if (_numsidedeadguy == 1) then {_deadguyside = WEST};
if (_numsidedeadguy == 2) then {_deadguyside = GUER};
if (_numsidedeadguy == 3) then {_deadguyside = CIV};

What I want is to convert the config based _numsidedeadguy (which is  a number 0-3) to a variable called _deadguyside (being a string), EAST, WEST etc. Then _killerside is simply based on "side" which is a string.

I then want to be able to check if _deadguyside == _killerside.

Cheers!



« Last Edit: 14 Feb 2009, 22:47:21 by laggy »
And I looked and beheld a pale horse and his name that sat on him was Death and Hell followed with him.

Offline Rommel92

  • Members
  • *
Re: i.e side WEST and a number converted into "WEST"
« Reply #10 on: 14 Feb 2009, 23:00:28 »
Code: [Select]
private"_deadguyside";
if (_numsidedeadguy == 0) then {_deadguyside = EAST};
if (_numsidedeadguy == 1) then {_deadguyside = WEST};
if (_numsidedeadguy == 2) then {_deadguyside = GUER};
if (_numsidedeadguy == 3) then {_deadguyside = CIV};

Don't worry, I've spent hours trying to figure this out before, your codes fine. Most people fix this by declaring '_deadguyside' before they go into a seperate scope, but a private works just as well.

Check WorldEaters cleaner code below!
« Last Edit: 14 Feb 2009, 23:05:12 by Rommel92 »

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: i.e side WEST and a number converted into "WEST"
« Reply #11 on: 14 Feb 2009, 23:02:19 »
1. If you haven't declared _deadguyside private before it won't work.
2. Since GUER and CIV are no sides it won't work. [1]
3. It could be written slightly more elegant:

Code: [Select]
_deadguyside = [east,west,resistance,civilian] select _numsidedeadguy;


[1] ArmA thinks GUER and CIV are uninitialized global variables. So _deadguyside might become nil.
try { return true; } finally { return false; }

Offline Rommel92

  • Members
  • *
Re: i.e side WEST and a number converted into "WEST"
« Reply #12 on: 14 Feb 2009, 23:07:36 »
2. Since GUER and CIV are no sides it won't work. [1]

Sides: "WEST", "EAST", "GUER", "CIV", "LOGIC" or "UNKNOWN".

note: returned as values not strings.

So:

Code: [Select]
_deadguyside = [east,west,guer,civ,logic] select _numsidedeadguy;
 ???

followed from your link: http://community.bistudio.com/wiki/side

edit: Neither of us is wrong: http://community.bistudio.com/wiki/resistance

Both sets of code will work Laggy! (both mine and Worldeaters)

edit2:
[1] ArmA thinks GUER and CIV are uninitialized global variables. So _deadguyside might become nil.

THEORY: This may only happen if the sides haven't been created. Ie you need to create a Civilian, and a Resistance man for the side to become 'initialized'. Hence the commands 'createCenter' etc for sides.
« Last Edit: 14 Feb 2009, 23:14:09 by Rommel92 »

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: i.e side WEST and a number converted into "WEST"
« Reply #13 on: 14 Feb 2009, 23:24:11 »
1. Again, GUER and CIV are no sides.
2. The units that are checked for sides are provided by the "Killed" EH. When was the last time you shot or got shot by a game logic? ;)
try { return true; } finally { return false; }

Offline Rommel92

  • Members
  • *
Re: i.e side WEST and a number converted into "WEST"
« Reply #14 on: 14 Feb 2009, 23:28:56 »
Hahaha, you'll be surprised...  :dry:

 :P

Well I'll have to take your judgement on this, can't test it so;
But could you maybe explain why GUER and CIV are 'no sides'; eg 'nil' since they are global variables in the form 'civilian' and 'resistance'; which point to 'GUER' and 'CIV' as values.