KKinsane The Beginners Diary/Entry 1
From Spheriki
Contents |
Entry #1
Date: 17th June 2006
A little introduction
Ok, now that I've figured out how to use wiki I can finally get to work. First off i'm going to explain a bit about what these diary entries will include.
Each entry in the diary will be pretty much a step by step guide of what I did, its not necessarily going to be the right way, but we'll just have to see won't we!
Also, screenshots are going to be included quite often, the easiest way to learn is to use images as well as words.
My system
At this moment in time I'm using an Emachines 590, Windows XP is the Operating System in question, 60GB hard drive, 2.40 GHZ Pentium 4 processor, A good summary of this pc would be, runs almost anything, but not always with good results, we shall see if this limits anything in sphere in time. Also,
I am using Sphere version 1.1 (this is incase this tutorial gets back-dated)
Getting Started
At the moment, there's a problem with the latest updates file path, i'll update this as soon as the problem clears
Development Environment
This is where you want to be looking, We are never going to get anywhere without starting, so click on the folded paper icon, this creates a new project. You will see a little pop-up asking you what you want the project to be called and what the game will be called. Lets put test in both boxes for now. Click ok and a new window opens inside of sphere, no taking up of taskbar space which is very good.
All the folders are empty right now, the only thing you can click on is the "Game Settings" option, so lets do that!
Game Settings
Looks like we can change the title of the game in here, as well as set the resolution, type your name in the author bit, put a description and set a main script.
I remember from the last time I used sphere, the Main Script is the first script that Sphere's engine looks at when starting up a game. So, logically, we need to make a main script for the engine to read, and the script has to do something.
Lets start with something simple, I am going to try to make a script that gets the engine to display the text "HELLO SPHERICAL!"
Ello Dave
But first, Cigarette break (and some more Pro-Plus)
Hello World, we hope
The reason i'm choosing the hello world variant script is because its usually the easiest thing to learn in any scripting language.
First thing we need to do here is to create the new script. Go to file-->New-->Script, this will bring up a scripting window.
At the moment there is little to look at, the number is the line referance, this is useful for going back to a line thats causing a problem.
Right now, I haven't got the slightest clue of what I should type to make this work, so lets find a tutorial to work with.
About 10 minutes later...
http://sphere.sourceforge.net/flik/docs/sphere-1st.html - This one looks useful, this is flik's first tutorial, and the first portion of script in there is exactly what I was looking for :)
The script is:
EvaluateSystemScript("time.js"); // for Delay
function game()
{
GetSystemFont().drawText(0,0, "hello");
FlipScreen();
Delay(500);
}
This may look quite confusing, but this script isn't to hard to understand.
The first line tells Sphere to use the system script "time.js" within this script, the comment (// for delay) tells us that this script is probably for the part of the script that says "delay(500);"
Comments
Comments can be used like this eg.
script_here(); // this is a comment
or this
/* this is a comment pretty neat huh? */
for multiple lines :)
Function Game()
This one as far as I know starts everything off, i'm not really sure how exactly it works, but it is very important. Send me a PM explaining what this does and I'll edit this in later.
Confused yet?
As much as I know what this script does, I'm not entirely sure how to explain it all, but heck, this was always about trial and error.
Functions
The game function is the function that the engine immediately looks for and executes.
This is the only function that is automatically executed. All other functions must be 'pointed to'
through the game function or activated via triggers, personal scripts or special scripts.
Syntax: function game(parameters){commands}
I found this in the local documentation of sphere, you can find this by clicking help-->local documentation, there is a compiled html file in the "contributed folder"
So basically, Function Game() is the only function automatically read by the engine. the brackets encapsulate the commands of that function. We will have a more in depth look at functions later on, for now, back to the script!
Moving on
GetSystemFont().drawText(0,0, "hello");
This is the bit that draws the text, as I said, i'm planning on making it say "HELLO SPHERICAL!" therefore, were going to want to change this. the numbers represent the x and y axis, starting from the top left of the screen. Changing the x axis would make the text appear at a different place horizontally, as y would do vertically. using a negative number would also work, but if we did that the text would probably go offscreen.
the bit that says "hello" is what we are interested in, this is what the text will display, so lets change this to "HELLO SPHERICAL!"
Flipscreen()
FlipScreen <-- This one explains it pretty well :)
Lastly there is the delay(500); bit, this believe it or not is a completely separate function! If you go into the sphere files, look for system and then scripts and the time.js script, you will see the following code.
function Delay(milliseconds)
{
var start = GetTime();
while (start + milliseconds > GetTime()) {
}
}
looks like this script delays the next action for 500 milliseconds, that's about as much detail as we need to go into about this one.
Editing the script
As I said, we want this script to say "HELLO SPHERICAL!", so change the word hello into HELLO SPHERICAL!, and change the delay to 2000, just to make sure we don't miss it, as the delay is the only thing that stops the program from closing at the minute.
So, our script should be:
EvaluateSystemScript("time.js"); // for Delay
function game()
{
GetSystemFont().drawText(0,0, "HELLO SPHERICAL!");
FlipScreen();
Delay(2000);
}
Click the floppy disk icon to save and click the little lightning icon to run the game!
Did it work?
Well, on my pc I got a black screen and then the words HELLO SPHERICAL! appeared breifly in the top left corner. This is pretty much what I expected to happen, which is good.
It would be better if you had to press a button to close the program though, lets work on that next!
Knackered and my camera's busted
Thats all for now, getting pretty tired, need some more pro plus, been working on this for about 6 hours I think, it was well worth it though :) Peace out
What I learned
In this Diary Entry I learned how to:
- Download Sphere (Though there is a problem at the moment...)
- Open sphere, Make a new project and make a script
- Used a tutorial to learn how to draw text onscreen
And finally, the value of caffeine when you have to work for a long period of time :)



