Home   Help Search Login Register  

Author Topic: How do I change one element in an array ?  (Read 410 times)

0 Members and 1 Guest are viewing this topic.

Offline Roni

  • Members
  • *
  • Play the Game !
How do I change one element in an array ?
« on: 23 Jul 2004, 10:59:28 »
Okay, I know this a bone-brain simple query but how do I change just one element in an array ?  I've checked all the refs and I couldn't find anything
that addressed this presumably very simple query.   ???

I am working on a script that will let players search buildings for food and water.  The idea is to record the last 20 buildings that the player has searched so that they don't just keep hanging around the same building until the food magically appears.

I created an array of arrays  - 20 elements, all with a value of [0,0,0].  My script checks the nearest building position against each element of the array - if there is a match then the script exits, otherwise it is supposed to assign the position of that building as the "nth" searched building.  When the index reaches 20 then it will reset back to zero so the player can go back to the same building at a later time.

I tried _array select _n = _newElement but that didn't work.  I tried various brackets but still haven't had any luck.

Any ideas from anyone ?

HELP !



Roni

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:How do I change one element in an array ?
« Reply #1 on: 23 Jul 2004, 12:03:45 »
array set element

Operand types:
array: Array
element: Array
Type of returned value:
Nothing
Description:
Format of element is [index, value] Changes an element of given array. It element does not exist, resize index+1 is called to create it.

Example:
array set [0, "Hello"]
Plenty of reviewed ArmA missions for you to play

Offline Roni

  • Members
  • *
  • Play the Game !
Re:How do I change one element in an array ?
« Reply #2 on: 24 Jul 2004, 02:19:12 »
Sorry - my bad !   :'(  :-[


I should have edited or deleted this straight away - I found it in the Com Ref (where else ?) right after posting.

My problem was that I checked things like "assign", "let", "element" etc.  I got lazy and didn't get to the "s" 's until after I'd posted.

I got my script working  ;D and I'll post it to the Scripts board but I learned one very important thing - there is no simple way to compare arrays !  You can't use a "==" check, the "in" command or anything else.  Problem solved though - I simply saved the building objects themselvs in the array, not just their positions - it looks like you can compare objects but not arrays !   :hmm:

Thanks mac for the speedy response !



Roni
« Last Edit: 24 Jul 2004, 02:19:45 by Roni »