Null reference errors when using my mod (but everything works)

Started by edvardass, September 11, 2016, 04:54:45 AM

Previous topic - Next topic

edvardass

TL;DR: When using my radio mod (like TV, but bigger radius) I receive a lot (~100 per second) null reference errors when looking at certain objects (ex.: muffalo). See attached .png. Should I be worried?

So, I decided to make my first mod. I created a tree structure like this (yes, I shamelessly stole the sd_chickennest texture as a placeholder  :P):

RadioBoom
├───About
│       About.xml
│       Preview.png

├───Defs
│   ├───JobDefs
│   │       Jobs.xml
│   │
│   ├───Joy
│   │       JoyGivers.xml
│   │
│   └───ThingDefs
│           radioboom_ThingDefs.xml

└───Textures
    └───sd_chickennest
            sd_chickennest.png


The radio building itself works fine, so I guess ThingDefs are good.

Here is the JoyGivers.xml:

<?xml version="1.0" encoding="utf-8" ?>
<Defs>
   <JoyGiverDef>
      <defName>ListenToRadio</defName>
      <giverClass>JoyGiver_WatchBuilding</giverClass>
      <baseChance>2</baseChance>
      <canDoWhileInBed>true</canDoWhileInBed>
      <thingDefs>
         <li>Radio</li>
      </thingDefs>
      <joyKind>Passive</joyKind>
      <jobDef>Job_ListenToRadio</jobDef>
      <requiredCapacities>
        <li>Sight</li>
      </requiredCapacities>
   </JoyGiverDef>
</Defs>


And here is the Job_ListenToRadio I defined:

<?xml version="1.0" encoding="utf-8" ?>
<Defs>
   <JobDef>
      <defName>Job_ListenToRadio</defName>
      <driverClass>JobDriver_WatchBuilding</driverClass>
      <reportString>listening to the radio.</reportString>
      <joyDuration>4000</joyDuration>
      <joyMaxParticipants>20</joyMaxParticipants>
      <joyGainRate>1</joyGainRate>
      <joyKind>Passive</joyKind>
   </JobDef>

</Defs>


I didn't find any useful tutorials online, so I had to improvise. If you have any suggestions, be free to tell me :)

Thanks.

[attachment deleted by admin - too old]

skullywag

The error is with a thing called "Ball", thats not your radio.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

edvardass

Yeah, and the error was with the Muffalo as well. I checked the same colony without the mod, and there weren't any errors. I think it's a rendering error, since it only appears when I look at the object. Are you sure it's OK? If nothing else, it makes debugging worse...

Thanks anyway!

Master Bucketsmith

Psssst! If you put that structure in code tags, it'll look like below! ;)
RadioBoom
├───About
│       About.xml
│       Preview.png

├───Defs
│   ├───JobDefs
│   │       Jobs.xml
│   │
│   ├───Joy
│   │       JoyGivers.xml
│   │
│   └───ThingDefs
│           radioboom_ThingDefs.xml

└───Textures
    └───sd_chickennest
            sd_chickennest.png


Are you absolutely sure you haven't got a stray file or def in there somewhere?

edvardass

I don't know, here's the radioboom_ThingDef, maybe it has some wild tag somewhere...


<Buildings>

<ThingDef ParentName="BuildingBase">
    <defName>Radio</defName>
    <label>radio</label>
    <description>Radio for colonist's pleasure.</description>
    <graphicData>
      <texPath>sd_chickennest/sd_chickennest</texPath>
      <graphicClass>Graphic_Single</graphicClass>
      <shadowData>
        <volume>(0.7, 0.6, 0.7)</volume>
        <offset>(0,0,-0.15)</offset>
      </shadowData>
    </graphicData>
    <altitudeLayer>Building</altitudeLayer>
    <drawPlaceWorkersWhileSelected>true</drawPlaceWorkersWhileSelected>
    <rotatable>false</rotatable>
    <minifiedDef>MinifiedFurniture</minifiedDef>
    <socialPropernessMatters>true</socialPropernessMatters>
    <fillPercent>0.40</fillPercent>
    <statBases>
      <WorkToMake>1000</WorkToMake>
      <MaxHitPoints>100</MaxHitPoints>
      <Flammability>1.0</Flammability>
      <MarketValue>100</MarketValue>
      <EntertainmentStrengthFactor>1</EntertainmentStrengthFactor>
    </statBases>
    <costList>
      <Steel>30</Steel>
      <Component>1</Component>
    </costList>
    <pathCost>70</pathCost>
    <passability>PassThroughOnly</passability>
    <building>
      <isJoySource>true</isJoySource>
      <watchBuildingStandDistanceRange>
        <min>1</min>
        <max>7</max>
     
  </watchBuildingStandDistanceRange>
    </building>
    <placeWorkers>
      <li>PlaceWorker_WatchArea</li>
    </placeWorkers>
    <comps>
      <li Class="CompProperties_Power">
        <compClass>CompPowerTrader</compClass>
        <startElectricalFires>true</startElectricalFires>
        <basePowerConsumption>50</basePowerConsumption>
      </li>
      <li Class="CompProperties_Flickable"/>
    </comps>
    <tradeTags>
      <li>Radio</li>
    </tradeTags>
    <constructEffect>ConstructMetal</constructEffect>
    <designationCategory>Joy</designationCategory>
    <designationHotKey>Misc4</designationHotKey>
    <researchPrerequisites><li>TubeTelevision</li></researchPrerequisites>
  </ThingDef>
  </Buildings>

Master Bucketsmith

On a side-note; you have to put any parent defs you reference to inside the scope of your mod.
So you gotta find Buildings_Art and search for the code below. Feel free to copy it now, but remember to look there if there's an update to the game, to check if anything changed!
  <ThingDef Name="BuildingBase" Abstract="True">
    <category>Building</category>
    <thingClass>Building</thingClass>
    <soundImpactDefault>BulletImpactMetal</soundImpactDefault>
    <selectable>true</selectable>
    <drawerType>MapMeshAndRealTime</drawerType>
    <terrainAffordanceNeeded>Light</terrainAffordanceNeeded>
    <repairEffect>Repair</repairEffect>
    <leaveResourcesWhenKilled>true</leaveResourcesWhenKilled>
    <filthLeaving>BuildingRubble</filthLeaving>
  </ThingDef>

Put this between <Buildings> and <ThingDef ParentName="BuildingBase">.

Other than that, I don't see anything wrong with the ThingDef you made. There might be something missing? Is it a copy of the television with altered values?

edvardass

Thanks for the advice.

Yeah, you guessed it, it's a copy of a TV with some values changed. The downside is that the worker area is kind of "+" shaped and not round (like a sun lamp), I haven't found a way around that just yet.

kaptain_kavern

Dunno if it can help but I noticed two things comparing your objects defs and vanilla ones.

None of the vanilla joy objects have a min watching distance lower than 2 and they all use another tag : <watchBuildingStandRectWidth> that it isn't in your code.

Keep up you will find

edvardass

Thanks for the input, everyone. In the end, it seems that the bug was unrelated to my mod.

I have added the parent building class definition, and the <watchBuildingStandRectWidth> tag made my area look like two intersecting rectangles, not quite the sun lamp sphere, but I'll get there.

You can get the source code here: https://www.dropbox.com/sh/g6ugjojllwtivhe/AABeAfhwwMnjiJjMV-R91LzDa?dl=0. There's a nice radio texture :P