Gw Temp


Tutorial - 'The Basics of Sphere revealed' by bluemoogle

An item about Sphere posted on


Another article on Sphere. In this one BM goes back to basics!


Basics of Sphere Scripting.... REVEALED!
by blue_moogle of GamingW (

/- Contents -\

1. Introduction
2. Understanding Whats going on
3. Functions
4. Variables
5. If then Else cases
6. Final Words

/- Introduction -\
Ok, so you got sphere. Now what? Scripting comes to your mind.. and you have NO clue how to script, do you. Well, dont'
worry! I'm here! I'll teach you everything you'll need to know basically.. and more! But this is only part 1... the
basics. If you are an RM2k Users, I greatly suggest reading my other tutorial "Switching from Rm2k to Sphere". Alright,
onto the tutorial!


/- Understanding whats going on -\
First thing is first. You should already know what sphere does, and how to configure it properly. Secondly, you should
be free for atleast a half and hour to test everything. Here's some resources I suggest getting, for testing purposes:

scholar.rss (or any spriteset, but I'll be referring to this one) (or any MOD based music file, but I'll be referring to this one)
main.rfn (or any font, but I'll be referring to this one)

Ok, you got your resources. Good job! Now go read my other tutorial (switching from Rm2k to Sphere) to know how to use
these basically. When you're done with that, come back here, and we'll use em again! (but keep your other script you made
in the other tutorial).

Now that's done, make another script. If you don't remember how, just rigth click on SCRIPTS in the HQ area and click
insert. Give it a name.. I suggest test. Now we can move on!

First thing is first.. having this script is utterly useless unless we evaluate it atleast once. In other words, its
like having some food but you haven't cooked it yet. Well, we have to "cook" the script before we can use it. To do
so, open any already evaluated scripts (generally, if this is your second script, the only evaluated one will be your
starter script). Put this line of text anywhere you want in your script (doesn't have to be in functions).


Note, that is case sensitive.. from the EvaluateScript part, to the Name of the script. Remember this! For if you are
getting an error, its generally from not casing things right! Ok.. by doing this, you made Sphere "activate" the script
that its evaluating. Don't worry! Its not so complex! When a script is evaluated.. everything in a FUNCTION is made,
but not done. In other words.. the FUNCTION BOB is made, so you can use it later, but whatever BOB does, will not be
done untill used.

If you have code thats outside of a function, its MADE and DONE. Example, if you have a variable set as music file, and
then you play this variable, the music will ACTUALLY be played when evaluating the script. Here's something you should
remember related to this:

GLOBAL = Outside of a function
LOCAL = Inside a function

Now.. you may not be using these words now... but later on, you'll need to know the difference! Alright.. now we got our
script nicely made and evaluated! Lets move onto what this script will do!


/- Functions -\
If you pretty much understand what functions are, I suggest skipping this part.. all it does is explain them.
Alright.. functions are the core of Sphere. They do everything they want you to do. A function is basically lines of
code that you want to use over and over again. Like a MESSAGE box type function you'll probably want to use over and
over again. Instead of re-writing this message box script AGAIN and AGAIN.. you could just summon this message box
function! Simple as that!

Functions can be named anything. If you have a message box function.. YOU Don't have to call it message box! You can
call it FIRE ALARM or FLDUALSKUFLKAUSF if you wanted. Its just reasonable to have your functions be named what THEY
do. All functions must be organized into something similar to what is shown below.

function *name*()

Heres what each part of the function does:
function = duh... meaning that the follows is a function.
*name* = replace this with the name of this function. Must be unique from other ones!
() = putting things in there is used by some scripts.
*code* = replace this with the code. The code is what the function does!
{ and } = starts and ends the function.

Thats it... a function is nothing more, nothing less. Simple as that. Well.. theres other types of functions.. but they
do things differently than this kind. So don't worry about them untill you get that far.


/- Variables -\
Ok.. single handily.. Variables are the MOST imporant thing in the world of coding. Not even functions are as important.
In sphere's case.. variables DO everything.. from HOLDING music.. to TEXT.. to numbers.. pictures.. to whatever! You can't
make a game without variables. Remember that GLOBAL and LOCAL stuff I said earlier.. this applies to variables.

If you -make- a variable in a function.. its a local variable. AFTER The function is ended, THE VARIABLE is destroyed (loses
its current value and its name.. whatever.. its just GONE.) Though you can keep making it come back when you just resummon
the function.. you might want variables to be there Forever. No worries! Thats what globals are for!

If you -make- a variable outside a function.. its a GLOBAL variable. Usually global variables are made when the script is
evaluated. But don't worry.. IF you -edit- the global variable in a function.. it won't get destroyed, but will keep its
value it recieved in the function. MAJORLY recommened you make all your variables global so other functions and scripts
can use them. Lets go over some of the types of variables ( I don't know them all.. but man, there sure are a LOT).

var bob = 42;

This is a basic INTEGER variable. It just holds numbers. Here's the basics of it:
var = meaning the following is variable relating
bob = name of the variable you are making/editing
= <-- SETTING the variable
42 = what the variable is storing.
; = ends this line of code

Simple as that. Heres another.

var colors = "blue";

This is a basic STRING variable. A string is some words.. from 1 to as many as you want. Here's the basics of it:
var = meaning the following is variable related
colors = name of the variable you are making/editing
= <-- SETTING the variable
"blue" = what the variable is storing. NOTE, its a STRING, so you must put "" around it.
; = ends this line of code

These two alone can do wonders. If you wanted a simple OFF/ON switch like deal, you could SET it as OFF in the beginning,
and later SET is as ON. Heres some various ways of EDITTING currently made variables.

= <-- setting. DELETES the old value and replaces it with the one you specify
+= <-- for intergers.. ADDS whatever number you specify to that interger
-= <-- for intergers.. SUBTRACTS whatever number you specify to that integer
/= <-- for intergers.. DIVIDES whatever number you specify to that integer
*= <-- for intergers.. MULTIPLIES whatever you number you specify to that integer

Pretty basic huh? STRING variables can only use the set mode. Variables can be SO much much more, too. But.. even though
they are the most important thing in coding.. they are useless without one thing. IF THEN ELSE!!! Those things are almost
just as important.. if not as important!


/- IF then ELSE cases -\
Ok.. we have our variables. Now to use them! First lets make our variable.. in your now evaluated script, put this line
of code in:

var testing = 0;
var testmusic = LoadSound("")

There... this will be our testing integer variable! Now lets test with it! Heres what we'll do. We'll make the music
play if the variable is equal to 5. How? If and else cases! And this now to your script!

while ( testing <= 5 )
testing += 1;
if ( testing == 5 )

Ok.. a WHILE is a type of IF and ELSE. Its like an IF case that'll repeat if equals what you set it to. Heres the basics.

EvaluateSystemScript("time.js") = evaluates the system script time.js. You need this evaluated to use delay() function.
while = type of IF case
testing = variable name
<= <-- type of checker
5 = the number the while is checking for
testing += 1; adds 1 to testing
Delay(500) = waits half a second
If = tyoe of IF case
testing = variable name
== <-- type of checker
5 = the number the if is checking for; = plays the music

Pretty simple, huh? If you don't understand something.. try messing around with it. If it doesn't work, try try again!
Here's the types of checkers for IF cases.

== <-- equal too
<= <-- less then or equal too
>= <-- greater than or equal too
!= <-- not equal too

Some If Case types:

More on the various IF statement cases in other tutorials. For now practice with WHILE and IF... and ELSE if you wish too.
There ya go. You got the basics of scripting! But what about that font file I made you get? Well.. read on to the next
chapter and I'll tell you!


/- Final Words -\
Ok.. you made a script.. but with my help. Will you remember all this stuff? Probably not very likely. So follow these
steps and it should be easier to remember what I said.

1. Create 2 variables, and integer and a string variable. If you didn't get any errors, you pass this part. Have the
integer be 4 and the string be HELLO WORLD
2. Create an If Case (not while) to see if the integer is equal to 5, Put in this case the play music part. If you don't
here music, you pass this part.

1. Create a message box function and have it say whatever a string variable's value is.
-To do so, use these commands and edit it so it'll work.

LoadFont("fontname here").drawText(x,y,"text here");

Hint: Replace "text goes here" with the string variable name! (note, Since its a variable name, don't put "" around it)
If you manage to make text appear on the screen.. Good job! If it doesn't work.. try messing with the X and Y coords to
get it working. And if all else fails.. read my other tutorials! They should explain it!