Jump to content
Ed!

Creating classes with variables and functions just like in OOP

Recommended Posts

I am currently thinking of using a combination of setVariable and getVariable on objects to get the same behavior as you would get from classes in OOP.

 

I am thinking of doing the following:

_x = someObject;
_x setVariable ["foo", "bar"];

which would be similar to:

Object x = new Object();
x.foo = "bar";

If there is a better practise, please stop reading and just direct me towards it.

 

If the above is sufficient, what object would be the best to use the setVariable/getVariable on?

 

I am looking at creating an array which might contain more than a thousand of these objects.

Share this post


Link to post
Share on other sites

Hmm arma does support macros so you can have unique syntaxt instead of having to write setvariable everytime.

 

something like this:

#define SETV(obj,var,value) obj setVariable[var,value];
 
// then just use it like this
_obj = someobject;
SETV(_obj,"var",21345);

that's just an example of what you could do, only imagination is limit so you can improve it from that.

Share this post


Link to post
Share on other sites

How would I then go about doing the following?:

_obj1 = someobject;
_obj1 setVariable["foo", "bar"];

_obj2 = someobject;
_obj2 setVariable["parent", _obj1];
_obj2 setVariable["foo", "baz"];

_quz = (_obj2 getVariable "parent") getVariable "foo";

I want to know what the best "someobject" would be to attach the variables to.

 

Edit:

My question should rather be: How do I create a namespace?

I do not want to use missionNameSpace or units etc. I just want a namespace which does not belong to anything.

Share this post


Link to post
Share on other sites

I don't know if you can create namespaces but you can create Logic object and use it with setVariable and getvariable.

_center = createCenter sideLogic;
_group = createGroup _center;
_pos = [0, 0, 0]
_logic = _group createUnit ["LOGIC",_pos , [], 0, ""];

  • Like 1

Share this post


Link to post
Share on other sites

 

I don't know if you can create namespaces but you can create Logic object and use it with setVariable and getvariable.

I guess creating units with the least resource usage will be the best then.

Share this post


Link to post
Share on other sites

If all its doing is saving variables use createvehicle instead or disable simulation. No need to waste resource on AIBrain if its not doing anything other than holding data.

Also group it to bis_mainscope so your not creating any more groups than the default logic that is spawned for you.

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×