Welcome Guest [Log In] [Register]
Welcome to Mp2d. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Learning
Topic Started: Mar 20 2008, 04:08 PM (1,357 Views)
edthedestroyer
Member Avatar
Elite Pirate
[ *  *  *  *  *  * ]
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);
");
As good as banned.
New home.
Offline
 
Timmeh
Member Avatar
The Electryc Penys
[ *  *  *  *  *  *  *  *  * ]
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?
Posted Image
Offline
 
edthedestroyer
Member Avatar
Elite Pirate
[ *  *  *  *  *  * ]
I think thats for using " in text. I'd solve this by creating one or two scripts.
As good as banned.
New home.
Offline
 
Timmeh
Member Avatar
The Electryc Penys
[ *  *  *  *  *  *  *  *  * ]
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.
Posted Image
Offline
 
Timmeh
Member Avatar
The Electryc Penys
[ *  *  *  *  *  *  *  *  * ]
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,size*aspect_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,size*aspect_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+"<filepath>"+global.qt+",1,0,0,0,1,0,0);
options_button_sprite = sprite_add("+global.qt+"<filepath>"+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,size*aspect_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,size*aspect_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);

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.
Posted Image
Offline
 
DeProgrammer
Member Avatar
Elite Pirate
[ *  *  *  *  *  * ]
Did you try "" for quotation marks? That's one way to do it in Visual Basic. Another is Chr(32), but I doubt GameMaker even has a Chr() function.
Posted Image
Signature by Rewrite.
My talent comes from deep within...like vomit!
Offline
 
Timmeh
Member Avatar
The Electryc Penys
[ *  *  *  *  *  *  *  *  * ]
Read the first non-commented line. <_<
Posted Image
Offline
 
Troid92
Member Avatar
Music God / Temp Admin
Admin
You can use 'single quotes' inside "double quotes" for the first layer of strings inside strings. From there on it looks like you'll have to go with the chr(34) thing though. After about three layers I started getting an error that looked like it was adding the quotes to the previous layer and unavoidably messing that string up, but I may have been doing something wrong.

I'm really surprised GM doesn't have anything around this though, seeing as it's a very string-based language, and every other language I can think of has something...
Posted Image
MIDI-maker / Fangame Programmer
Yay red text.
Offline
 
Timmeh
Member Avatar
The Electryc Penys
[ *  *  *  *  *  *  *  *  * ]
Good to know. Thanks :D
Posted Image
Offline
 
Timmeh
Member Avatar
The Electryc Penys
[ *  *  *  *  *  *  *  *  * ]
Quote:
 
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?

EDIT: Oh, I figured it out as I posted this.
Woot.
The .exe was compiling onto my desktop.
Posted Image
Offline
 
Timmeh
Member Avatar
The Electryc Penys
[ *  *  *  *  *  *  *  *  * ]
Okay, scripts cannot be defined outside of the UI.
So, we'll have to use scripts.
Give me a bit to figure out if this means I should reorganize the structure I'm currently using.
Posted Image
Offline
 
Timmeh
Member Avatar
The Electryc Penys
[ *  *  *  *  *  *  *  *  * ]
The code so far:
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,size*aspect_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,size*aspect_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+"battleroombutton.bmp"+global.qt+",1,0,0,0,1,100,25);
options_button_sprite = sprite_add("+global.qt+"optionsbutton.bmp"+global.qt+",1,0,0,0,1,100,25);
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(room_width/2,50,battle_room_button_object);
instance_create(room_width/2,room_height-50,options_button_object);
");

room_being_set = global.options_room;
room_set_width(room_being_set,size*aspect_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,size*aspect_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);

Today, we're going to get rid of the idiotic quotation problem, with the clever use of scripts.
We're then going to fill the title page with stuff, so that our game starts with a pretty animation.
We're also going to start working on the options menu.

Part 1 - the idiotic quotation problem:
Teacher: What, Johnny, is a script?
Johnny: A script is a bunch of code that you can run at any time!
Teacher: That's a stupid explanation, but I don't have any better ideas, so sure.
Johnny: D=

So, if we've got a bunch of code (the creation code for a room) that we want to run at any time (at the room creation), we just have to put the code into a script.
Since we can't define scripts except using the UI, create a script called menu_room_creation, and just copy/paste the creation code from earlier into the script.
Code:
 
battle_room_button_sprite = sprite_add("battleroombutton.bmp",1,0,0,0,1,100,25);
options_button_sprite = sprite_add("optionsbutton.bmp",1,0,0,0,1,100,25);
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(room_width/2,50,battle_room_button_object);
instance_create(room_width/2,room_height-50,options_button_object);

Since we don't have any nested quotations, we don't have to use global.qt anymore.
We'll keep the variable for now, in case it comes in handy later - we might not be able to replace EVERYTHING with a script.

Part 2 - the title page:
Start by changing the room in the last line to "title_room", instead of "menu_room". Keep the "global.".
We want the title screen to be the FIRST THING that people see upon opening the game. Always.

Good components of a title room:
1) an animation
2) a way to skip the stupid animation, cause no one wants to see it

We'll be working in the creation code of title_room. By this I mean a new script, entitled title_room_creation, and with this typed into it:
Code:
 
timmy_prods_sprite = sprite_add("timmy.bmp",1,0,0,0,1,0,0);
slice_anim_sprite = sprite_add("slice.gif",1,0,1,0,1,0,0);
timmy_prods_object = object_add();
slice_anim_object = object_add();
object_set_sprite(timmy_prods_object,timmy_prods_sprite);
object_set_sprite(slice_anim_object,slice_anim_sprite);
object_event_add(timmy_prods_object,ev_keypress,vk_escape,"room_goto(global.menu_room);");
object_event_add(slice_anim_object,ev_step,0,"if(self.x < 330){self.x += 5;}");
instance_create(1,1,timmy_prods_object);
instance_create(1,1,slice_anim_object);

You'll need the following files:
http://timaster.googlepages.com/slice.gif
http://timaster.googlepages.com/timmy.bmp
Feel free to change timmy.bmp to whatever you want.

Note that one of the values in slice.gif changed from the usual 0 to a 1. Slice.gif is partially transparent (the left side).

Now, go to edit>global game settings, and under other, turn all the "let some stupid key do something stupid that you don't want it to" options off.

Now we are able to skip the intro animation with the escape key. We are not, however, able in any way to quit the stupid game. Let's add a quit button to the main menu.
First, make the button.
http://timaster.googlepages.com/quitbutton.bmp
Oh, shit, I forgot to give you the smaller versions of the other buttons, I think.
Here they are:
http://timaster.googlepages.com/battleroombutton.bmp
http://timaster.googlepages.com/optionsbutton.bmp

Just in case, I'm going to start uploading the ongoing progress at the end of every few posts. I'll also add the link in the first post.

Anyway, now we have the quit button. So change the creation code of the menu room to include the button.
Code:
 
battle_room_button_sprite = sprite_add("battleroombutton.bmp",1,0,0,0,1,100,25);
options_button_sprite = sprite_add("optionsbutton.bmp",1,0,0,0,1,100,25);
quit_button_sprite = sprite_add("quitbutton.bmp",1,0,0,0,1,100,25);
battle_room_button_object = object_add();
options_button_object = object_add();
quit_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_set_sprite(quit_button_object,quit_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);");
object_event_add(quit_button_object,ev_mouse,ev_left_button,"game_end();");
instance_create(room_width/2,50,battle_room_button_object);
instance_create(room_width/2,room_height/2,options_button_object);
instance_create(room_width/2,room_height-50,quit_button_object);


Now, I want to work on creating a piece of code for each room that clears the information from each room as we move between rooms.

We'll make a new script for this, called "*_room_clear", for each room.
So far, "menu_room_clear" and "title_room_clear".
The script will have to run from somewhere, so in each room, we need to create a passive object, with no sprite or anything. We'll also change our already written code around a bit, for the title room, and put this object (passive_object will be its name) in charge of skipping the intro animation.
This object we've created for each room will do everything that a tangible and/or visible object isn't doing.

Now, frankly, I'm way too lazy/tired to explain and provide code for everything, or proofread this post, so I'll quickly tell you what happened in debugging, and then you can go look at everything at the end of the post.

Debugging: Decided to place all of the variables set in the creation code inside the passive_object, and rename the passive object to "this". Instead of having everything take place directly inside the room creation code, it will take place inside of passive_object, and the creation code will only directly initialize passive_object. This is a HUGE change, actually, since now the entire game will take place in a series of "passive_object"s. This makes it easy to create variables global only for the room. Which I want.

Here's the link (the .exe inside is the right compiled .exe):
http://timaster.googlepages.com/RTS.rar

PS Please note that the battle room does and should look like crap. This is because I enabled the option of setting views for it, but did not set a view yet.
Posted Image
Offline
 
Timmeh
Member Avatar
The Electryc Penys
[ *  *  *  *  *  *  *  *  * ]
Alright well, no one really cared, but I think I'll continue where I left off for my own sake after my graphics card fan arrives on Monday (assuming I can get it to work).
Posted Image
Offline
 
Timmeh
Member Avatar
The Electryc Penys
[ *  *  *  *  *  *  *  *  * ]
The new fan apparently doesn't quite work.
By which I mean, it moves like 0 air. Though it only crashed the comp when I was playing WoW with all maxed settings, so maybe I can do regular stuff fine.
Posted Image
Offline
 
CloudVaris
Member Avatar
Omega Pirate
[ *  *  *  *  *  *  * ]
Timaster,Apr 28 2008
10:26 PM
The new fan apparently doesn't quite work.
By which I mean, it moves like 0 air. Though it only crashed the comp when I was playing WoW with all maxed settings, so maybe I can do regular stuff fine.

Ouch >_< Maybe you can get it to work all right with some tweaking? As unhealthy as it sounds for my computer, I had to mess with some stuff in my CPU fan to make it work right <_<


Edit: Also, I didn't know you played WoW. Sucks for me, though <_< just one more person that probably doesn't play guild wars >_<
Posted Image
Offline
 
ZetaBoards - Free Forum Hosting
Enjoy forums? Start your own community for free.
Go to Next Page
« Previous Topic · General Discussion · Next Topic »
Add Reply