Learning

Here’s the latest progress on the RTS:
http://timaster.googlepages.com/RTS.rar


original post
[size=2]
So I had this totally crazy idea that probably isn’t going to work… but what if it did?

I’m currently learning like 5000 things at once. So I was thinking I could make a topic and post what I’m doing in it, and let someone else go along with me on this learning adventure.

I’m about to start making a local SQL server out of my computer by installing Linux on it.
All you need for this is about 10GB of free space on your hard drive.
If no one’s interested, I won’t bother regularly updating with what I accomplished, but I’d absolutely love to explore things along with someone else.

Other things I plan on learning sometime soon include:
How to make a GM6 RTS.
Javascript.

If you’re interested in either of those, I can post about those instead.[/size]

!!!

Ho ho. I’ll do that then.
I’m going to be in CT for the weekend, but when I get back, I’ll try and get started with that.
I already had some progress, but it’s back in MI, and I’m in DC.
Woo traveling.

Okay, let’s do this.
Now I’m going to basically write everything I do.

First, though, I wanna make it clear exactly what I’m doing.
I am making a GM6 game that will function as a playable RTS. However, I will not be using this newfangled crap that GM6 supports. EVERYTHING that I can possibly jam into scripts and code will be in scripts and code. I’m doing this simply because I don’t feel comfortable in a regular GM6 environment, but I don’t foresee any reasons why this would fail.

So, to start, open GM6 in advanced mode.

The only objects that can run code, strictly speaking, are rooms. Everything else that triggers functions is inside of rooms; they’re the base. So, this will be the first (and hopefully only) non-code thing that we do:
Create a room.

This room will NOT function as an actual game room, so set everything to 0’s and offs and whatnot (a loading bar might go here later, but don’t worry about that).

Now, we want to make the transition into pure code. So find “Creation code” under “Settings”, and click that.

Ta-dah! We are now functioning within the realm of code.
Here, before we start anything really solid, we will create some portion of the structure of the game. We want to be able to create everything that the interface can through the use of code. I know how to use code to create only Scripts, Objects, and Rooms, but I expect to be able to do all of these (except Paths and Time Lines, maybe) eventually.
Sprites
Sounds
Backgrounds
Paths
Scripts
Fonts
Time Lines
Objects
Rooms
I don’t yet know how to arrange objects in rooms. I expect this all to be very doable, though.

So, let’s create some rooms. What rooms will we need…? Let’s say a menu room, and a battle room. Two menu rooms, even. The first will say “Enter Battle” and “Options”. The second will have options.
To find all of the functions to set rooms, look for “Rooms” in the GM6 help, and click the second entry titled Rooms.

First, we want to create a room. Depending on how you want to do this, you can either clump the room creations together and then have the room settings later, or create and set a room at the same time. I’m going to do the latter.
First, we’ll create the title page room, which is the first menu room I talked about earlier.
global.title_page = room_add();
The “global.” means that this variable is available ANYWHERE in the game. I want this, because I want to be able to quit back to the title page at all times, and if the room index isn’t available, that could be difficult. I could assume that the title page index is 1 (0 is taken by the first room that we just created in the GM6 interface), but what if isn’t, for whatever reason? Best just use a variable.

To make it easier on me if I decide I don’t like the name of the room, or if I want to copy/paste the same settings, I’ll input the room index into a generic variable.
room_being_set = title_page;

Then set all the variables for the room. I’m gonna go do things, and when I come back, I’ll paste the code for the creation of the 3 rooms. Feel free to write your own.

I will entirely fail to continue if no one is actually interested…

You’ve caught my interest with the SQL server and JavaScript. And I’ll follow along with the RTS. Why learn alone?

Heh.
Okay then, I’ll do all 3 =P
To be continued tomorrow.

i never said i wasn’t interested! i said i WAS

just because i didn’t post a reply doesn’t mean i didn’t read it, as i did.

Oh, well, please reply in the future =P

I’m like halfway through writing the room settings.
But before I give you that, a lesson in colors, because they’re neat:
What does GM6 think when it thinks “color”?
I’ll tell you!
We all know what RGB is (if you don’t, wtf are you doing here, get some spriting experience), but GM6 doesn’t know. GM6 thinks in terms of a single number, not 3. Luckily, there’s an easy conversion. Hint: There are 16,777,216 possible colors. The single number goes in range from 0 to 16,777,215.
Okay, I’ll explain.
GM6 has the following color functions (among others):

These functions return a number, which is in the range 0 to 16,777,215. 16,777,216 is 256^3. 16,777,215 is white. 0 is black.
The function that GM6 uses to determine the color from the RGB values is as follows:

R*(256^0)+G*(256^1)+B*(256^2)

So, 0 to 255 is red. 256 to 511 is red with 1 point in green. Etc.
THAT’S color.
So what about HSV? Well, HSV is whacky. V, or brightness for regular people, singlehandedly covers the entire range of 0 to 16,581,374. A V value of 255 is always white, regardless of what the H and S are.
What I’m trying to say is, I have no fucking idea, but HSV is retarded as shit and I will SHOOT YOU if you even think about using it, because it’s an enormous information loss. It still gives you the 0 to 16,777,215 range, but with many holes in-between. There is a loss of at LEAST 196,608 distinct colors.
That’s a lot of colors.
Don’t use HSV.

Anyway, what I’m getting at is that you can do zany shit with colors, since the formula for getting a color from 3 components is very simple. Also, you’ll save at least a tiny bit of processing power by using the number instead of the function for colors.

Thank you.

[code]global.title_room = room_add();
global.menu_room = room_add();
global.options_room = room_add();
global.battle_room = room_add();

/constants for all rooms/
size = 256;
aspect_x = 5;
aspect_y = 4;
def_bg = 1958430;
/*************************/

room_being_set = title_room;
room_set_width(room_being_set,sizeaspect_x);
room_set_height(room_being_set,size
aspect_y);
room_set_caption(room_being_set,“RTS”);
room_set_persistent(room_being_set,0);
room_set_background_color(room_being_set,def_bg);
room_set_view_enabled(room_being_set,0);

room_set_code(room_being_set,"
");

room_being_set = menu_room;
room_set_width(room_being_set,sizeaspect_x);
room_set_height(room_being_set,size
aspect_y);
room_set_caption(room_being_set,“Main Menu”);
room_set_persistent(room_being_set,0);
room_set_background_color(room_being_set,def_bg);
room_set_view_enabled(room_being_set,0);

room_set_code(room_being_set,"
");

room_being_set = options_room;
room_set_width(room_being_set,sizeaspect_x);
room_set_height(room_being_set,size
aspect_y);
room_set_caption(room_being_set,“Options”);
room_set_persistent(room_being_set,0);
room_set_background_color(room_being_set,def_bg);
room_set_view_enabled(room_being_set,0);

room_set_code(room_being_set,"
");

room_being_set = battle_room;
room_set_width(room_being_set,sizeaspect_x);
room_set_height(room_being_set,size
aspect_y);
room_set_caption(room_being_set,“Battle!”);
room_set_persistent(room_being_set,1);
room_set_background_color(room_being_set,def_bg);
room_set_view_enabled(room_being_set,1);

room_set_code(room_being_set,"
");[/code]There, that’s your basic skeleton for the rooms.
Questions?

Nods in agreement
It makes sense so far.

The number should range from 0 to 16,777,215, actually, since there are 16,777,216 colors.

Also, it’s R * (256^0) + G * (256^1) + B * (256^2). Bitshifts. 256 is 1 0000 0000 in binary, which is a shift of 8 bits. The max value is 256^3 - 1, not (256 - 1) ^ 3.

GM isn’t doing it some weird way. It’s simply assigning all three color amounts with one value: the optimal method.

HSV (hue, saturation, value) is calculated some smart way. There is no color loss when using it. All (maybe an exception of 6 or so, but I doubt it) colors can be represented in HSV.

There is color loss with HSV. You cannot represent every color you can make with RGB in HSV.

Though yes, I miscalculated with the 255. Sorry about that.
EDIT: Fixed the numbers in the post.
EDIT2: Found an example in paint, which admittedly doesn’t use the 0 to 255 range for HSV, so it’s guaranteed to have information loss, but the RGBs 253 255 255 and 252 255 255 have the same HSV values.

I almost finished today’s (yesterday’s, now) post, but got stuck in the debugging stage. Project postponed until I can get a hold of troid.

Today, we’re going to make the menu point at things. First, we’ll need images for buttons.
Let’s whip up 400x100 images.
Battle Room
Options

Save these in a folder with your .gm6 file.

Now, we don’t want these images hanging around all the time. We want to create them for the main menu room, and then delete them. So, we’re going to load them into the game at the main menu room creation.

Look for

room_set_code(room_being_set," ");
Where room_being_set is menu_room.

We’re going to fill in the creation code for that room. We don’t really know exactly what the creation code is, though.
I quote from the help page:

In case anyone is a tad confused about instances, here’s what instances and objects are:
An object is a set of properties that are applied to an instance.
An instance is an actual living, breathing thing inside the game.
For example, an object is “ball”, and an instance is the ball you have in your garage. Objects don’t exist, because you cannot interact with them. They are like definitions.

Now, armed with the knowledge of what actually happens when we switch rooms, we can set about making those buttons.
Remember: we are going to DESTROY those buttons whenever we leave the room. Perhaps later, we will want to destroy them only when we enter the battle room. But let’s work with this, for now.

We need to:

  1. Put the sprites of the button objects into the game.
  2. Make objects that have those sprites and change rooms when clicked.
  3. Make instances of those objects.

Go back to that line you found earlier, and write this:

room_set_code(room_being_set," battle_room_button_sprite = sprite_add(battleroombutton.bmp,1,0,0,0,1,0,0); options_button_sprite = sprite_add(optionsbutton.bmp,1,0,0,0,1,0,0); battle_room_button_object = object_add(); options_button_object = object_add(); object_set_sprite(battle_room_button_object,battle_room_button_sprite); object_set_sprite(options_button_object,options_button_sprite); object_event_add(battle_room_button_object,ev_mouse,ev_left_button,"room_goto(battle_room);"); object_event_add(options_button_object,ev_mouse,ev_left_button,"room_goto(options_room);"); instance_create(50,50,battle_room_button_object); instance_create(50,250,options_button_object); ");

To figure out what the hell each line means, type the function name into the “index” tab of the Help file.

Now, we want to test our work. For this, we’ll have to go from the first room, the code for which we are writing, to the menu room. After EVERYTHING we’ve written so far, just write “room_goto(menu_room);”, and then compile and run the executable.

Woohoo, debugging time.

  1. room_set_background_color gave the wrong number of arguments, apparently.
    Yup, I forgot the “show” argument. Add a “,1” in the lines with that function.
room_set_background_color(room_being_set,def_bg,1);
  1. It doesn’t like my "object_event_add"s, for some reason.
    Dunno what the fuck I did, but it made it work, kindof… I took out the quotation marks.

object_event_add(battle_room_button_object,ev_mouse,ev_left_button,room_goto(global.battle_room);); object_event_add(options_button_object,ev_mouse,ev_left_button,room_goto(global.options_room););
But wait until 4)…
3) The global variables need to have a “global.” before them.
4) Now I get the object_event_add error again.
Wtf.

--------END OF TRANSMISSION--------

So yeah, waiting on Troid.

EDIT:
Or Ed.
Here’s my code, and I’ll upload the error message in a sec.

[code]global.title_room = room_add();
global.menu_room = room_add();
global.options_room = room_add();
global.battle_room = room_add();

/constants for all rooms/
size = 256;
aspect_x = 5;
aspect_y = 4;
def_bg = 1958430;
/*************************/

room_being_set = global.title_room;
room_set_width(room_being_set,sizeaspect_x);
room_set_height(room_being_set,size
aspect_y);
room_set_caption(room_being_set,“RTS”);
room_set_persistent(room_being_set,0);
room_set_background_color(room_being_set,def_bg,1);
room_set_view_enabled(room_being_set,0);

room_set_code(room_being_set,"
");

room_being_set = global.menu_room;
room_set_width(room_being_set,sizeaspect_x);
room_set_height(room_being_set,size
aspect_y);
room_set_caption(room_being_set,“Main Menu”);
room_set_persistent(room_being_set,0);
room_set_background_color(room_being_set,def_bg,1);
room_set_view_enabled(room_being_set,0);

room_set_code(room_being_set,“
battle_room_button_sprite = sprite_add(battleroombutton.bmp,1,0,0,0,1,0,0);
options_button_sprite = sprite_add(optionsbutton.bmp,1,0,0,0,1,0,0);
battle_room_button_object = object_add();
options_button_object = object_add();
object_set_sprite(battle_room_button_object,battle_room_button_sprite);
object_set_sprite(options_button_object,options_button_sprite);
object_event_add(battle_room_button_object,ev_mouse,ev_left_button,“room_goto(global.battle_room);”);
object_event_add(options_button_object,ev_mouse,ev_left_button,“room_goto(global.options_room);”);
instance_create(50,50,battle_room_button_object);
instance_create(50,250,options_button_object);
”);

room_being_set = global.options_room;
room_set_width(room_being_set,sizeaspect_x);
room_set_height(room_being_set,size
aspect_y);
room_set_caption(room_being_set,“Options”);
room_set_persistent(room_being_set,0);
room_set_background_color(room_being_set,def_bg,1);
room_set_view_enabled(room_being_set,0);

room_set_code(room_being_set,"
");

room_being_set = global.battle_room;
room_set_width(room_being_set,sizeaspect_x);
room_set_height(room_being_set,size
aspect_y);
room_set_caption(room_being_set,“Battle!”);
room_set_persistent(room_being_set,1);
room_set_background_color(room_being_set,def_bg,1);
room_set_view_enabled(room_being_set,1);

room_set_code(room_being_set,"
");

room_goto(global.menu_room);[/code]

EDIT2:

I have sad news, you can’t execute a string within a string that is bring executed.

Here’s your problem

Each color represents a string how the computer reads it.

room_set_code(room_being_set,"
battle_room_button_sprite = sprite_add(battleroombutton.bmp,1,0,0,0,1,0,0);
options_button_sprite = sprite_add(optionsbutton.bmp,1,0,0,0,1,0,0);
battle_room_button_object = object_add();
options_button_object = object_add();
object_set_sprite(battle_room_button_object,battle_room_button_sprite);
object_set_sprite(options_button_object,options_button_sprite);
object_event_add(battle_room_button_object,ev_mouse,ev_left_button,
“room_goto(global.battle_room);” );
object_event_add(options_button_object,ev_mouse,ev_left_button,
“room_goto(global.options_room);”);
instance_create(50,50,battle_room_button_object);
instance_create(50,250,options_button_object);
");

Oh.

The only way I can think of to solve that.
Is quite frickin’ inefficient.
Oh well.
EDIT: Wait, doesn’t GM6 have a " or something?

I think thats for using " in text. I’d solve this by creating one or two scripts.

I think I came up with a convoluted and stupid solution. I’ll just assign " to a variable, so the actual character doesn’t show up in the code.

[code]/global constants/
global.qt = chr(34);
/******************/

global.title_room = room_add();
global.menu_room = room_add();
global.options_room = room_add();
global.battle_room = room_add();

/constants for all rooms/
size = 64;
aspect_x = 5;
aspect_y = 4;
def_bg = 1958430;
/*************************/

room_being_set = global.title_room;
room_set_width(room_being_set,sizeaspect_x);
room_set_height(room_being_set,size
aspect_y);
room_set_caption(room_being_set,“RTS”);
room_set_persistent(room_being_set,0);
room_set_background_color(room_being_set,def_bg,1);
room_set_view_enabled(room_being_set,0);

room_set_code(room_being_set,"
");

room_being_set = global.menu_room;
room_set_width(room_being_set,sizeaspect_x);
room_set_height(room_being_set,size
aspect_y);
room_set_caption(room_being_set,“Main Menu”);
room_set_persistent(room_being_set,0);
room_set_background_color(room_being_set,def_bg,1);
room_set_view_enabled(room_being_set,0);

room_set_code(room_being_set,“battle_room_button_sprite = sprite_add(”+global.qt+""+global.qt+",1,0,0,0,1,0,0);
options_button_sprite = sprite_add("+global.qt+""+global.qt+",1,0,0,0,1,0,0);
battle_room_button_object = object_add();
options_button_object = object_add();
object_set_sprite(battle_room_button_object,battle_room_button_sprite);
object_set_sprite(options_button_object,options_button_sprite);
object_event_add(battle_room_button_object,ev_mouse,ev_left_button,"+global.qt+“room_goto(global.battle_room)”+global.qt+");
object_event_add(options_button_object,ev_mouse,ev_left_button,"+global.qt+“room_goto(global.options_room)”+global.qt+");
instance_create(50,50,battle_room_button_object);
instance_create(50,250,options_button_object);
");

room_being_set = global.options_room;
room_set_width(room_being_set,sizeaspect_x);
room_set_height(room_being_set,size
aspect_y);
room_set_caption(room_being_set,“Options”);
room_set_persistent(room_being_set,0);
room_set_background_color(room_being_set,def_bg,1);
room_set_view_enabled(room_being_set,0);

room_set_code(room_being_set,"
");

room_being_set = global.battle_room;
room_set_width(room_being_set,sizeaspect_x);
room_set_height(room_being_set,size
aspect_y);
room_set_caption(room_being_set,“Battle!”);
room_set_persistent(room_being_set,1);
room_set_background_color(room_being_set,def_bg,1);
room_set_view_enabled(room_being_set,1);

room_set_code(room_being_set,"
");

room_goto(global.menu_room);[/code]
Success… kindof.

To do list:

  1. I need a way to put in a filepath that works on all computers now. The full path appears to work, but just “battleroombutton.bmp” or “…\battleroombutton.bmp” or even “.\battleroombutton.bmp” don’t work. Help?
  2. I need to make the buttons smaller, or the room bigger. A size of 256 is too big, and this size (64) is too small. I’ll just adjust the bitmaps or something.
  3. I’m not sure the buttons are actually going to the rooms I’m sending them to.