Jump to content


Photo
- - - - -

Level Editor Example V1.1


  • Please log in to reply
24 replies to this topic

#1 d41

d41

    GMC Member

  • New Member
  • 526 posts

Posted 12 December 2006 - 03:59 AM

LEVEL EDITOR EXAMPLE


Example Title - Level Editor Example
Example Description - This is an example for a level editor. It includes saving, loading, different objects, and it has lots of comments in the code so you can understand it more easily :)
File Type - .zip
Game Maker version - 6.x, Unregistered
Download
Download here
Filesize - 5.68 KB


Features:
- Saving
- Loading
- Placing different objects
- Snapping to a grid

If used, give credit to "d41".
And it would be nice if you linked to "www.d41games.uni.cc" (You don't have to.)

Edited by d41, 09 January 2007 - 01:33 AM.

  • 1

#2 fogger

fogger

    Clockwerk Studios

  • GMC Member
  • 430 posts
  • Version:GM6

Posted 20 December 2006 - 08:33 AM

Nice example/tutorial:.
And I can see you didn't use the 'instance_create then execute string' thing

This is exactly what I'm looking for:..:

Can you do it so that it saves tiles and their layer information?
  • 0

#3 Mr.Fantastic

Mr.Fantastic

    GMC Member

  • New Member
  • 181 posts

Posted 29 December 2006 - 07:15 AM

Very well commented! Anyways, why is it that I cant load. It does not load any saved file. Why?
  • 0

#4 Lord Aztair

Lord Aztair

    GMC Member

  • New Member
  • 25 posts

Posted 17 January 2007 - 12:16 PM

Very nice! Well commented and easy to alter. I didn't really find a problem with it, maybe add a function to change the background colour.

Nice job!
  • 0

#5 RandomGames$$$

RandomGames$$$

    RandomGamesProgramer

  • Validating
  • 283 posts

Posted 23 January 2007 - 10:48 PM

Is there a function in this to play the level?

#6 d41

d41

    GMC Member

  • New Member
  • 526 posts

Posted 27 January 2007 - 02:29 AM

Nice example/tutorial:.
And I can see you didn't use the 'instance_create then execute string' thing

This is exactly what I'm looking for:..:

Can you do it so that it saves tiles and their layer information?

<{POST_SNAPBACK}>

Thanks. For tiles: Maybe you could store the tile's x, y and layer variables in a data structure or array when the are created and then save to a file from that.

ps. What is the "instance_create then execute string" thing you were talking about?

Very well commented! Anyways, why is it that I cant load. It does not load any saved file. Why?

<{POST_SNAPBACK}>

Thanks!
That was a problem with v1. Download v1.1. (I thought I uploaded the new version right when it appeared, but about a month later when I saw it, it was still the old version).

Very nice! Well commented and easy to alter. I didn't really find a problem with it, maybe add a function to change the background colour.

Nice job!

<{POST_SNAPBACK}>

Thanks. Changing the background color is easy: Add a background color button, and in it's left click event put this code:
background_color=get_color(c_black);
Then when you save, before saving all the objects, add a code to save background color. (Same with loading) eg.
file_text_write_real(file,background_color); file_text_writeln(file);

Is there a function in this to play the level?

<{POST_SNAPBACK}>

No. This example is meant to be the level editor, not a game. Besides, you can do that by using the loading code in another room. Then create the player object, then change all the level editor blocks to the real block by putting a code like this at the end of loading:

instance_create(obj_player);
with(obj_leveleditorblock)
{
instance_destroy();
instance_create(obj_gameblock,x,y);
}

:blink:
  • 0

#7 hawk14

hawk14

    GMC Member

  • GMC Member
  • 745 posts

Posted 27 January 2007 - 03:27 PM

in the obj_control 'global left button' event, duplicate the event and make it 'global left Pressed' event, now in the 'global left button' event replace the code with this:
if keyboard_check(vk_shift)
{
//Notice that this is in the GLOBAL left mouse button event. This means
//that it will do this event no matter where the mouse is.
//mouse_x and mouse_y are the positions of the mouse.
_x=mouse_x
_y=mouse_y
//We are setting _x and _y to the mouse positions so that the
//position of the mouse will not change during what we are doing
//in this event.

//FIRST, we need to check if the mouse is in the room and not over the
//selection area, because we don't want it to make objects there.
if(_x>0&&_x<640&&_y>0&&_y<480)
{
    //This is to create an object when you left click.
    //First we will destroy objects that are there so that you don't have tons of 
    //the same object overlapping.
    position_destroy(_x,_y);
    //Then we create the currently selected object at the position of the mouse.
    instance_create(_x,_y,global.currentobj);
    //global.currentobj is the variable we will store the object that gets placed.
    //We will change this variable when you click on an icon for a different object.
}
}
this will allow you to hold down shift to spread the objects around, and if your not holding down shift then it will only make a single one. like the room editor in gamemaker. :P

Edited by hawk14, 27 January 2007 - 06:46 PM.

  • 0

#8 lord wolfban

lord wolfban

    GMC Member

  • GMC Member
  • 362 posts
  • Version:Unknown

Posted 30 January 2007 - 05:09 PM

just wondering can this be used if say u made an .exe and u made something u wanted to add in the game (the player would have to go through a process like file>load to bring in the new features) but would u be able to load the new features and still have the same data? like if u were to do a rpg with skills and u loaded more weps, would the player still have their skills?

is it possible to add levels+objects into a .exe file? would eg if had skills in a RPG and the player had to load some more weps into the game, would the skills be the same?
  • 0

Link to my Illustration/Concept Designer website: clymsmith.weebly.com


#9 d41

d41

    GMC Member

  • New Member
  • 526 posts

Posted 01 February 2007 - 04:33 AM

in the obj_control 'global left button' event, duplicate the event and make it 'global left Pressed' event, now in the 'global left button' event replace the code with this:

<cut>
this will allow you to hold down shift to spread the objects around, and if your not holding down shift then it will only make a single one. like the room editor in gamemaker. :angry:

<{POST_SNAPBACK}>

Cool, Thanks. The reason I did not do that, though, is because: 1) How would they know to use shift? Most people don't read the instructions before playing. 2) Usually you are just placing blocks, and you usually would want to not have to keep clicking.

just wondering can this be used if say u made an .exe and u made something u wanted to add in the game (the player would have to go through a process like file>load to bring in the new features) but would u be able to load the new features and still have the same data? like if u were to do a rpg with skills and u loaded more weps, would the player still have their skills?

is it possible to add levels+objects into a .exe file? would eg if had skills in a RPG and the player had to load some more weps into the game, would the skills be the same?

<{POST_SNAPBACK}>

That's sort of possible. You cannot change the exe, but you can do other things. Here is a way you could do it:

First you would have 3 file extensions. Let's use ".lvl" (level) and ".bcd" (begin code) and ".scd" (step code). On starting the game, you would use file_find_first and file_find_next to search for these. First search for .bcd. Inside those files you would have code to executed when the game starts. Then .scd. That has code to be executed every step. Open up that, get the code and execute it every step.
Then with .lvl, store a level code just like this example. You can make it run the level by using .scd and .bcd files.

.bcd files could have code to make another object, etc.

Then if you had updates you could give people those files.

Although it would probably be much easier to just make a new exe...
  • 0

#10 I.Am.Me

I.Am.Me

    GMC Member

  • New Member
  • 15 posts

Posted 06 February 2007 - 07:09 PM

when i pressed load a .lee file an error came:

ERROR
in action number 1
of mouse event for left pressed
for object obj_load

Error dealing read.
  • 0

#11 lord wolfban

lord wolfban

    GMC Member

  • GMC Member
  • 362 posts
  • Version:Unknown

Posted 14 February 2007 - 03:00 PM

That's sort of possible. You cannot change the exe, but you can do other things. Here is a way you could do it:

First you would have 3 file extensions. Let's use ".lvl" (level) and ".bcd" (begin code) and ".scd" (step code). On starting the game, you would use file_find_first and file_find_next to search for these. First search for .bcd. Inside those files you would have code to executed when the game starts. Then .scd. That has code to be executed every step. Open up that, get the code and execute it every step.
Then with .lvl, store a level code just like this example. You can make it run the level by using .scd and .bcd files.

.bcd files could have code to make another object, etc.

Then if you had updates you could give people those files.

Although it would probably be much easier to just make a new exe...


Yea it would be easier to create new .exe but then the person who might have worked real hard to get their skills up then they have to start again because of a update
  • 0

Link to my Illustration/Concept Designer website: clymsmith.weebly.com


#12 kickassgames

kickassgames

    GMC Member

  • GMC Member
  • 230 posts

Posted 07 March 2007 - 03:16 AM

i don't know if this question was answered but how do you make the levels from the editor load in the game?? sorry if this question was said and answered i don't understand some things
  • 0
Come fight me fool:
Click HERE

#13 d41

d41

    GMC Member

  • New Member
  • 526 posts

Posted 22 March 2007 - 03:49 AM

i don't know if this question was answered but how do you make the levels from the editor load in the game?? sorry if this question was said and answered i don't understand some things


Just save it. Then click the load button and click on the file.

If that doesn't work, try re-downloading it, you may have the older version.
  • 0

#14 Emejapazco

Emejapazco

    GMC Member

  • New Member
  • 5 posts

Posted 26 March 2007 - 05:26 PM

Wow this is a pretty good tutorial. So good I'm posting for the first time ^_^ (im not a noob i just never post!)

Just two things:

1. Is there a way to encode the variables? Maybe multiplying, squaring or using a few trigonometry formulas. Then do the reverse of them when opening the file.
Reason being that if the game was a real game where you can score points, the player can cheat and change the variables even with a program as simple as note pad.

2. Is there a way of setting the default of the file location to my documents or the same folder the game is located instead of the temp folder?
  • 0

#15 d41

d41

    GMC Member

  • New Member
  • 526 posts

Posted 30 March 2007 - 02:42 AM

Wow this is a pretty good tutorial.

<{POST_SNAPBACK}>

:blink:

1. Is there a way to encode the variables? Maybe multiplying, squaring or using a few trigonometry formulas. Then do the reverse of them when opening the file.
Reason being that if the game was a real game where you can score points, the player can cheat and change the variables even with a program as simple as note pad.

<{POST_SNAPBACK}>

Sure. When they are saving, you can do stuff to them. Instead of saving the variables directly, do "x*5" or whatever for each variable in the saving code. Then when you are loading, do the opposite, "x/5" in the loading code. (You can use a more complicated formula, x*5 was just an example)

2. Is there a way of setting the default of the file location to my documents or the same folder the game is located instead of the temp folder?

<{POST_SNAPBACK}>

It's only going to the temp folder because you are running it from the gm6.
Once you save it as a .exe, (Create Executable), it will go to wherever the exe is.

-----------------------------

Do you think I should change it to gmk now that GM7 is out, or should I leave it as gm6?
  • 0

#16 Emejapazco

Emejapazco

    GMC Member

  • New Member
  • 5 posts

Posted 30 March 2007 - 05:51 PM

Since nobody posted a reply to my previous post about encoding/encrypting data, i have written the script myself:

CAUTION!: the following code is advanced-experienced user rated and may baffle novice users :(

This tutorial is written for string variables only. If you have real variables convert the real variable into a string by using the string(variable name here) function.

Firstly open up save object.

If you are saving already defined string you have too create a duplicate of the variable so the code doesn't overwrite your original variable. Call the new variable temp_(variable

name here).
Code1. In this tutorial I'm going to save the variable var1. In the create event put:
temp_var1 = var1

Code2. Also in the create event put the following code:
string_position=1
//This will be used to tell the program the place where the program should change the letter/number.

alphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrst
uvwxyz "
//This will be used later! There must be a space at the end if the string.

random_string="//put in you random letters here"
// Remember random_string must be exactly the same length as the alphabet string.
//Also do not repeat any letters otherwise you will have major problems when loading.

no_line="0123456789"
//This is for encoding numbers. Again do not repeat numbers!

I will be using all of these variables later and you should be able to understand it better then.

Code3. The next bit of code may take a while to explain:
Again put it in the create event.

repeat(string_length(temp_var1))//Basically it says repeat this however long temp_var1 is.
{
replace_letter=string_char_at(random_string,string_pos(string_char_at(temp_var1, string_position),alphabet))
//Sets the letter that is going to be replaced. It gets the character at the place (string_position), looks where it is //in the alphabet and returns the letter in random_string at the same position.

temp_var1=string_delete(temp_var1,string_position,1) 
//Deletes the letter at string_position

temp_var1=string_insert(replace_letter,temp_var1,string_position) 
//Replaces the letter you just deleted with replace_letter.

string_position +=1 
//Sets the string position to +1 so when the code is repeated it moves to the next letter.
}

Thats it for encoding! All you have to do is save the temp_var1 like in the original tutorial.

When you load the file you will need to decode it. Do this by loading like in the original tutorial but put only the last 2 codes in to load object.

Put the first bit of code in the create event and the second code in the left pressed event AFTER the original code if your using the same principles of the original tutorial.

Now got to that second code and where it says replace_letter=....,alphabet)) switch random_string with alphabet and alphabet with random_string. This code should now do

the exact opposite of what it did in save object and replace the random_string letter with the letter from the alphabet. If you have done everything exactly how i have designed
this should work.

NOTE!
Remember that variable you made called no_line? This is to save numbers. you can do this by changing wherever it says alphabet in code3 to no_line. Simple as that!

If the code doesn't work and you are getting really frustrated bug me enough and i might make an example file. :D

I will try to make the example file any way but it depends on if i have enough time.

Happy saving and loading! :blink:
  • 0

#17 shadowhunt

shadowhunt

    GMC Member

  • New Member
  • 3 posts

Posted 19 May 2007 - 04:56 AM

amazing... completley amazing howver just one small possibility
placing tiles, that can prove to be very important but still, amazing.
  • 0

#18 metal-games

metal-games

    metal-games

  • New Member
  • 732 posts

Posted 28 May 2007 - 07:34 PM

This has give me a good idea-made a game editer.exe and a player.exe and make the level with the editer and play it with the player-it should work as long as they have the same object names.
  • 0

#19 d41

d41

    GMC Member

  • New Member
  • 526 posts

Posted 01 June 2007 - 01:40 AM

This has give me a good idea-made a game editer.exe and a player.exe and make the level with the editer and play it with the player-it should work as long as they have the same object names.

<{POST_SNAPBACK}>

Well, actually, no, that won't work. It keeps track of the object's ID, not its name. But it can be easily modified to use the names and not the IDs. Just change the save code to write a string with the name of the object instead of the object ID, also change the load code to create the right objects.
  • 0

#20 gymnastdaniel5

gymnastdaniel5

    Roboleader

  • GMC Member
  • 1018 posts

Posted 09 July 2007 - 06:33 AM

The code you made for the player doesn't work... it says:
_________________________________________

ERROR in
action number 1
of Key Release Event for <unknown> Key
for object obj_gameblock:

Creating instance for non-existing object: 224
  • 0

#21 irregular

irregular

    GMC Member

  • GMC Member
  • 1271 posts

Posted 09 July 2007 - 11:46 AM

wouldn't using multiple layers of tiles work better? I just think that objects are a strange way to do it. and lots more coe if you have a lot. But hey, that's why I coded mine different.
  • 0

#22 metal-games

metal-games

    metal-games

  • New Member
  • 732 posts

Posted 09 July 2007 - 12:39 PM

This has give me a good idea-made a game editer.exe and a player.exe and make the level with the editer and play it with the player-it should work as long as they have the same object names.

<{POST_SNAPBACK}>

Well, actually, no, that won't work. It keeps track of the object's ID, not its name. But it can be easily modified to use the names and not the IDs. Just change the save code to write a string with the name of the object instead of the object ID, also change the load code to create the right objects.

<{POST_SNAPBACK}>


I did it-i saved this a a gm6 and copyed it and made the objects do diffrent things.
  • 0

#23 d41

d41

    GMC Member

  • New Member
  • 526 posts

Posted 09 July 2007 - 07:18 PM

Player code? Huh? Is this a problem with the level editor example, or have you edited it at all? It looks like you saved a level with a certain object, and then deleted that object from the gmk and tried to load it?

Are you making two separate games, eg leveleditor.exe and levelplayer.exe? If so, that is your problem. It stores the ID's of the objects, and not the object names. So even if the objects in to two games have to same name, it will not work. You can fix this by changing the save code to save the object name instead of the ID, and also change the loading code accordingly.

Good luck...!
  • 0

#24 Nocturne

Nocturne

    Nocturne Games

  • Administrators
  • 25708 posts
  • Version:GM:Studio

Posted 12 July 2011 - 08:24 PM

Std Msg: Please use the tutorial template header (The Tutorial Clean Up Crew).

  • 0

U1FVsm3.png

40799.png


#25 Greenhawk

Greenhawk

    Gue Games

  • GMC Member
  • 722 posts
  • Version:GM:Studio

Posted 09 August 2012 - 04:08 AM

sp how do you make it playable in tds games?
  • 0

Games Made:

 

Youtube Channels:

One of the many GMC Gurus.