Home   Help Search Login Register  

Author Topic: how to get one script to influence/write to another  (Read 1723 times)

0 Members and 1 Guest are viewing this topic.

Offline twisted

  • Members
  • *
  • I'm a llama!
how to get one script to influence/write to another
« on: 06 Mar 2009, 01:53:54 »
Hi. again i am showing my inexperience...

i am trying to write a script where a mhq keeps track of all ai groups on its side. basically the idea is like a command center that tracks groups and sends them where they are needed.

the mhq would run one script and the ai would 'check in' on init and then the mhq would add each to its list of groups. and that is what i am really nto sure how to begin getting to work.




Offline Gnat

  • Addons Depot
  • Former Staff
  • ****
  • I Bite!
    • Gnats
Re: how to get one script to influence/write to another
« Reply #1 on: 06 Mar 2009, 11:25:59 »
Are u simply providing the MHQ with their identy, just once from the group leader at Init, then the MHQ script populates them into a dynamic (managed) array, and on a regular interval, checks the group status via a query to the group leader ... ?
... or are you wanting a more complicated script running with each group, sending data to the MHQ ?

Offline twisted

  • Members
  • *
  • I'm a llama!
Re: how to get one script to influence/write to another
« Reply #2 on: 06 Mar 2009, 17:23:19 »
thanks for the reply Gnat. i want to keep it very simple, but when the groups are attacked/see enemy they send info to the mhq who will then send in reinforcements.

#EDIT: No need to quote the entire previous post you're replying to..     h-
« Last Edit: 06 Mar 2009, 17:55:59 by h- »

Offline Gnat

  • Addons Depot
  • Former Staff
  • ****
  • I Bite!
    • Gnats
Re: how to get one script to influence/write to another
« Reply #3 on: 07 Mar 2009, 04:24:45 »
hmmm well I'm thinking some Global variables or arrays to broadcast the info, but I'm not experienced with their proper use.
Someone else?

Offline twisted

  • Members
  • *
  • I'm a llama!
Re: how to get one script to influence/write to another
« Reply #4 on: 07 Mar 2009, 14:40:52 »
cheers mate.
i have looked at kronzy's UPS script. that's one damn great script. taking inspiration for it I am experimenting with using global variables in the main script.

one thing i cant figure out is how to use arrays as an index of information. another beginners mistake probably. how in an array like [X,4,2,Y] do i check the Y value of array index X=2; sorry for the layman way of trying to explain it.

below is the code i am  experimenting with (it is incomplete). forgive the loose structure. i am just trying to get my head around how to get the two way communication going.

main.swf is
Code: [Select]
// command centre AI. a vehicle on ground acts as a command hq. it orhcestrates group interaction, sends reinforcements, provides support. if it is destroyed it will respawn in a few minutes leaving  its team under great disadvantage.

// initial proof of concept. 1 script thats on a vehicle. 1 script that runs on 2 squads of ai.

// the 2 squads are added to a array on the vehicle.

// when ai detect enemy they report in to vehicle. vehicle sends other ai to detecting ai position.
if !(isserver) exitwith {};



TWI_totalgroups = 0; //number of groups
TWI_reportin = [0,0,0,0,0,0]; // group array index, x,z,enemyx,enemyz,need help?

private ["_hq","_totalgroups","_groupinfo","_enemyspotted","_waypoints","_loop","_cycle"];

_hq = this select 0;

_totalgroups = 0;
_groupinfo = [0,0,0,1]; // group index. x,a,strength. redundant right now.
_enemyspotted = [0,0,0]; //enemy index, x,z coords. later will add other details. redundant
_waypoints = [];

_loop = true;

// place squads into arrays.




while {_loop == true} do
{

sleep 1;

if (TWI_totalgroups > _totalgroups) then {_totalunits = TWI_totalgroups};


// cycle through squads every 10 seconds to see if they are in emergency.
sleep 10;
for [{_cycle =0}, {_cycle <= _totalunits} , {_cycle=_cycle+1}] do

{ private ["_arrayindex","_needhelp"];

_arrayindex = TWI_reportin select 0;

 _needhelp = // need a way to reference select 5 of arraindex?
 
 
};

};

each groupai.sqf script updates TWI_totalgroups by one when first run.
plus each groupai.sqf being under fire/spotting enemy updates TWI_reporting accordingly.

it probably is a very clumsy attempt at a solution but it is a beginning that might just work.
« Last Edit: 07 Mar 2009, 14:47:30 by twisted »

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: how to get one script to influence/write to another
« Reply #5 on: 08 Mar 2009, 15:01:35 »
one thing i cant figure out is how to use arrays as an index of information. another beginners mistake probably. how in an array like [X,4,2,Y] do i check the Y value of array index X=2; sorry for the layman way of trying to explain it.

Uhm, sorry for not understanding it... :)

I'd love to help but my brain returned several "the use of array index is not allowed in this context" errors. Could you rephase it?
try { return true; } finally { return false; }

Offline DeanosBeano

  • Addons Depot Staff
  • *****
  • SirDeanosbeano bstowed on me by sui ;)
    • Fraghaus
Re: how to get one script to influence/write to another
« Reply #6 on: 08 Mar 2009, 15:20:16 »
if i understand you right ,
 to get selected info from your array is same as you would do when passing the info to the script.

 for example
 _yourarray = [X,4,2,Y]

 
  _yourarray select 0 ; //will return the  X in _yourarray
 _yourarray select 1 ; //will return the  4 in _yourarray
and so on

if you want to send that value to another script or indeed all then you simply add

 _valone (or valone) = _yourarray select 0 ; //will return the  X in _yourarray
 [_valone] exec(VM)  "blah.sqs(f)" ;

 there are much easier ways but i am an old fart who refuses to learn spawn /sqf/ functions etc.

 i am not expert here and your question is very "Laymans" as you say .

 
 
I love ofp

Offline twisted

  • Members
  • *
  • I'm a llama!
Re: how to get one script to influence/write to another
« Reply #7 on: 08 Mar 2009, 22:29:27 »
thanks for taking the time to respond and sorry for the layman-ness of my question.

the array i am thinking of is array more like a 4x4 array that would contain indexed information.

for example 1,0,0,active means group one is at 0,0 and active
2,1,1,inactive means group two is at 1,1 and inactive.
3,10,10,active means group three is at 10,10 and active..

then by selecting group index 0 i can access the relevant information.

i have read up on arma array on their biki and am pretty sure they they do not work like this.

the closest i can think of is to manufacture my own arrays. will have to research how as i do not now or have a clue how. pretty new to this scripting stuff but the help i get here has accelerated my learning.





Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: how to get one script to influence/write to another
« Reply #8 on: 08 Mar 2009, 23:23:22 »
I see. Well, you could use nested arrays, i.e. arrays containing arrays.

Code: [Select]
// example of an array containing three other arrays
group_info = [ ["grp1", 1, 10], ["grp2", 2, 20], ["grp3", 3, 30] ];
player globalChat str(group_info);

// add two arrays

group_info = group_info + [["grp4", 4, 40]]; // note the double brackets

subarray_five = ["grp5", 5, 50];
group_info = group_info + [subarray_five]; // find out what happens if you omit the brackets ;)

// read some data

subarray_one = group_info select 0;  // -> ["grp1", 1, 10]

x1 = subarray_one select 1;          // -> 1
y4 = (group_info select 3) select 2; // -> 40


// display the first elements of all subarrays
{
    player sideChat (_x select 0);
} forEach group_info;
try { return true; } finally { return false; }

Offline twisted

  • Members
  • *
  • I'm a llama!
Re: how to get one script to influence/write to another
« Reply #9 on: 09 Mar 2009, 21:22:27 »
thanks. that is exactly what i was looking for..