OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Dane on 25 Nov 2004, 22:12:58

Title: Problem with typeOf.
Post by: Dane on 25 Nov 2004, 22:12:58
What's wrong with this script?

_aaaPos1 = ["randomAAA1","randomAAA2","randomAAA3"]
_ranPos1 = ( _aaaPos1 select ( random ( (count _aaaPos1) - 0.5 ) ) )

_vehicle = ["VIT_BMD3","VIT_BMD3M","VIT_BMP3","VIT_BMP3A","VIT_BTR80"]
_ranVehicle1 = ( _vehicle select ( random ( (count _vehicle) - 0.5 ) ) )

#Sector1Create
_tank1 = "DKMM_TUNGUSKA" createvehicle getMarkerPos _ranPos1
"Suchcrew" createunit [getMarkerPos _ranPos1, earm1, "ec1 = this", 1, "SERGEANT"]
"Suchcrew" createunit [getMarkerPos _ranPos1, earm1, "ec2 = this", 1, "CORPORAL"]
"Suchcrew" createunit [getMarkerPos _ranPos1, earm1, "ec3 = this", 1, "PRIVATE"]
ec1 moveincommander _tank1
ec2 moveingunner _tank1
ec3 moveindriver _tank1
_escort1 = _ranVehicle1 createvehicle getMarkerPos _ranPos1
_IFV = ["VIT_BMD3","VIT_BMD3M","VIT_BMP3","VIT_BMP3A"]
_APC = ["VIT_BTR80"]

if (_escort1 == typeOf _IFV) : goto "IFV1"
~0.5
if (_escort1 == typeOf_APC) : goto "APC1"

But the script doesn't go to "IFV1" or "APC"  ???

Title: Re:Problem with typeOf.
Post by: Planck on 25 Nov 2004, 22:28:48
Maybe you could try:

? (_escort in _IFV) : goto "IFV1"
~0.5
goto "APC1"


Planck
Title: Re:Problem with typeOf.
Post by: Dane on 25 Nov 2004, 22:45:12
No _escort wouldn't fit in APC because _escort should be an APC or IFV...

this should define IFV and APC...
_vehicle = ["VIT_BMD3","VIT_BMD3M","VIT_BMP3","VIT_BMP3A","VIT_BTR80"]
_ranVehicle1 = ( _vehicle select ( random ( (count _vehicle) - 0.5 ) ) )

_escort1 = _ranVehicle1 createvehicle getMarkerPos _ranPos1
_IFV = ["VIT_BMD3","VIT_BMD3M","VIT_BMP3","VIT_BMP3A"]
_APC = ["VIT_BTR80"]
this should determine if spawned vehicle is APC or IFV...

if (_escort1 == typeOf  _IFV) : goto "IFV1"
~0.5
if (_escort1 == typeOf _APC) : goto "APC1"

but it doesn't
Title: Re:Problem with typeOf.
Post by: dmakatra on 25 Nov 2004, 22:48:42
EDIT: Nvm. :P

:beat: *Gets Shot* :beat:
Title: Re:Problem with typeOf.
Post by: Sui on 25 Nov 2004, 23:41:37
First off, welcome to the forums Dane.

It's always good to see new faces :)

Two problems with the line: if (_escort1 == typeOf  _IFV) : goto "IFV1"

     if (condition) then {command}      or
     ? (condition) : command


You're trying to compare an object to a whole array, instead of just one element.
Also you've got the typeOf in the wrong place.[/list]
Try something like this:

? ((typeOf _escort1) in _IFV): goto "IFV1"
~0.5
goto "APC1"
Title: Re:Problem with typeOf.
Post by: Dane on 26 Nov 2004, 05:57:32
I think misunderstood what Planck ment with (_escort in _IFV) ::)
Thanks, i'll try this as soon i get home from work.
Title: Re:Problem with typeOf.
Post by: Blanco on 27 Nov 2004, 00:16:24
I don't get it...

_IFV is an array with classname of vehicles. right?
_ranvehicle is a random created vehicle. The types of the vehicles are stored in the _vehicle array. Still OK?

Now afaiK typeof only works with objects, you are calling it with an array...

maybe this works...


Quote
if (typeof _escort1 in _IFV) : goto "IFV1"
~0.5
if (typeof _escort1 in _APC) : goto "APC1"

**oops**

Planck allready told this...



Title: Re:Problem with typeOf.
Post by: Dane on 27 Nov 2004, 06:57:26
Nope it doesn't.
I keep getting an error message, something with type array expected object.
So i guess your right it doesn't work with arrays, only objects but thanks anyway i'll keep experimenting with it and try a different approach maybe.
Title: Re:Problem with typeOf.
Post by: Blanco on 27 Nov 2004, 07:49:36
Does this work?  :P


Quote
_aaaPos1 = ["randomAAA1","randomAAA2","randomAAA3"]
_ranPos1 = ( _aaaPos1 select ( random ( (count _aaaPos1) - 0.5 ) ) )

_vehicle = ["VIT_BMD3","VIT_BMD3M","VIT_BMP3","VIT_BMP3A","VIT_BTR80"]
_ranVehicle1 = ( _vehicle select ( random ( (count _vehicle) - 0.5 ) ) )

#Sector1Create
_tank1 = "DKMM_TUNGUSKA" createvehicle getMarkerPos _ranPos1
"Suchcrew" createunit [getMarkerPos _ranPos1, earm1, "ec1 = this", 1, "SERGEANT"]
"Suchcrew" createunit [getMarkerPos _ranPos1, earm1, "ec2 = this", 1, "CORPORAL"]
"Suchcrew" createunit [getMarkerPos _ranPos1, earm1, "ec3 = this", 1, "PRIVATE"]
ec1 moveincommander _tank1
ec2 moveingunner _tank1
ec3 moveindriver _tank1
_escort1 = _ranVehicle1 createvehicle getMarkerPos _ranPos1
_IFV = ["VIT_BMD3","VIT_BMD3M","VIT_BMP3","VIT_BMP3A"]
_APC = ["VIT_BTR80"]

_type = format ["%1",typeof _escort1]

? (_type in _IFV) : goto "IFV1"
~0.5
? (_type in _APC) : goto "APC1"
Title: Re:Problem with typeOf.
Post by: Dane on 27 Nov 2004, 08:17:05
Fraid not. The random vehicle get spawned but script doesn't go to "APC or "IFV" were the different crews an soldiers get spawned. But this time i didn't recieve any error messages... weird :-\
Title: Re:Problem with typeOf.
Post by: Blanco on 27 Nov 2004, 08:48:26
Thats weird because it works for me. ???

The script did jump to the IFV1 or APC1 label in my test.





Title: Re:Problem with typeOf.
Post by: Dane on 27 Nov 2004, 09:15:53
 ::) It worked for me to ;D forgot i made a few changes in script including labels... sorry bout that.
Thanks for helping all.