Writing a Header
Let's create a header for Ichigo. We have a lot of Gizmos, including ones that don't have Actor equivalents, but we can create custom Gizmos if we wish. Let's do that now. Let's create a custom Gizmo: the GoodBoy.
You must have the Ichigo Class library to write header files by following this guide. This is included in Ichigo Template.
Firstly, create a new file called goodboy.lua in the /include folder. We want to make sure our code does not run multiple times, so we need some sort of "load blocker". Type the following into the file:
if GoodBoy then return endWe need to include the Gizmos header in order to create a custom Gizmo. Let's do that. Write underneath our load blocker:
include "gizmos"Next, we need to define the GoodBoy class. It doesn't have to be anything fancy at the moment, as long as it extends the Gizmo class.
class "GoodBoy" : extends "Gimzo" {
__ready = function(self)
print("GoodBoy created.")
end;
Bark = function(self)
SCREENMAN:SystemMessage("Bark!")
end;
}Now we can create a GoodBoy within layout.lua:
myBoy = GoodBoy:new()And we can call its methods within files such as main.lua:
function ready()
myBoy:Bark()
endHere is what the code looks like in its entirety:
-- goodboy.lua
-- written by Sudospective
if GoodBoy then return end
include "gizmos"
class "GoodBoy" : extends "Gimzo" {
__ready = function(self)
print("GoodBoy created.")
end;
Bark = function(self)
SCREENMAN:SystemMessage("Bark!")
end;
}We have successfully created our first header! Headers are great for creating classes that can then be instantiated as objects, which can come in handy for minigame files.
Last updated
Was this helpful?