Home   Help Search Login Register  

Author Topic: problem removing an array element  (Read 1394 times)

0 Members and 2 Guests are viewing this topic.

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
problem removing an array element
« on: 29 Jun 2004, 18:16:45 »
I am trying to get a looping system to remove the selected Masterarray element when  it's subarray  is empty

The following system is a simplified version of the actual system showing only the pertinent information



INIT.sqs
Quote

;;;Sub Arrays
tx_AmbushArray = ["Missions\AmbushA.sqs","Missions\AmbushB.sqs","Missions\AmbushC.sqs"]
tx_AssasinArray = ["Missions\AssasinA.sqs","Missions\AssasinB.sqs","Missions\AssasinC.sqs"]
tx_RecceArray = ["Missions\RecceA.sqs","Missions\RecceB.sqs","Missions\RecceC.sqs"]

;;;Master Array
tx_Minimissions = [tx_AmbushArray,tx_AssasinArray,tx_RecceArray]


When required (via booleans and a monitoring script not shown) the following chain of scripts is run in this order

SERVER_SELECT.sqs
(Server side script which randomly picks a master element position and a sub element position of the master element
Quote

?!(local server):exit
#START
tx_selectmission = false

#TYPE_SELECT
;; selects the master array element
tx_AA = count tx_minimissions
?(tx_AA < 1): goto "END"
tx_A= random tx_AA
tx_A = (tx_A - tx_A mod 1)
?(tx_A == tx_AA): tx_A = tx_A - 1

#MISSION_SELECT
;; selects a subarray element of the masterArray element
tx_BB = 0
{tx_BB= (Count _x)} ForEach tx_Minimissions select tx_A
tx_B= random tx_BB
tx_B = (tx_B - tx_B mod 1)
?(tx_B == tx_BB): tx_B = tx_B - 1
tx_sendmission = true

#PV
{PublicVariable _x;}foreach["tx_A","tx_B","tx_sendmission"]
exit

#END
hint "Debug NO MORE MISSIONS AVAIL"
exit

Once the above script has run it's course, the next script is then started up by a script monitoring the booleans (not shown)


ALL_SET.sqs
Having received the public variables, this "local to all" script then selects the actual element that the random script decided on and then processes it  eg [] exec _mission
Quote

#START
tx_sendmission = false
#SET_MISSION
_minimissions = tx_minimissions
;;following is array created from masterArray element
_type = []
_type = _type + (_minimissions select tx_A)

;;following creates variable for  the actual sting element  in the sub array
_mission = _type select tx_B
_type = _type - [_mission]
_count = count _type
_minimissions set [tx_A, _type]

?  (_count  < 1): hint "Debug: Sub Array Empty"

;;The following line needs to remove the element from the masterarray if its subarrays are empty. (This is where my problem lies

as you can see i have tried many possibilities only a few shown here)

;;? (_count  < 1):_Minimissions = _Minimissions - (_minimissions select tx_A)
;;? (_count  < 1):_Minimissions = _Minimissions - [_minimissions select tx_A]
;;? (_count  < 1):_Minimissions = _Minimissions - _type
? (_count  < 1):_Minimissions = _Minimissions - [_type]


tx_minimissions = _minimissions
[] exec _mission
exit

#END
hint "NO MORE MISSIONS"

exit


once the _Mission that this script starts has run its course, it then starts up the SERVER_SELECT.sqs and the loop continues


The problem is, when the subarray is empty and _count <1, i cannot remove the relevant array element from the _minimissions (tx_minimissions) array
the green coloured line is run, so the script does see the subarray as empty

so when the loop restarts at the server_select.sqs, the script still see's in this example 3 elements in the master array and thus is able to select a sub array which is empty

this then causes the loop system to fail

when running a debug, ,
_type or _minimission select tx_A returns the contents of the subarray
 not the actual masterarray element. eg "tx_RecceArray"




In advance........Many thanks for any help offered
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123

Pimmelorus

  • Guest
Re:problem removing an array element
« Reply #1 on: 30 Jul 2004, 14:08:24 »
I cannot test ATM, Terox, what you are doing wrong in the syntax of the array manipulation. So, I here give you a method that will work for sure. At the place of the GREEN text write:

Code: [Select]
_temp = []
{IF (count _x > 0) THEN {_temp = _temp + [_x]}} forEach Tx_minimissions
TX_minimissions = _temp

This solves the prob for sure :)

Good luck, Pimmelorus
« Last Edit: 30 Jul 2004, 14:13:20 by Pimmelorus »

Offline Chris Death

  • Former Staff
  • ****
  • Finally Death's gonna get ya
    • OFPEC
Re:problem removing an array element
« Reply #2 on: 01 Aug 2004, 23:16:08 »
Pimmelorus method is correct

Rebuild the array but excluding the part you want to delete from
the array.

Anywayz Terox, there is a function at editors depot, which does
the very same thing too.

~S~ CD
Dont argue with idiots....they will bring you down to their level and beat you there with experience.

How to use Waypoint type Scripted