Author Topic: A Loading Problem  (Read 2905 times)

This is something that has been bothering me for a very long time because I couldn't not find an answer to this issue.

In CityRPGX, and in many City RPG mods, there is a problem where bricks loaded do not load correctly with the associated datablocks.

Loaded lots, terminals, and such all do not function until they are replanted. I suspected the problem was a missing onLoad function, but I have been at a loss where to begin. Here is my half assed attempt to fix it.

Code: [Select]
package plantLots
{
        function CityRPGXSmallLotBrickData::OnLoadPlant(%this,%brick,%a)
        {
parent::OnLoadPlant(%this,%brick,%a);
             %brick.setDatablock(%brick.getDatablock().CityRPGXLotTriggerData);
return;
}
function CityRPGXHalfSmallLotBrickData::OnLoadPlant(%this,%brick,%a)
        {
parent::OnLoadPlant(%this,%brick,%a);
             %brick.setDatablock(%brick.getDatablock().CityRPGXLotTriggerData);
return;
}
};

Anyone got any bright ideas?

Btw the package was activated, it just doesnt say in the code.
« Last Edit: October 08, 2012, 07:17:23 PM by Randomness »

onLoadPlant and onLoad are everything that you need.

The bricks are still missing their triggers. When they're replanted, they work fine.

In brick datablocks, triggers (for lots at least) are defined as such,

Code: [Select]
triggerDatablock = CityRPGXLotTriggerData;
« Last Edit: October 08, 2012, 07:21:34 PM by Randomness »

I don't understand, you used "onLoadPlant" twice

Fixed, I think.

Code: [Select]
package plantLots
{
        parent::OnLoadPlant(%this,%brick,%a);
        function CityRPGXSmallLotBrickData::OnLoadPlant(%this,%brick,%a)
        {
             %brick.setDatablock(%brick.getDatablock().CityRPGXLotTriggerData);
return;
}
function CityRPGXHalfSmallLotBrickData::OnLoadPlant(%this,%brick,%a)
        {
             %brick.setDatablock(%brick.getDatablock().CityRPGXLotTriggerData);
return;
}
};

Im just shooting around in the dark here, I only have a basic understanding of parents. I still guesstimate the problem is that bricks do not have set datablocks until replanted.

Code: [Select]
package plantLots
{
    function CityRPGXSmallLotBrickData::OnLoadPlant(%this,%brick,%a)
    {
%brick.setDatablock(%brick.getDatablock().CityRPGXLotTriggerData);
return parent::OnLoadPlant(%this, %brick, %a);
    }
    function CityRPGXHalfSmallLotBrickData::OnLoad(%this,%brick,%a)
    {
%brick.setDatablock(%brick.getDatablock().CityRPGXLotTriggerData);
return parent::OnLoad(%this, %brick, %a);
    }
};

try that and you will see you get a syntax error

only functions can be placed in packages, that floating parent:: in the function will just cause problems.  You also have, as far as I can tell, two exactly identical functions that do nothing except overwrite eachother.

Also be aware that in order to call CityRPGXSmallLotBrickData::OnLoadPlant, the brick must already have the datablock "CityRPGXSmallLotBrickData"
generally, trigger data does not contain datablock names to give a valid datablock to change to

So your code has many errors and do discernable intended functionality

you might want to start with fxdtsbrickdata::onwhatever because that will work for all bricks

edit: then again I don't do a ton of server sided coding, just my two cents.  If kalphiter says that will work I'd go with him.
« Last Edit: October 08, 2012, 07:34:09 PM by Nexus »

try that and you will see you get a syntax error

only functions can be placed in packages, that floating parent:: in the function will just cause problems.  You also have, as far as I can tell, two exactly identical functions that do nothing except overwrite eachother.

Also be aware that in order to call CityRPGXSmallLotBrickData::OnLoadPlant, the brick must already have the datablock "CityRPGXSmallLotBrickData"
generally, trigger data does not contain datablock names to give a valid datablock to change to

So your code has many errors and do discernable intended functionality

you might want to start with fxdtsbrickdata::onwhatever because that will work for all bricks

edit: then again I don't do a ton of server sided coding, just my two cents.  If kalphiter says that will work I'd go with him.

Quote
function CityRPGXSmallLotBrickData::OnLoadPlant(%this,%brick,%a)
Quote
function CityRPGXHalfSmallLotBrickData::OnLoad(%this,%brick,%a)



ok that was just one small part that I addressed and you can definitely format the code to be much more readable so people trying to help you don't make oversights like that, not to mention the fact that you removed the "plant" from the second function after the fact

honestly no formatting at all is probably better than the random spacing and tabs you have now.
but I do think that the datablock namespacing in those functions is not going to work as intended unless loading works fundamentally different than I believe it does.

It returned

Error: fxDTSBrick::setDatablock() - Could not find data block ""

anyway.


Here's an example brick format I use:

Code: [Select]
datablock fxDTSBrickData(CityRPGXSmallLotBrickData : brick16x16FData)
{
iconName = "Add-Ons/GameMode_CityRPGX/shapes/BrickIcons/16x16LotIcon";

category = "CityRPGX";
subcategory = "CityRPGX Lots";

uiName = "Small Lot";

CityRPGXBrickType = 1;
CityRPGXBrickAdmin = false;

triggerDatablock = CityRPGXLotTriggerData;
triggerSize = "16 16 48";
trigger = 0;

initialPrice = 500;
taxAmount = 10;
};
« Last Edit: October 08, 2012, 07:53:19 PM by Randomness »

It returned

Error: fxDTSBrick::setDatablock() - Could not find data block ""

anyway.

yea that's what I thought:

generally, trigger data does not contain datablock names to give a valid datablock to change to

Edit:
From the datablock you posted, you don't even have the instance field "CityRPGXLotTriggerData" initiated to begin with.
Of course it isn't going to do anything.

I'm thinking that what you actually want to do is activite the triggers, and not mess around with the datablocks of the lots.
« Last Edit: October 08, 2012, 07:57:14 PM by Nexus »

Then how am I to reassign the trigger datablock onLoadPlant?

Is this something that can even be fixed?

Then how am I to reassign the trigger datablock onLoadPlant?

Is this something that can even be fixed?

I forget how triggers work, I think you need to do some sort of code like:
new trigger()
{
     datablock = %brick.getdatablock().triggerdata;
};
or something... this is the kind of thing that is handy to look up

Code: [Select]
package plantLots
{
    function CityRPGXSmallLotBrickData::OnLoadPlant(%this,%brick,%a)
    {
new trigger()
{
     triggerData = %brick.getDatablock().CityRPGXLotTriggerData;
}
return parent::OnLoadPlant(%this, %brick, %a);
    }
    function CityRPGXHalfSmallLotBrickData::OnLoadPlant(%this,%brick,%a)
    {
new trigger()
{
     triggerData = %brick.getDatablock().CityRPGXLotTriggerData;
}
return parent::OnLoadPlant(%this, %brick, %a);
    }
};


I'm hoping datablock shouldn't stay datablock.

oky, here1s what you need to do:

copy everything from onPlant and change the names in the copy to 'onLoadPlant'


don't write any new code

source: me, i did this once before, worked flawlessly. 


if it doesn't work, paste the entire fxDtsBrick::onPlant function here