Fandom

Surfpup's tConfig Mod Wiki

Using Codable.RunMethod/RunGlobalMethod & more

124pages on
this wiki
Add New Page
Comments0 Share

Codable.RunMethod and Codable.RunGlobalMethod are methods who call a method described in the parameters of these methods. It can be used to:

  • Call a method from another person's mod (that's how Avalon's achievements are made)
  • Call a custom method from a(n) projectile/npc a(n) npc/player just spawned (that's how Poro's Rideable Nyan Cat mod is made)
  • Much more!

To get the return value of the method you just called, use Codable.customMethodReturn (and convert it to another type, it's default type is object)

  • Note: if the return value is an array, use Codable.customMethodRefReturn (and convert it to another type, too. it's default type is object[])

Calling the methodsEdit

RunMethodEdit

Codable.RunMethod(string methodName, object[] parameters)

  • note: instead of creating a new object[] for adding the parameters, you can just add all parameters as.. parameters after the methodName

UseEdit

(Pr represents a projectile)

Pr.RunMethod("SetStuff", new object[] {1, true, new Vector2(2f, 0.3f)});

or:

Pr.RunMethod("SetStuff", 1, true, new Vector2(2f, 0.3f));

RunGlobalMethodEdit

Codable.RunGlobalMethod(string className, string methodName, object[] parameters)

  • note: if you have a class in a class, you can have 2 string className's
  • note: instead of creating a new object[] for adding the parameters, too; you can just add all parameters as.. parameters after the methodName

All the (primary) classes you can access are:

  • ModWorld (Global\World.cs)
  • ModPlayer (Global\Player.cs)
  • ModGeneric (Global\Generic.cs)
  • Global_Item (Item\Item.cs)
  • Global_NPC (NPC\NPC.cs)
  • Global_Projectile (Projectile\Projectile.cs)
  • Global_Tile (Tile\Tile.cs)

UseEdit

Codable.RunGlobalMethod("ModWorld", "DatClassName", "DoSomething", new object[] {1, true, "abc"});

or:

Codable.RunGlobalMethod("Global_NPC", "Blahblahblah", 1, false, 0f);

Codable.customMethodReturnEdit

this variable returns the value that the called method should return. You better use this one, because Codable.RunGlobalMethod and Codable.RunMethod return a boolean: true if the method exists, false otherwise.

UseEdit

(N is an NPC)

if (N.RunMethod("ReturnsAnInt") {
    int returnValue = (int)Codable.customMethodReturn;
    if (returnValue == 3) { // ...........

as i told before, use Codable.customMethodRefReturn if the return value is an array.

#INCLUDEEdit

  1. INCLUDE is used for adding multiple files to a code.

UseEdit

#INCLUDE "FileName.cs"

this file 'FileName.cs' is in the same directory as the cs file where you put this piece of code in.

to add files from another directory:

#INCLUDE"...\FolderName\FileName.cs"

'...' stands for the main folder of you mod.

or to go even further:

String Folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games", "Terraria", "Codes") + "\\";
#INCLUDE Folder + "FileName.cs"
  • note: Folder isn't a string, but a String (big diffirence!)

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.