Author Topic: How would I create an object inside another object?  (Read 1210 times)

Once again, I am coding yet another chatbot, but this time it shall be a huge project.
How would I go about creating an object inside another object, Nexus taught me how it was better to use objects to store variables than just putting global variables.

Code: [Select]
%obj = new scriptObject(tank)
{
       var1 = 40;
       var2 = 20;
};
tank.kill();

function tank::kill()
{
       (coding here)
}
But what I am trying to do is place an object inside another object, if it's possible can somebody tell me how


???
for instance, performing a function with 2 objects in it
Code: [Select]
player.armor.destroy();

new scriptGroup(myGroup);

new scriptObject(a);
new scriptObject(b);
new scriptObject(c);

myGroup.add(a);
myGroup.add(b);
myGroup.add(c);

for(%i=0;%i<myGroup.getCount();%i++)
     echo(myGroup.getObject(%i).getName());


for instance, performing a function with 2 objects in it
Code: [Select]
player.armor.destroy();

Edit: wait what?

I think he means
new scriptobject(blah){};
blah.asdf = new scriptobject(){};

???

Confusion all over the topic

I think he means
new scriptobject(blah){};
blah.asdf = new scriptobject(){};

???
indeed that is what i mean


also when I am defining variables using other variables and operations, do I need parenthesies around the definition part?
example:
Code: [Select]
%tankenergy = tank::health/2

also when I am defining variables using other variables and operations, do I need parenthesies around the definition part?
example:
Code: [Select]
%tankenergy = tank::health/2
Unclear what you want here. Give us more information.

Unclear what you want here. Give us more information.
is
%tankenergy = tank::health/2;
or
%tankenergy = (tank::health/2);
proper syntax?

tank::health isn't valid syntax, however parentheses are not needed nor will they do anything.

It sounds like you want something like this:
Code: [Select]

%obj = new scriptObject(tank)
{
       var1 = 40;
       var2 = 20;
};
tank.build();
tank.kill();
tank.print();

function tank::kill()
{
       (coding here)
}

function tank::setup(%this)
  {
   %tread = new ScriptObject(Tread);
   %tread.setup();
   %turret = new ScriptObject(Turret);
   %turret.setup();
  }
function tank::print(%this)
  {
   echo("tank: " @ %this);
   echo("tank treads: " @ %this.tread);
   echo("tank turret: " @ %this.turret);
  }


function tread::setup(%this)
  {
   (coding here)
  }

function Turret::setup(%this)
   {
    (coding here)
   }