Spherical forums

Creations => Game Development => Topic started by: East on April 12, 2017, 10:07:55 am

Title: RPG Events in Sphere
Post by: East on April 12, 2017, 10:07:55 am
Hi guys! Came back here after a long, long hiatus from Sphere and developing in general and for the past few days I've been scripting and photoshoping like crazy, after I found my Sphere project while cleaning up my old PC.

I came into the Sphere world after a few years of working with RPG Maker 2000, and one of the things that I found most difficult is creating events for a story-driven game. I got used to RM2k's quality of life and the task of scripting every event from scratch in Sphere made me give up on the idea and instead, just focus on creating gameplay elements like a battle system, movement system, etc.

Now that I came back I've tried to come up with a way to create an event system that will allow me to create new events on the fly, that won't feel like some dirty job that will put me off after a while.

At first I had a single "events(switch)" function with a switch inside of it, that I could call whenever I wanted for simple events. The actual event code was right inside the case section that was called. The problem was that I could only make it work with very simple events, such as changing variables or objects, a single box of dialogue, etc. It was nice for a start but I couldn't do anything substantial with it and it actually put me off for a while as I didn't feel like I could script any narrative using it.

Yesterday I had the idea of integrating an events system into the update script of my active battle system. The update script is active almost all the time, even when combat is toggled off, and I figured that if I can use it to create complex skills with multiple phases, I can probably use it with some kind of loop system to create events.

What I came up with was once again, an event(switch) function, but this time each switch case called a secondary function, and inside that function was the actual event script.

The first function is called from inside the update script whenever var event_taking_place says so, and the secondary function is built from sections of if cases, checking a main "event step" variable and a secondary "event loop" one. After each step, the first variable gets +1 and the loop variable gets reset. I tried to mimic what I used to do with RM2k and I look at every "step" section like a line of "code" in RM.

It looks something like this:

In the update script:
Code: [Select]

if (event_taking_place) events(event_title);

So that when I want to call an event, I set the "event title" variable to the one I want to call and then turn on the "event taking place" one.

In event.js:
Code: [Select]
function events(event_title) {
switch (event_title) {

case "RaditzShowsUp":
// Raditz shows up at Master Roshi's House, freaks everyone out, takes Gohan and flies off


(Yep. It's a DBZ game)

And then:
Code: [Select]
function event_raditzshowsup() {

// Step 1: Raditz shows up and steps forward
if (event_loop == 0) {
CreateMapPerson({ name: "Raditz", spriteset: "enemies/raditz.rss", x: 19, y: 27, layer: 0 });
QueuePersonCommand("Raditz", COMMAND_FACE_NORTH, true);
MoveNPC({ name: "Raditz", command: COMMAND_MOVE_NORTH, tiles: 1 });
SetPersonScript("Gohan", SCRIPT_COMMAND_GENERATOR, ""); // gohan stop moving
event_step = 1;
if (event_loop >= 50 && event_step == 1) {
event_dialogue_done = false;
event_talker = "Raditz";
dialoguelist[0] = new msg(event_talker,"Ah, there you are, Kakarot!",event_talker, true);
convo = true;
event_step = 2;

// Step 2: Move 2
if (event_loop >= 100 && event_step == 2) {
if (event_dialogue_done){
if (!convo) {
QueuePersonCommand("Raditz", COMMAND_FACE_NORTH, true);
MoveNPC({ name: "Raditz", command: COMMAND_MOVE_NORTH, tiles: 1 });
event_loop = 0;
event_step = 3;
} else { event_loop = 0; }

... And so on, when the last step calls an "end_event()" function to reset everything and close things up.

AAAnd... after all that, and considering I'm kind of a coding noob, I just want to ask, is this an OK system to have? What I was worrying about is if the act of calling a function inside a function inside a function, etc. etc., with a loop variable, from an update script, may be too much on the game engine and will cause problems down the road when I have more systems running? Right now it seems fine but I don't wanna find out too late that I broke something beyond repair.

Also, I would love to hear suggestions and ideas for a - maybe - better event system, and feel free to correct me/notify me/tip me about weird things in my code, as I said, I'm pretty much a noob in coding but somehow I do know how to get things to work, using functions from the API (and that's what I'm afraid of  ;D :P).

This turned out to be quite the wall of text so thanks if you've made it this far!  :)
(Attached: screenshot of said event taking place)
Title: Re: RPG Events in Sphere
Post by: Fat Cerberus on April 12, 2017, 10:18:11 am
You should look into using miniSphere's "scenes" module for this (you should definitely upgrade to miniSphere if you haven't already):

No need to reinvent the wheel, this functionality is built-in now. :)
Title: Re: RPG Events in Sphere
Post by: East on April 12, 2017, 10:30:08 am
A quick question about miniSphere - is the LoadSoundEffect function gone? I actually tried it last night but whenever I tried to test/debugg my game, I got a message telling me that LoadSoundEffect is undefined. Haven't had time to try and fix it, should I just change every LoadSoundEffect into LoadSound?
Title: Re: RPG Events in Sphere
Post by: Fat Cerberus on April 12, 2017, 10:32:41 am
LoadSoundEffect() was a Sphere 1.6 function.  Since 1.6 never made it out of beta I didn't bother implementing most of the 1.6 API.  Games pretty much got written for 1.5 only so that's what I implemented.
Title: Re: RPG Events in Sphere
Post by: East on April 12, 2017, 10:34:55 am
Allrighty then. Off to try it out! ;D
Title: Re: RPG Events in Sphere
Post by: Ma3vis on April 12, 2017, 07:14:56 pm
Hi East! Welcome back, Sent you a PM :)