Play the games, create the levels

Topic, Path 4 Mouse Help

Checkout our iPhone & iPad games!

You must register or log in to post a message.

jp 15 years ago
  gecko, can you tell more about "replaced the old ones", what exactly did yuo do ? Can you give also the url of the archive you downloaded ?
Captain_404 15 years ago
  Are there any errors in the output box?

Maybe you should host your fla's and version of the api you're using online somewhere. I know I don't have flash 8 so I couldn't look at it and test it for you, but jp might be able to help. Although that's really up to him...
geckojsc 15 years ago
  I downloaded all the latest API files, replaced the old ones, compiled editor_example1.fla, then uploaded the swf... It still didn't work...
Have a look at the game and see for yourself, you can type in the text box, you can capture a thumbnail, but you can't save, upload or test the level...
jp 15 years ago
  @Captain, yes it's an old bug of the Flash IDE (I didn't see this bug anymore on Flash CS3). Sometimes, it doesn't detect that an external class has changed (!!!).
Captain_404 15 years ago
  Also, I've found sometimes when I use a new version of the API, it doesn't immediately load the new version into flash. You could try editing MyGameManager and MyEditorManager by just adding some white space (but no actually lines of code) and then saving to make sure your swf is using the latest version.


In response to you code question.

The unserializeAndPlay function will only be called once the level is loaded. Your code that displays the level is on the first (ok, actually second) frame of your game, meaning that it will run once the game loads, not once the level loads. You can run this code once the level loads by putting it inside of a function and calling that function from within the unserializeAndPlay function
jp 15 years ago
  About the level editor, I tested the download package and it works. This is what I made :
- I downloaded the package here http://www.bonuslevel.org/about/f8.rar
- I unrared the package.
- I compiled editor_example1.fla
- I uploaded editor_example1.swf on my game.

When I click on the UPLOAD button, it works and save a level.

Can you try to do exaclty the same ?

In case you copied some of the files from the apckage to your own dir, aybe you forgot to copy some of the files ?
check that you didn't forget
Serializer.as
MyLevelData.as
(of coure MyEditorManager.as and EditorManager.as also).
geckojsc 15 years ago
  Ok! (^_^)

So while I'm waiting, can someone help me with the code on the second frame? I know it's not quite right, but I don't know what is wrong with it...
I want the current level to load up and get made into a map.
I think the main problem is with this part:

function unserializeAndPlay(data:String) {
leveldata.unserialize(data);
map = levelToArray(data);
return true;
}

Check below to see the rest of the code.
Captain_404 15 years ago
  In this case, your problem is with the editor api, not the game api (or so it sounds)

Further, I think it may just be an incompatibility with the version of flash you're using, I had similar problems not too long ago.

If I were you, I'd sit tight and wait for jp to do his magic coding thing.
jp 15 years ago
  I think the problem of the level editor is not related to your game. When you click on UPLOAD, the level is not saved in database. That means the level editor doesn't send the data to the API. When you click on TEST, it's the same problem, the level editor doesn't send the data to the API (the API later forwarding the data to the game engine to test it).
geckojsc 15 years ago
  On the first frame of my game swf I have this code:
SPOILER


On the second frame, I have this code:
SPOILER

(I know the code in the second frame is wrong, but shouldn't BL still apply the basic functionality of the save, upload, and test buttons in the editor???)


Is there anything wrong with the code on the first frame, or something I need to add?
Captain_404 15 years ago
  Sort of.

As long as the API was declared inside the game properly (and was the right version, etc), it would still work.
geckojsc 15 years ago
  So this problem shouldn't happen even in a game with no BL API used in the game.swf and editor.swf at all...
Captain_404 15 years ago
  If the api has been implemented correctly (ie, if it works with your version of flash) the test button should take you to the game engine regardless. All the buttons should work, actually.
geckojsc 15 years ago
  Do I need to add anything else to the game swf? I ask this because I have not fully implemented the API to the game swf yet... That shouldn't make a difference, because I don't expect the level to work when I press test, but I would at least expect the game to appear on the screen, even if it just get a blank level with nothing but a snake that follows the mouse...
jp 15 years ago
  @gecko, you downloaded the FP8 package "Examples", you compiled the editor and submitted online and it deosn't work ?
I will check this problem this evening.
geckojsc 15 years ago
  I downloaded the newest versions of MyGameManager and MyEditorManager, and it worked fine, but I couldn't save or test levels... Then I downloaded the newest versions of GameManager and EditorManager, and the buttons disappeared again.


And no, I didn't save a backup... Maybe I could just press Ctrl + Z...

[edit]
Ok, I've fixed that problem, but the buttons still don't do much...
I'll carry on working on the game engine, but I don't know if it will work or not...
Captain_404 15 years ago
  Obviously it did make a difference :P

Did you at least keep a backup of the other version? If not, remember to do that next time, you always need something to fall back on.

Did you download the API file or the example file?
geckojsc 15 years ago
  I'm using F8 though, should that make a difference?
I'll download the MyGameManager and MyEditorManager codes again though, just to be sure...

Argh!! Now the buttons have disappeared again!

Do you think this is a problem with the editor, the player, or one of the My?Manager files?
Captain_404 15 years ago
  There was a problem with the api being incompatible with mx04 a while ago. I believe jp fixed it though, so if you download the latest version you should have a fully functional, up-to-date tutorial.
geckojsc 15 years ago
  Ok, now I've got a different problem...

I'm trying to do what THeNiNJa did for his editor (use the BL demo editor), but the options for thumbnails, testing, saving and uploading don't appear at the bottom, there is just a blank screen with a text box... What am I doing wrong?

[edit]
Actually, I just deleted a load of things with 'override' before them in MyEditorManager, and now it works perfectly...

[edit2]
Ok, but when I press test, save or upload, nothing happens...
jp 15 years ago
  Yes you just have to extend the blInit() method in MyGameManager.as. For example :

public function blInit() {
_root.init();
}

This will be called only once.

There is antoher method blWelcome() that is called each time you click on STOP when playing a game. you can implement or not this method. Like this for example.

public function blWelcome() {
_root.gotoWelcomeScreen();
}
Captain_404 15 years ago
  Sounds like a great update, jp. That's something I've been wanting ever since Push :)

Wouldn't you just have to add a line of code inside BLInit telling your intro to play? I haven't used the function all that much though, so I really don't know.

Although, if I were you, I'd just focus on getting the editor and game engine working properly before you do anything else.
geckojsc 15 years ago
  I'm happy with 500 x 440.
So how should I use blinit?
I want my introduction to play only when everything has finished loading.
jp 15 years ago
  Oh by the way, it's not related with the serialization, but I made an update recently that allows any size of game and any size of editor. The game and the editor can have different sizes as well. I found this constraint very anoying myself. A 500x440 editor is very small and games today get bigger and bigger because the sizes of screens has increased a lot.
jp 15 years ago
  gecko I also suggest that you start your serilization by a format version number. Something like 0_ for example.
If you realize later that you need to had something in your level that is not possible with your current serialization format, then you have to change your format. You increase the version number (1_) to inform the unserializer which format has been used. On the unserializer method, you have to read first the format version first and then unserialize with this format (in order to make it compatible with old and current format). Of course you don't need to increase the format version number while the game is in test, it's only when your game is published and has already leveld created with the old format that you need to use this.
I had to change my serializtion format many times for my games.

Note that in the download package of the API for Flash 8, there is a a Serializer.as class that is very easy to use.

Exple how to serialize and unserialize an array of number

var serializer:Serializer=new Serializer("");

// Serialize the level data
serializer.writeNumber(0); //serializtion version number
serializer.writeNumber(dataArray.length); //write first the length of the array
//write array elements
for (var i:Number=0;i<dataArray.length;i++) {
serializer.writeNumber(dataArray[i]);
}
var levelDataString:String=serializer.serialized; //Here is the string to send to the BL API

//Unserialize
serializer=new Serializer(levelDataString);
var versionNb:Number=serializer.readNumber();
dataArray=new Array();
var nbElements:Number=serializer.readNumber();
for (var i:Number=0;i<nbElements;i++) {
dataArray[i]=serializer.readNumber();
}
Captain_404 15 years ago
  Your letters will have to be stored and interpreted as string data. You'll have to build your game system around this as well, it will have to be flexible enough to recognize if a value is a string or a number and react accordingly.

You can do it, but personally I find it easier to use a system based entirely on numbers.
geckojsc 15 years ago
  Thanks, that will help a lot!
But instead of using two digits, can I use letters as well as numbers?
so:
[1,1,0,1,a,d,1,a,0,0]
Captain_404 15 years ago
  The structure I use for my level data in flash is based on an array, but for the api to read that I have to translate that into a string.

As for how to store your array data as a string, it depends on what kind of array you're using and what kind of data it holds.

Ultimately, you need to be think about how your going to take the string data the api gives you and turn it back into an array. You should build your string in a way that best fits that.

Let's say your level data is contained in a single dimension array made only of 1's and 0's. You wouldn't need a very complex structure for this at all. Your sting would only need to be something like "0010101110"

Later on, when you need to turn this string back into an array, all you'll need to do is

myMap = leveldata.split();

and myMap will be an array full of 1's and 0's. Although, these 1's and 0's will still be strings, so you'll have to loop through that array and change them into number values.


Now, lets say that your level data looks something like this:

[1,1,1,10,0,1,0]

When you turn that into a string, it would become

"11110010"

And then using the split function would turn it into an array with the values

[1,1,1,1,0,0,1,0]

As you can see, the number ten gets lost. We need a way to differentiate between the numbers. In this case, it is best to put commas between all your numbers when turning them into a string, so your sting will look like

"1,1,1,10,0,1,0"

Then when you need to turn this back into an array, you can use the function

myMap = leveldata.split(",");

and it will return an array identical to your original array. (although you will still need to loop through and turn all the strings into numbers)


This works great for single dimensional arrays, but what if our level data is stored in a multi-dimensional array? For example

myMap = [[2,2,3],[1,1,0]];

For this, I recommend adding comma's between all the array elements and |'s between the arrays themselves, so your string should end up looking like this

"2,2,3|1,1,0"

This way, when it comes time to turn this string back into an array, all you need to do is

myMap = leveldata.split("|");

then loop though the elements of myMap, splitting them at "," and then turn those values into numbers.


Good level data is only defined by how well and accurately you can turn it back into an array. You should always build your string structure with this in mind.
geckojsc 15 years ago
  Ok! Thanks!

Also, about blinit(). How should I make the game play the introduction only when the API had loaded?

So is this good level data?
SPOILER


I will ask for help with unserializing the data and all that stuff later...
THeNiNJa 15 years ago
  You will need something similar to:
[0,0,1,0,1,1,0,3,0,0]
Your engine needs to know where to split the data. If there's nothing between each number, it will think that it's one huge number ...
SPOILER

My data looks like this:
1,1,3,0,4,1|1,1,2,4,7,1|1,1,3,0,4,1 - (ALL CREDITS GO TO CAPTAIN_404!)

[<<] [1] [2] [3]

Flash game development

First post of the topic

geckojsc 15 years ago
  Please may I have some help with my game, Path 4 Mouse?

Okay, I would like to know how to create the level data, and load it, and make all the objects work, and a lot of other stuff too. I think I might have started too early, but I was dying to make a game for BL, and I can't really give up now!

So basically I would like to know how to make a tile based map, that opens up on the screen when you play the game, or something like that.

I might be able to manage it myself if the game was not for BL, but using the API and making arrays are two completely new things to me!
Our free flash games   Games for your site   Games for your iPhone   Contact   Twitter @jpsarda & @bonuslevelorg