Author Topic: Scriptgroup, Scriptobject  (Read 1713 times)

What would be the use of a scriptgroup? How would I go about getting members of each. I plan to make a system where a scriptgroup holds scriptobjects which each hold bricks. I wouldl ike to know how scriptgroups work.
Code: [Select]
if(!isobject(PRPGChunks))
$PRPG::Chunks = new scriptGroup(PRPGChunks);
function Chunkgen(%grid)
{
if(%grid $= "")
return;
%chunk = new scriptObject()
{
class = PRPG_ChunkSO;
grid = %grid;
creatorBLID = 3291;
};
$PRPG::Chunks.add(%chunk);

}
function PRPG_ChunkSO::onAdd(%this) //minigame initial setup
{
echo("created");
}

function PRPG_ChunkSO::onRemove(%this)
{
echo("removed");
}
How would I go about getting children of the group, removing children from the group, checking if children exist, getting a list of them, and so on.

it's easy ;)
Code: [Select]

if(isObject(exampleGroup))
exampleGroup.delete();
new ScriptGroup(exampleGroup);

function exampleGroup::exampleFunction(%this,%exampleNumber)
{
for(%i=0;%i<%exampleNumber;%i++)
{
%obj = new ScriptObject();
%obj.number = %exampleNumber;
%this.add(%obj);
}
}
function exampleGroup::dumpExampleObjects(%this)
{
for(%i=0;%i<%this.getCount();%i++)
{
%obj = %this.getObject(%i);
%num = %obj.number;
echo("Object: " @ %obj @ " Number: " @ %number);
}
}

if you do for example
exampleGroup.exampleFunction(5);
it will create 5 example objects and will add it to the example group.
then when you do exampleGroup.dumpExampleObjects(); it loops through all the objects inside the exampleGroup
then it gets each object, finds the number in it, and echos it.
Some quick notes

ScriptGroup.add(%object) - will add an object to the group
ScriptGroup.getCount() - will list the amount of objects in the script group
ScriptGroup.getObject(%count) - it will get the object in the group. %count i think is like, the first object added to the group would be 0, the next 1, the one after that would be 2. etc.
ScriptGroup.remove(%object) - removes an object from the group
ScriptGroup.isMember(%object) - returns a boolean value, checking to see if the object is a member of the script group.
« Last Edit: March 23, 2012, 09:41:27 PM by Brian Smithers »

Heres a quick chunk system i made, not tested but feel free to use it.

function chunkObject()
{
   return new ScriptObject() { class = "Chunk" };
}

function Chunk::addBrick(%this,%brick)
{
   if(isObject(%brick.chunkGroup))
   {
      error("::addBrick(%this,%brick): " @ %brick @ " is in a group!");
      return;
   }
   %brick.chunkGroup = %this;
   %this.chunk[%this.chunkCount++] = %brick;
}
function Chunk::clearBricks(%this)
{
   for(%i=0;%i<%this.chunkCount;%i++)
   {
      %brick = %this.chunk[%i];
      if(isObject(%brick))
         %brick.delete();
   }
}
function Chunk::getBricks(%this)
{
   for(%i=0;%i<%this.chunkCount;%i++)
   {
      if(%str $= "")
         %str = %this.chunk[%i];
      else
         %str = %str SPC %this.chunk[%i];
   }
   return %str;
}
function ChunkGroup::getBricks(%this)
{
   for(%i=0;%i<%this.getCount();%i++)
   {
      %chunk = %this.getObject(%i);
      if(%str $= "")
         %str = %chunk.getBricks();
      else
         %str = %str SPC %chunk.getBricks();
   }
   return %str;
}
function newChunkGroup()
{
   %chunkGroup = new ScriptGroup()
   {
      class = "ChunkGroup";
   };
   return %chunkGroup;
}
function ChunkGroup::newChunk(%this,%bricks)
{
   %chunkObject = chunkObject();
   for(%i=0;%i<getFieldCount(%bricks);%i++)
   {
      %brick = getField(%bricks,%i);
      %chunkObject.addBrick(%brick);
   }
   return %chunkObject;
}

it's easy ;)
Code: [Select]
function exampleGroup::dumpExampleObjects(%this)
{
for(%i=0;%i<%this.getCount();%i++)
{
%obj = %this.getObject(%i);
%num = %obj.number;
echo("Object: " @ %obj @ " Number: " @ %number);
}
}
Just do %scriptGroup.listObjects(); It's a default method.

Just do %scriptGroup.listObjects(); It's a default method.
i was showing how to get all objects in script group
plus, it was a custom message.

i'll be working with these tomorrow as well as working with placing bricks. gonna be a nightmare

i'll be working with these tomorrow as well as working with placing bricks. gonna be a nightmare
just talk to me on steam
ill help you :D

nvm weekend field trip to d.c Monday I'll be back

The real problem now is saving everything inside of them then re-applying it when it loads...

I think you could do this:
%scriptGroup.save("base/test.cs");

Then do this to load it:
exec("base/test.cs");

I think you could do this:
%scriptGroup.save("base/test.cs");
Then do this to load it:
exec("base/test.cs");
Using this would require some special modifications but technically you wouldn't need to load bricks with this method

Using this would require some special modifications but technically you wouldn't need to load bricks with this method
Why wouldn't you? Say I generate one chunk of terrain and save the bricks/scriptgroup. How would i manage to reload those bricks and have them fit into the scriptgroup without the non terrain stuff being messed up.

well
nvm
i got a better chunk method
that should actually even save the bricks.
let me write
but the file would look like this

new ScriptGroup(blah)
{
   blah = "vagina";
   blah1 = 1337;
   blah2 = 69;
   new ScriptGroup()
   {
      testicles = true;
      new fxDTSBrick()
      {
         yourmom = "fat";
      };
      new fxDTSBrick()
      {
         your = "stupid";
      };
   };
   new ScriptGroup()
   {
      testicles = false;
      new fxDTSBrick()
      {
         i = "hate you";
      };
      new fxDTSBrick()
      {
         die = "in a hole";
      };
   };
};


get it?

without the non terrain stuff being messed up.
put the non terrain stuff in a chunk


function chunkObject()
{
   return new ScriptGroup() { class = "Chunk" };
}

function Chunk::addBrick(%this,%brick)
{
   if(%brick.inChunk)
   {
      error("::addBrick(%this,%brick): " @ %brick @ " is in a group!");
      return;
   }
   %brick.inChunk = true;
   %this.add(%brick);
}
function Chunk::clearBricks(%this)
{
   for(%i=0;%i<%this.getCount();%i++)
   {
      %brick = %this.getObject(%i);
      if(isObject(%brick))
         %brick.delete();
   }
}
function Chunk::getBricks(%this)
{
   for(%i=0;%i<%this.getCount();%i++)
   {
      if(%str $= "")
         %str = %this.getObjet(%i);
      else
         %str = %str SPC %this.getObject(%i);
   }
   return %str;
}
function ChunkGroup::getBricks(%this)
{
   for(%i=0;%i<%this.getCount();%i++)
   {
      %chunk = %this.getObject(%i);
      if(%str $= "")
         %str = %chunk.getBricks();
      else
         %str = %str SPC %chunk.getBricks();
   }
   return %str;
}
function newChunkGroup()
{
   %chunkGroup = new ScriptGroup()
   {
      class = "ChunkGroup";
   };
   return %chunkGroup;
}
function ChunkGroup::newChunk(%this,%bricks)
{
   %chunkObject = chunkObject();
   for(%i=0;%i<getFieldCount(%bricks);%i++)
   {
      %brick = getField(%bricks,%i);
      %chunkObject.addBrick(%brick);
   }
   return %chunkObject;
}

package chunkBricks
{
   function fxDTSBrick::onAdd(%this)
   {
      parent::onAdd(%this);
      if(%this.isChunk == true)
         %this.plant();
   }
};activatepackage(chunkBricks);


that should work