1

Hello to all of you on the forum, i would like to know if any one of you would help me with something i want to try.
I am trying to make a thing where a user could create a map.
My problem is not making a map my problem is:
I want to save the map in a serten extension, and i want bgt to open that map name when it is chosen from the menu.
How will i let the user select there maps from a menu?
How do i make bgt open the map file with the extension?
thanks in advance

best regards
never give up on what ever you are doing.

Thumbs up

2

It sounds like the find_files function is what you want.

string[] filenames = find_files(*.map); 

That gives an array with all the *.map files in the current directory.
If the issue is how to save/load the data, that is more dependent on the details of your maps.

Some of my games
Keep up to date by following @Jeqofire on twitter!
Ear Ninja?

Thumbs up

3

Please, teach me to create maps in BGT!

Thumbs up

4

Hello and thanks cae_jones
I think the find_files will work
But what i want to do for example:
Int minx= the user's data that he or she created in the file with the extention.

best regards
never give up on what ever you are doing.

Thumbs up

5

Sorry i ment max x, = the data in the file with the extension that is surposed to be loaded to the game, and then i want the user to be able to play on the map that he or she created

best regards
never give up on what ever you are doing.

Thumbs up

6

Here's a rough idea for you:
Create a map class that:
*holds a two dimentional array with enough space to store a number for each tile which will exist in your map. So if your map is 100 by 100 squares, then you'll create an array of 100 arrays, each containing space for 100 integers representing what is found at that location (wall, grass, stone, etc).
*A method which can tell a player, npc, enemy or other actor class whether or not it's possible to walk on the requested square. For example: if(map.getTile(x, y) != WALL) stepTo(x, y);
*A method which can save the contents of the arrays to a file. This is one of the tricky parts but it can be handled in a few different ways. You can use BGT's dictionary and serialize/deserialize functions to do a lot of the heavy lifting, which will be fast but it'll output rather large map files unless you can get creative with how to represent your data (I'd just get something working first before you worry about this).
*A method which can load the saved data back into the arrays in the exact same way it was originally stored.
As it sounds like you're just starting out with BGT, remember as you learn that programming is really about taking large problems (like how do I create a map) and breaking them down into many, very small sub-problems.
To give a real world but simple example: lets say the (big) problem we want to solve is, how do I eat a slice of pizza? Now let's break it down into smaller steps:
*Lift hands.
*Locate plate which contains pizza (which in itself could be broken down into many steps).
*Move hands to previously discovered location.
*Lower hands until they touch plate.
*Grasp hands around pizza.
*Lift hands again.
*Move hands to location of mouth.
*Open mouth.
*Use teath to grasp pizza.
*bite.
*open and close jaw until pizza is reduced to tiny pieces.
*swallow.
*repeat until finished.
This is the way in which you need to think about programming tasks in order for them to seem less daunting.
so to give you general information:
Make sure you understand how to work with arrays (access them, loop through them, resize them, etc). Make sure you know how to use the file and dictionary objects (or objects in general). and feel free to ask when you're stuck. This way, big picture problems like what you're trying to solve will start to make more sense.

Proud to be the official hosting provider for http://www.vgstorm.com!

Thumbs up

7

Hello i already have a few arrauys in the map handelin the x an  y objects.
My problem is, to load and save the maps.
As you said i will have to use deserlisation function in bgt.
But how can i let the user save the file. (the mapM ) and let bgt find that location and display it in a menu?
as i said, i can make a menu, that works but can any one please help me with that?

best regards
never give up on what ever you are doing.

Thumbs up

8

Create a dictionary object.
Loop through your map and insert each square into the dictionary with a key name which corresponds to the location on the map. For example, the index map[0][0] might be stored in the dictionary under the key "map[0][0]". This way you can easily determine from within your loops what the names will be based on the loop counter. For instance, if your outer loop counter is called x and your inner loop counter is called y, then the keyname is like string key="map["+x+"]["+y+"]";
Once all of your squares are in the dictionary it's time to serialize it. Use the serialize function and it will return a string containing everything you just saved. Create a file object, open the file previously requested by the user and stored in a string somewhere and write out the contents of the string you got from serialize. If you wanted to encrypt the maps you would use string_encrypt on the serialized string before writing it to the file.
To load it back in you perform the steps in reverse. Open the previously saved file for reading, read it into a string, decrypt if necessary, use the deserialize function to get it back into a dictionary, then loop through the empty (but correctly sized) map array and load the values in one-by-one.
This takes care of saving and loading. You can ask the user what file they want to save to using input_box or some other means of capturing input.
As for automatically displaying previously saved maps in a menu, you're going to want to use the find_files function to search a directory for files with a given extention. something like string[] maps = find_files("maps\*.map");
If what you want is to search the user's entire computer... I strongly advise against this as it could literally take minutes and could come up with lots of false positives.
So just have the user specify a directory where they want to store maps, and use find_files to search that directory for appropriate files and populate a menu with the results.

Proud to be the official hosting provider for http://www.vgstorm.com!

Thumbs up

9

Will i be able to present the maps in a menu?

best regards
never give up on what ever you are doing.

Thumbs up

10

Why not? Populate the menu with the names of the maps in the order that they're found and they'll directly correspond with indecies into the array returned by find_files.
The run and run_extended methods return the selection made by the user as a number and you'll be able to use that to determine which map was selected and open it for editing.

Proud to be the official hosting provider for http://www.vgstorm.com!

Thumbs up