Custom code, help me get the basics down with classes and compiling!

Started by Sunspots, February 27, 2014, 08:38:09 AM

Previous topic - Next topic

Sunspots

So, I decided to start working on some custom machinery. My idea was to clone the nutrient paste dispenser and make a machine that takes in a resource in hoppers and outputs new items.

The game doesn't seem to find my class when I reference it in <thingClass>

I can see that the dll is found/done something with in the log:

Non platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\Mods\Concrete\Assemblies\ConcreteMod.dll (this message is harmless)

But on launch the game tells me "Could not find a type named  Building_CementMill" every time I start up.
The code that is compiled to the dll is (I've taken out the rest of the code for now, just to try getting it working):
namespace ConcreteMod
{
public class Building_CementMill : Building
{
public Building_CementMill ()
{

}
}
}


What are the first steps I need to take to make this work?

(I've followed the steps in the end of this page, I'm using MonoDevelop)

Rokiyo

I haven't had a chance to get a .NET environment up and running yet, nor have worked with .NET yet, so apologies in advance if my attempts to play "spot the difference" aren't helpful.

That being said, it doesn't look like the Tynan's classes that extend Building are declaring their own namespaces or constructors.

Have you tried the following?
using System;
public class Building_CementMill : Building
{
}

Sunspots


Tynan

I haven't actually tried loading a thing class like this; I tested code loading with an incident def. But based on what I know, this should work.

If the class is under a namespace you'll need to address it like so: <thingClass>ConcreteMod.Building_CementMill</thingClass>

Maybe if you provide the output_log file we can look at see what might be wrong?
Tynan Sylvester - @TynanSylvester - Tynan's Blog

Sunspots

Still not working :(

ThingDef:
<ThingDef ParentName="BuildingBase">
<defName>CementMill</defName>
<eType>BuildingComplex</eType>
<label>Cement mill</label>
<thingClass> ConcreteMod.Building_CementMill</thingClass>
<texturePath>Things/Building/NutrientDispenser</texturePath>
<altitudeLayer>BuildingTall</altitudeLayer>
<passability>Impassable</passability>
<castEdgeShadows>true</castEdgeShadows>
<fillPercent>1</fillPercent>
<maxHealth>350</maxHealth>
<flammability>1.0</flammability>
<description>Grinds limestone into cement</description>

<size>(3,4)</size>
<workToBuild>600</workToBuild>
<costList>
<li>
<thingDef>Metal</thingDef>
<count>90</count>
</li>
</costList>
<overdraw>true</overdraw>
<interactionSquareOffset>(0,0,3)</interactionSquareOffset>
<hasInteractionSquare>true</hasInteractionSquare>
<killedLeavings>
<li>
<thingDef>DebrisSlag</thingDef>
<count>6</count>
</li>
</killedLeavings>
<filthLeavings>
<li>
<thingDef>SlagRubble</thingDef>
<count>3</count>
</li>
</filthLeavings>
<leaveResourcesWhenKilled>true</leaveResourcesWhenKilled>
<surfaceNeeded>Heavy</surfaceNeeded>
<designationCategory>Building</designationCategory>
<staticSunShadowHeight>0.75</staticSunShadowHeight>
</ThingDef>


Compiled code:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ConcreteMod
{
public class Building_CementMill : Building
{
public Building_CementMill ()
{

}
}
}

output_log:
Initialize engine version: 4.3.0f4 (e01000627d60)
GfxDevice: creating device client; threaded=1
Direct3D:
    Version:  Direct3D 9.0c [nvd3dum.dll 9.18.13.3467]
    Renderer: NVIDIA GeForce GTX 670
    Vendor:   NVIDIA
    VRAM:     1990 MB (via DXGI)
    Caps:     Shader=30 DepthRT=1 NativeDepth=1 NativeShadow=1 DF16=0 INTZ=1 RAWZ=0 NULL=1 RESZ=0 SlowINTZ=0
Begin MonoManager ReloadAssembly
Platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\UnityEngine.dll (this message is harmless)
Loading C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\UnityEngine.dll into Unity Child Domain
Platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\Assembly-CSharp-firstpass.dll (this message is harmless)
Loading C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\Assembly-CSharp-firstpass.dll into Unity Child Domain
Platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\Assembly-CSharp.dll (this message is harmless)
Loading C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\Assembly-CSharp.dll into Unity Child Domain
Platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\Assembly-UnityScript-firstpass.dll (this message is harmless)
Loading C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\Assembly-UnityScript-firstpass.dll into Unity Child Domain
Platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\Vectrosity.dll (this message is harmless)
Loading C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\Vectrosity.dll into Unity Child Domain
- Completed reload, in  0.048 seconds
<RI> Initializing input.

<RI> Input initialized.

desktop: 1920x1080 60Hz; virtual: 3200x1080 at 0,0
Platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\System.dll (this message is harmless)
RimWorld 0.2.363 rev42831

(Filename: C:/BuildAgent/work/d3d49558e4d408f4/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 53)

Platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\System.Core.dll (this message is harmless)
Platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\System.Xml.dll (this message is harmless)
Platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\Mono.Security.dll (this message is harmless)
Platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\System.Configuration.dll (this message is harmless)
Could not find a type named  ConcreteMod.Building_CementMill

(Filename: C:/BuildAgent/work/d3d49558e4d408f4/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 53)

Non platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\Mods\Concrete\Assemblies\ConcreteMod.dll (this message is harmless)
Platform assembly: C:\Users\Sunspots\Desktop\RimWorld363Win\RimWorld363Win_Data\Managed\System.Xml.Linq.dll (this message is harmless)

(What bothers me here is that the error is before the "Non platform assembly" line, does it mean it isn't loaded in the right order?)

And this error is in the console:
http://pbrd.co/1fLAVBt

Tynan

There is a space at the start of this element:

<thingClass> ConcreteMod.Building_CementMill</thingClass>

Tynan Sylvester - @TynanSylvester - Tynan's Blog

Tynan

You can see the extra space here:

Could not find a type named  ConcreteMod.Building_CementMill
Tynan Sylvester - @TynanSylvester - Tynan's Blog

Sunspots

Removed the space, still get the exact same error :/ (well, the error is now also without the space)

Rokiyo

FYI I believe the thingDef for the nutrient paste dispenser also has that extra space there.

And yeah... Very intriguing that you get your type not found error BEFORE your file loads.

Tynan

Quote from: Rokiyo on February 27, 2014, 04:12:36 PM
And yeah... Very intriguing that your get your type not found error seems to happen BEFORE your file loads.

Yeah, this may be related to a bug in the core game.

When I tested DLL loading it worked with loading IncidentDefs, but they're not referenced the same way as a ThingDef references its thingClass. I suspect the load order is broken for this. I'll be looking into it.
Tynan Sylvester - @TynanSylvester - Tynan's Blog

Rokiyo

Wow, I just realised how badly I mangled that sentence... Guess that's what I get for posting from my phone.

Is there a way to produce slightly more verbose log output?

Tynan

Tynan Sylvester - @TynanSylvester - Tynan's Blog

Tynan

Ok, I fixed this yesterday in the internal build; I can now write a mod with external assemblies of any kind.

Sunspots, if you want to work on this, I'd be glad to have you join the test team and get a head start for Alpha 3. PM or email me if interested.
Tynan Sylvester - @TynanSylvester - Tynan's Blog

Architect

Lucky lad! :D Can't wait to delve properly into C# and find new ways of doing things wrong with alpha 3 XD
Check out BetterPower+ and all its derivatives by clicking the picture below.

It adds many new methods of power generation and uses for it, as well as other things such as incidents.


Tynan

Quote from: Architect on March 01, 2014, 02:01:35 PM
Lucky lad! :D Can't wait to delve properly into C# and find new ways of doing things wrong with alpha 3 XD

I'm happy to have you give it a shot as well. Really, anyone who's serious about it can ask and I'll probably bring you on.
Tynan Sylvester - @TynanSylvester - Tynan's Blog