Home   Help Search Login Register  

Author Topic: Problem with typeOf.  (Read 816 times)

0 Members and 1 Guest are viewing this topic.

Dane

  • Guest
Problem with typeOf.
« 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"  ???


Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Problem with typeOf.
« Reply #1 on: 25 Nov 2004, 22:28:48 »
Maybe you could try:

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


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

Dane

  • Guest
Re:Problem with typeOf.
« Reply #2 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
« Last Edit: 25 Nov 2004, 22:50:31 by Dane »

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:Problem with typeOf.
« Reply #3 on: 25 Nov 2004, 22:48:42 »
EDIT: Nvm. :P

:beat: *Gets Shot* :beat:
« Last Edit: 25 Nov 2004, 22:49:24 by dmakatra »

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:Problem with typeOf.
« Reply #4 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"
  • You're mixing syntaxes... try either:

     if (condition) then {command}      or
     ? (condition) : command
  • Planck's hit the nail on the head... well... he's using the right end of the hammer ;D


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"
« Last Edit: 25 Nov 2004, 23:43:43 by Sui »

Dane

  • Guest
Re:Problem with typeOf.
« Reply #5 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.

Offline Blanco

  • Former Staff
  • ****
Re:Problem with typeOf.
« Reply #6 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...



« Last Edit: 27 Nov 2004, 00:18:31 by Blanco »
Search or search or search before you ask.

Dane

  • Guest
Re:Problem with typeOf.
« Reply #7 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.

Offline Blanco

  • Former Staff
  • ****
Re:Problem with typeOf.
« Reply #8 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"
Search or search or search before you ask.

Dane

  • Guest
Re:Problem with typeOf.
« Reply #9 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 :-\

Offline Blanco

  • Former Staff
  • ****
Re:Problem with typeOf.
« Reply #10 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.





« Last Edit: 27 Nov 2004, 08:53:27 by Blanco »
Search or search or search before you ask.

Dane

  • Guest
Re:Problem with typeOf.
« Reply #11 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.