Page 1 of 1

Array of AI?

Posted: Thu May 12, 2005 11:54 pm
by lizardkid
After dealing with copy/pasting very simple lines of code jsut to get multiple AI to do something all at the same time, i really want to know how to create an array of AI. or an array in MOH period.

i tried

level.array[] = { ... )

i tried

level.array = { .. }

and all that, but it isn't working.
it'd be a lot easier if there was a way to store AI in an array.

Posted: Fri May 13, 2005 5:53 am
by jv_map
Read script files.txt :wink:

Arrays
======

Standard usage
--------------

nonident_prim_expr [ expr ]

nonident_prim_expr is a non-identify primitive expression and expr is an arbitrary expression.
nonident_prim_expr [ expr ] interprets nonident_prim_expr as an array and accesses the element at the position at which expr evaluates to.
Indexing of arrays can be by integers or strings.

Types of arrays
---------------

1) Constant array
Created by expression of the form entry_1::entry_2::entry_3:: ... :: entry_n
Constant arrays start their indexing at 1.
Once created a constant array can not be changed but it can be read for its values.

2) Hash table array
Unitialised entries evaluate to NIL. Any new entry can be set.

3) Targetname array
Created by the $ targetname operator if more than one entity exists for that targetname.
For example, $player is an array if more than one player is in the game.
Targetname arrays start their indexing at 1.

Examples
--------

println local.n[10] // prints the element at position 10 of the local.n array

local.n[1][3] = 10 // sets the element at position (1, 3) of the local.n array equal to 10 (Hash table array)

local.n = hello::world::this::is::a::test::123 // consant array
println local.n[1] // prints hello
println local.n[7] // prints 123
println local.n[8] // results in Script Error: const array index '8' out of range
println local.n[hello] // results in Script Error: const array index '0' out of range

local.n[hello][world][5] = 23
local.a = local.n[hello]
local.b = local.a[world]
println local.b[5] // prints 23

for (local.n = 1; local.n <= 10; local.n++)
println game.stats[game.stats_name[local.n]] // print out element in game.stats array at position game.stats_name[local.n]

local.a = (a::b)::c
println local.a[1][1] // prints a
println local.a[1][2] // prints b
println local.a[2] // prints c


Vector Examples
---------------

Vectors are accessed like arrays in the indices 0, 1, 2.
A vector could be set like
local.my_vector = (10 -2 60.1)

Then this vector could be accessed like:
println local.n[2]
which would print 60.1 to the console.

Example
-------
$player.origin += (5 6 7) // offset the player's origin by (5 6 7).


Make Array Example
------------------

local.Path1 = makeArray
t1 300 10 200
t2
t3
t4
t5
t6
t7 NIL 10 200
t8
t9
t10
t11
t12
t13
t14 0 10 200
endArray

println local.Path1[1][2]
println local.Path1[1][3]
println local.Path1[1][4]
println local.Path1[1][5]
println local.Path1[14][1]
println local.Path1[15][1]
end

results in:

300
10
200
NIL
t14
NIL

printed to console.

Posted: Fri May 13, 2005 7:52 am
by lizardkid
I know how arrrays work, i need to know how to init one. i dont see how to do that there.

Posted: Fri May 13, 2005 9:22 am
by jv_map
Well you don't have to actually init it, you can use it right away:

level.array[1] = level.friendly1
level.array[2] = level.friendly2
level.array[3]= $german5

You can use any integer or string index, doesn't have to be in order and you could skip entries.

Or, you could do:

level.array = level.friendly1::level.friendly2::$german5

Which has a fixed size, indexing starts at 1.

:)

Posted: Sat May 14, 2005 12:51 am
by lizardkid
so if i wanted to array my 7 friendlies i'd go

level.friends = level.f1::level.f2::level.f3::level.f4 // ...

?

then to reference say 4 i'd go

level.friends[4]

right?

Posted: Sat May 14, 2005 7:57 am
by jv_map
Roger roger 8-)