I've been pining for the 'dot' notation that C++ uses to access data for a particular object. In flashpoint script, you either have to use one of the commands in the comref (getpos for example), or store your data in a whole bunch of variables in script (_soldier1startloc, _soldier2startloc, _car23owner and so on). It can get cumbersome (for me) to keep track of/use/update all these variables in script sometimes especially in large .sqs files. Plus there is the additional problem of global variables being the only way that scripts can 'communicate' - otherwise they are completely cut off from each other. With global variables again there is the problem of keeping track of names, plus the fact that they all seem to be public and overwritten perfectly easily, and from anywhere. The fact that the script is parsed means there is no compiler error if you accidentally attempt to overwrite a 'private' variable (or at least one that somebody
intended to be private) which is used some other script(s). Having masses of global variables seems... unsafe, and a bit uncomfortable at times.
So my idea, if original, is to store data pertaining to an object (you define the data, and its tag) in an n-dimensional array. This would reduces the number of global variables to just one.
Example: say you had 2 scripts for a C&H game. The first monitored the capture points for east/west presence and updated who owned what. The second was an ai script that told a group of soldiers where to move next and what to do. When the first script detected that a capture point was taken, it would update the waypoint for the soldiers to the next objective. The second (ai) script would tell them to move to the objective/patrol and guard once they were there.
Problem: how do the 2 scripts communicate? The mission designer might understandably want the soldiers to patrol through certain waypoints at one objective, and another another set at the next. Or he might want them to mount a certain machine gun at the first objective, and a tank at the next. How does the mission designer store all these variables: objectives, positions, machine guns etc? It's possible but difficult to do this with conventional waypoints and switch commands, and it gets trickier the more objectives there are. Generally the mission designer will script, and use variable names.
In flashpoint, you might name them something like this: CurrentObjective, WayP1GuardPoint1, WayP1GuardPoint2, WayP2MG1, WayP2MG2 and so on. (The variables might be local or global, depending on how the scripts are structured). Here it gets messy, especially if the variables are global, because they'll need original names to stop them getting accidentally overwritten by competing scripts.
Solution: In C++, you might be able to store/retreive the data like this: currentobjective.patrolpoints [ 0 ] (for the first patrol point in a series for this objective), currentobjective.defences.machineguns (for a list of machinegun defences associated with this objective) etc. It's 'object orientated' in that the code revolves around various objects which contain data and functions that modify that data. These functions can also modify
other object's data (if that object allows it), which makes it powerful. Apologies if you know all this already.
How to implement something this in OFP? As I mentioned before, with an n-dimensional 'array'. Since 'array's in ofp are very flexible, you can store this data like this:
[ [
AnObject,["dataname1",data1],["dataname2",data2] ] , [
AnotherObject,["dataname1",data1] ] , ... ]
With a simple check, you could find, say, AnObject 's second piece of data by searching firstly for AnObject in the array, and secondly for "dataname1" in it's various data arrays. Effectively you get 'AnObject.Dataname1', which equals 'data1'. In this way, you can store/retrive any number of pieces of info associated with a single object. Only 2 functions would be required for this which I can write quite easily- one to store new data, one to retreive it.
Advantages: 1. You can assign your own properties to an object without ever needing to name it, or know it's name. Simply because the object itself resides in the array. So you could assign a piece of data to an unnamed object, and run into it sometime later (e.g. with a nearestobject command) and find it's data again.
2. You can assign as many properties as you like to an object (within the various limitations of the game).
3. Drastically cuts down on the number of variable names needed.
Disadvantages:1. The functions that find the data and the object iterate through all the elements. This means that the more pieces of data you add, and the more objects you add, the longer the check would take. The 'retreive data' functions are much slower than simply accessing a variable by name. Translation: More objects with more properties = slower to find one property.
2. Probably there are others.
Sorry for this long and rambling post. If you're still with me, please let me know what you think, or if this has been done before. If you have a question also please tell me.