When you create a brand new project, SkookumScript can easily be used to run any generic engine commands while your project is running.
(This example assumes you have already created a project or are using one of the example projects such as
SkookumDemo and the SkookumIDE is connected to your running project.)
Eventually though, you will want to add SkookumScript behavior that is part of your project.
To do this you need to click on a class in the class hierarchy that you want to add a routine to and then add a Class/Member. The
Master mind class is a good starting point to add initial code for your overall project.
You can do this by going to "File" menu and select "Add a Class/Member", or click on the "Add a Class/Member" pane that is at the bottom of the "Members" tab or just press
Since this is the first time you are adding SkookumScript code into your project (if you are not using the SkookumDemo project which already has SkookumScript code in it) you will see the following:
Once you select "OK" the files SkookumScript needs will be added to your project. We call this Skookifying your project and once done your project is Skookified.
Now you have access to the "Add a Class\Member" dialog.
Let's add a
fizz_buzz() method which is a common example coding problem.
The FizzBuzz problem:
Write a program that prints the integers from 1 to 100 (inclusive).
- for multiples of three, print
Fizz (instead of the number)
- for multiples of five, print
Buzz (instead of the number)
- for multiples of both three and five, print
FizzBuzz (instead of the number)
So you type in the name of the method in the "Name:" field, ensure that it is an instance method (
c class method), and set the overlay to "Project". (An overlay is like a code library.) Then select "Add".
Voila, it creates your method. (It copies from a template file which you can customize.)
(If you have version control such as Perforce set up it will add the file using it.)
The "Add a Class\Member" dialog is quite versatile, you can use it to create all sorts of things just depending on the name that you enter. It also shows you a hint before you start typing:
[Class.] NewClass, _coroutine, _method[?], ![constructor], !!(destructor), ConvertClass, @instance_data[?], class_data[?]
- a name starting with a capital letter will create a subclass for the currently selected class
- a name starting with an underscore
_ and then a lowercase letter will create a coroutine (a routine that takes time / may take more than one frame to complete)
- a name starting with a lowercase letter will create a method (a routine that returns immediately)
- a name starting with an exclamation mark
! will create a constructor method for the class
- a name starting with two exclamation marks
!! will create a destructor method for the class
- a name that is an existing class will create a conversion method from the current class to the specified class type
- a name starting with an at symbol
@ will create an instance data member for the class
- a name starting with two at symbols
@@ will create class data member for the class (called a
static member in some languages)
- names that indicate they can end in an optional question mark
? can have a question mark added to make them be a predicate method or data member that always returns a
Instead of using the currently selected class you can also specify the class that you want to add to by first entering the class you want and then a period/dot
Then you just update the comments and put in the code body like so:
// Fizz buzz example
if idx.mod(15) = 0 ["FizzBuzz"]
idx.mod(3) = 0 ["Fizz"]
idx.mod(5) = 0 ["Buzz"]
(To see some alternate ways to write this take a look at some more SkookumScript examples on RosettaCode.)
Then commit the method (compile and send the changes to the project runtime) by going to the "Build" menu and select "Commit" press the "Commit" icon (gears) on the toolbar or press the
Scripts can only be run when your project is running so start your UE4 project - for example press the "Play" icon on the toolbar or press
P to play in the editor.
Now that your project is running type in the following in the "Workbench (REPL)" tab:
Make sure that the edit caret (sometimes call the edit cursor) is on that line and then press
F4 to execute it.
You should see its output in the SkookumIDE log:
nil is the result of the call to
fizz_buzz() which returns nothing.)
And you've made a simple method.
Look around at other routines to get ideas.
If you look around at other routines in the class hierarchy you may see some that have no code body - i.e. they do not have
] or anything between some code blocks. These routines are defined in C++ - you still see their parameters and description comments though their bodies are written in C++.