Page 1 of 2

Arrays

Posted: Mon Jun 16, 2003 2:51 am
by Alcoholic
im making a custom ai script for one of my soldiers. i want him to only shoot at things that have a #bazookatarget of 1. so in mohradiant, i give a guy a key of #bazookatarget and value of 1. now all of these guys will have different targetnames, blah blah. the only way they are alike is their #bazookatarget is 1. im guessing i need arrays to define everything with #bazookatarget 1. in my script, how exactly would i get my soldier to recognize these enemies as targets? how do i set up the arrays for teh targets?

Posted: Mon Jun 16, 2003 6:36 am
by jv_map
Hmm that all is very hard :(

The only way to 'get' an entity in the script is via its targetname, so the only way to make arrays is by using targetnames. Assuming you have two kinds of enemies in your map, one type targetnamed 'village_german', the other 'bocage_german' :wink:, you could make the array like this:

Code: Select all

local.j = 0
for(local.i = 1; local.i <= $village_german.size; local.i++)
{
  local.german = $village_german[local.i]
  if(local.german.bazookatarget)
  {
    local.j++
    level.bazookatargets[local.j] = local.german
  }
}
for(local.i = 1; local.i <= $bocage_german.size; local.i++)
{
  local.german = $bocage_german[local.i]
  if(local.german.bazookatarget)
  {
    local.j++
    level.bazookatargets[local.j] = local.german
  }
}
Now you have a level.bazookatargets array 8)

Posted: Tue Jun 17, 2003 2:08 am
by Alcoholic
i still havnet goten down all that for(local.i = 1; local.i <= $village_german.size; local.i++)
stuff and everything else i dont understand either like the .size and stuff. i tried looking at other scripts like exploder, but that didnt help. can u plz explain all that code you typed?

Posted: Tue Jun 17, 2003 2:19 am
by Alcoholic
when you say, "that is all hard", does that mean you CAN do it without identifyign them by targetnames? because that would be really great.

Posted: Tue Jun 17, 2003 2:23 am
by Alcoholic
hmm just a thought...

can you give the targets a 'wild letter'? for example, say you have 3 tanks, panzer1, panzer2, and panzer3. could you refer to either one of them in the script by typing panzer* :?: that would be really great. then i could use their individual names for specific scripted sequences im making.

Posted: Tue Jun 17, 2003 2:28 am
by Alcoholic
i just had an idea! i dont know if this works though just thought it up...

lets say you got 3 tanks. all named "panzer". now the bazookaman knows to shoot them because their name is "panzer". now to use each one in individual scripted sequences, lets say i gave the first panzer, #bazookatarget 1, next #bazokatarget 2, and so on. now could i use a switch to identify which a specific one in the group? it would go something like this...


Note: never used switches before so plz inform me if i mess up format.

switch (panzer.bazookatarget)

1:
iprintln "Panzer 1"
2:
iprintln "2"
3:
iprintln "3"

would that work??? right now i think that would be the BEST way out of all the ways i posted up above.

Posted: Tue Jun 17, 2003 6:24 am
by jv_map
Yeah something like that, although the syntaxis should be a little different.

Code: Select all

switch($panzer[1].bazookatarget)
{
  case 1:
    // my sweet code here
    break
  case 2:
    // even more code here
    break
  default:
    // last code here
}
:)

Posted: Wed Jun 18, 2003 2:59 am
by Alcoholic
ok, im lost. whats the [1] for? wouldnt that just refer to the first panzer?

what about the cases? how do you know which is which? whats default mean?

Posted: Wed Jun 18, 2003 8:39 am
by jv_map
Yeah [1] means the first panzer of the array, i.e. the first panzer spawned. This is not necessarily the panzer with #bazookatarget 1. You can't run the switch statement on all panzers at once, since they all have a different #bazookatarget value :?

Case 1 equals #bazookatarget 1. I could also have written it as:

Code: Select all

switch($panzer[1].bazookatarget)
{
  case 2:
    // code for panzer 2 here
    break
  case 1:
    // code for panzer 1 here
    break
  default:
    // code for panzer 3 here
}
Default just means 'else', i.e. if the value of bazookatarget is not one of the above.

Posted: Wed Jun 18, 2003 6:37 pm
by Alcoholic
? ok i got the switch cases, now for the [1] thing... they are already placed in the map.. so wouldnt they all be called? and, if i used this switch in my script, i could call ANY panzer by the different cases?

and ANOHTer question, so that i understand cases. if my #bazookatarget was "bob", would i type code like this?

Code: Select all

switch ($panzer[1].bazookatarget)
{
    case bob:
        iprintln "Bob target"
    case default:
        iprintln "error could not find."
}
end
eh? eh?
[/code]

Posted: Wed Jun 18, 2003 10:45 pm
by Alcoholic
how do i refer to the panzer?

lets say i got 3 panzers. only one has a #bazookatarget. (and its 1)

now look at the code...

Code: Select all

switch ($panzer.bazookatarget)
    case 1:
        self drive here
        break
    default:
        println "None"
ok, i identified the pazner with a bazookatarget, but how do i refer to that one in the cases? do i just type self? i want that one panzer to do something specific. how do i make only that one panzer do it? plz comment the code alot i dont know much of what ur saying wiht these arrays.

Posted: Thu Jun 19, 2003 4:23 am
by mohaa_rox
if u used "self", ur panzer needs to thread the thread, e.g $panzer thread panerdrive, whereby the thread "panzerdrive", the $panzer is used as self.

Posted: Thu Jun 19, 2003 9:24 am
by jv_map
Here this might help :wink:

Code: Select all

for(local.i = 1; local.i <= $panzer.size; local.i++)
{
  local.panzer = $panzer[local.i]
  switch(local.panzer.bazookatarget)
  {
    case 1:
      level.panzer_1 = local.panzer
      break
    case 2:
      level.panzer_2 = local.panzer
      break
    case 3:
      level.panzer_3 = local.panzer
  }
}
This little piece of code loops for as many times as there are $panzers ($panzer.size) and assigns the $panzers to level.panzer_1, level.panzer_2 and level.panzer_3.

Posted: Thu Jun 19, 2003 6:35 pm
by Alcoholic
hmmm... kOOL! :shock: thats just what i need thx.

Posted: Thu Jun 19, 2003 6:35 pm
by Alcoholic
can u explain teh contents of the for statement? never really understood that line...