OFPEC Forum

Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Gruntage on 16 Mar 2010, 18:13:00

Title: Prob with 'IF' [SOLVED]
Post by: Gruntage on 16 Mar 2010, 18:13:00
Ello guys

For some reason i cant work out why this command isnt working:

Code: [Select]
if ((count giMines) > 0) then {goto "skip"}

it comes up with an error: type number expected array

the command is supposed to work by going to another part of the script when a condition is met. But when run it comes up with the error above.

Any ideas why?

Thx in advance

Gruntage
Title: Re: Prob with 'IF'
Post by: Krieg on 16 Mar 2010, 18:24:51
Hmm... :whistle:

Unsure if this will work, but try following code:
Code: [Select]
?((count giMines) > 0) : goto "skip"
Title: Re: Prob with 'IF'
Post by: RKurtzDmitriyev on 16 Mar 2010, 18:48:29
Your if command looks fine to me. Sounds to me most likely that giMines wasn't defined correctly. :confused:
Title: Re: Prob with 'IF'
Post by: Gruntage on 16 Mar 2010, 19:16:19
Ok heres the entire script:

Code: [Select]
_obj = _this select 0
_man = _this select 1
_index = _this select 2


;Only the player is allowed to place mines
if (_obj != _man) then {hint"Only the player can place a mine";exit}

;But not if he is in a vehicle (exception is car bomb)
if (vehicle _man != _man) then {hint"Not while you are in a vehicle";exit}

;and only if he still has mines left
if ((count giMines) < 1) then {hint"You have no more GI Mines left";exit}


#PlaceMine
_mine = giMines select 0
_distance = 1.25

giMines = giMines - [_mine]
if ((count giMines) > 0) then {goto"skip"}
_obj removeAction _index
;if ((count apMines) < 1) then {_obj removeAction countMineAction;8 setRadioMsg "NULL";9 setRadioMsg "NULL";MinesOn = nil}

#skip


_minePos = [(getPos _man select 0) + _distance * sin(getDir _man),(getPos _man select 1) + _distance * cos(getDir _man),0]
_man switchmove "CombatToPutDown"
titletext ["Planting Mine","PLAIN DOWN"]
~0.5
titletext ["Planting Mine","PLAIN DOWN"]
~0.5
titletext ["Planting Mine","PLAIN DOWN"]
~0.5
titletext ["Mine Planted","PLAIN DOWN"]
~0.5
gimines=gimines-1


hint format ["You have %1 AV Mines left!", gimines]
;player switchmove"HandGunStandToHandGunTakeFlag"
_case = "bomb" createVehicle [0,0,0]

_case setPos [_minePos select 0,_minePos select 1,-0.35]
~0.75


~ ArmDelay - 1 + random 2

_mine setPos _minePos
_case addAction["Disarm mine","DisarmMine.sqs"]


exit

This script basically allows the player to place mines (not the ones u get in ur gear section). I tried what u said krieg but it didnt work. The 'gimines' are the triggers that have the camcreated shells in e.g. heat125.  The amount of 'gimines' are defined in the init.sqs like gimines=9.

Are there any obvious probs with this script?

Thx for ur help so far

Gruntage
Title: Re: Prob with 'IF'
Post by: RKurtzDmitriyev on 16 Mar 2010, 22:30:10
You didn't show where in the game you define giMines. (Misread your post, see below). My suspicion that you didn't define them correctly is furthered by this line:

Code: [Select]
gimines=gimines-1
Is gimines a number or an array? If it an array, then that line of code makes no sense, and if it's a number, then your line

Code: [Select]
if ((count giMines) > 0) then {goto "skip"}
will make no sense. (count can only be used on arrays, it doesn't need to be used on numbers!)

EDIT: plus you said you defined them as gimines=9 . I'm 99% certain that that's your problem. Part of your script (copied below) is written as though you had an array of gimines. I doubt that OFP will recognize the difference between giMines and gimines btw. Your IF command is probably fine.

Code: [Select]
#PlaceMine
;SELECT ONLY WORKS WITH ARRAYS!
_mine = giMines select 0
_distance = 1.25

;AGAIN, GIMINES TREATED AS AN ARRAY!
giMines = giMines - [_mine]
if ((count giMines) > 0) then {goto"skip"}
_obj removeAction _index
;if ((count apMines) < 1) then {_obj removeAction countMineAction;8 setRadioMsg "NULL";9 setRadioMsg "NULL";MinesOn = nil}
Title: Re: Prob with 'IF'
Post by: Gruntage on 17 Mar 2010, 17:55:13
got it working now. i had to change gimines=9 to something else=9, and then have 'something else'='something else'-1 in the script. Thx for ur help.

topic solved