[SOLVED] Using string to load a new world?


(azrafe7) #10

?

Why not?

You can write a little script to gather all the Level names and copypaste them in your Globals.

EDIT: If you’re on windows copypaste this into “getLevels.bat” and put it in the folder containing your levels:

@echo off
echo. 2> levels.txt
for %%i in (*.as) do (
  echo %%~ni;
  echo %%~ni; >> levels.txt
)
echo.
echo written in "levels.txt"

When you run it a file named “levels.txt” will be generated with the names of all the .as files in that folder.


(Bora Kasap) #11

because it is not great anymore…

i’m using a folder containing level classes and importing them to GLOBALS.as as package by the way it works when i use new level1();

so, if i already have a package containing level clases, then why am i have to make a list of levels names’ again… thats weird, so that doesn’t look like the best way to me, i feel there is a way to do that easier…

EDIT about “thats weird”… thats not weird, that’s the only way to compile a project, i got it now…


(azrafe7) #12

http://www.rozengain.com/blog/2009/08/21/getdefinitionbyname-referenceerror-and-the-frame-metadata-tag/


(Zachary Lewis) #13

I put together a video tutorial on this kind of thing. Here’s the end effect. You can start from the beginning to learn about how I did things.


(Bora Kasap) #14

hellnooo… :frowning: then your suggestion is the best solution about that, thanky you very much for help, i’m using windows…

also thanks for your great tutorial :] i haven’t used ogmo editor before, or xml by the way… but i’ll learn in the future…

i’ve made my own level editor inside my project, it looks like ogmo… but because of my game doesn’t have lots of tiles, no need for ogmo right now…

    if (this.repeater == 0)
{
	GLOBALS.corecount = 1;
	this.tankcount = 0;
	
	this.group =
	  "11111111110001"
	+ "10000000000001"
	+ "10000000000001"
	+ "10000000000001"
	+ "10001111111111"
	+ "10000000000001"
	+ "10000000000201"
	+ "10000000000001"
	+ "11111111111111";
	
	this.row = 1;
	this.groupwidth = 14;
	this.xspace = 25;
	this.yspace = -25;
	this.bornx = FP.halfWidth - ((this.groupwidth - 1) * this.xspace / 2);
	this.borny = this.yspace - 100;
	
	for (this.col = 1; this.col < this.group.length + 1; this.col++)
	{
		switch (this.group.charAt(this.col - 1))
		{
			case "1":
				Enemy(create(Enemy)).init("tank", this.bornx, this.borny, 50, [0], [0], [0]);
				this.tankcount++;
			break;
			
			case "2":
				Enemy(create(Enemy)).init("core", this.bornx, this.borny, 50, [0], [0], [0]);
			break;
		}
		
		if (this.col % this.groupwidth == 0)
		{
			this.borny += this.yspace;
			this.bornx = FP.halfWidth - ((this.groupwidth - 1) * this.xspace / 2);
		}
		else
		{
			this.bornx += this.xspace;
		}
	}
}

(Jacob Albano) #15

For what it’s worth, none of my games use tiles at all and I use Ogmo for everything. It has a lot of flexibility and works quite well when you’re working with entities.

I used to do it the way you do (laying out levels in code) and it’s really pretty terrible for iteration because of the amount of time you waste between making changes and seeing them in action. If you use code to design levels, you have to recompile the game every time you make a change (which can get super slow!), whereas with data files and dynamic loading you can set it up to reload changes to your levels without even closing the SWF, in addition to cutting compile times way down when you do have to make a change in code.


(Bora Kasap) #16

you’re absolutely right….

but game is so complicated even for me, firstly, the numbers in editor you see as 1 and 2, they are not tiles, i’m working on something different, think like live tiles

sometimes enemies(tiles) spawning in different positions then coming together, or they are spawning together as a group then they are splitting around with given orders or a mix of both etc

(i’ve set video playback start time 3:33, take a looK)

so i mean, i’m affraid of using ogmo editor because of i can’t see the future, what if things’ll be “more complicated” than “not using ogmo” in the future (for this game)


(Jacob Albano) #17

Well, just because you set something up as tiles in Ogmo doesn’t mean they have to use Tilemaps in the game. :wink: Ogmo can output tilemaps as strings just like you have above, and you can then take those strings and loop through them just like you’re doing now.


(Bora Kasap) #18

it looks like i’m lightening about ogmo right now…


(Bora Kasap) #19

And now, i’ve realized that i can use ogmo very well for my game with Flashpunk’s QuadPath, when i mix ogmo and quadpath, it looks like everything’ll work great…also maybe i won’t need to use any paths, thank you very much!!!

i’m curious about something… when i finish my project, how i’ll import this files into the compiled swf file?


(Bora Kasap) #20

oh, i think i don’t need to use ogmo for this game… but xml’ll be great to check without recompiling lots of times… :slight_smile:


(Jacob Albano) #21

You can embed XML just like other assets.

[Embed(source = "path/to/file.xml", mimeType = "application/octet-stream")] private const MyXML:Class;

var xml:XML = FP.getXML(MyXML);

(Bora Kasap) #22

yeah but :confused: when i embed something like that, how can i change variables after compilation? i think i got something(complete wrong) wrong… thats not funny :frowning:

EDIT: Ahh, is that about that “mimeType” thing? i see there is “stream” word there, is that means i didn’t get something wrong? :smiley:

EDIT AGAIN: reading xml only when compiling project :frowning:

FINAL EDIT: Why am i not using shared object to do something like that! :smiley:


(Jacob Albano) #23

“Octet stream” means the file is in binary format. It’s a little strange but Flash requires it.

Shared Objects won’t help you here. As far as I know you can’t edit them manually and you don’t want your game data to be in that format.

If you want to change them after compilation you can use FLAKit. :heart: I didn’t realize that was what your most recent question was about.


(Bora Kasap) #24

yeap, you’re right again, shared object doesn’t help me, also i’ll use this stuff for importing xml files dynamically, so, i’ve just realized i can use URLLoader for this… i think this time it’ll work as i want… when i complete my levels, i’ll change URLloaders’ to “FP.getXML”…

i’ve asked a little question at the beginning of this topic, but i’ve learnt lots of stuff because of talkflow… Even FLAKit not required to me, i’ll just control entities’ movement functions with this…


(Jacob Albano) #25

Yep, URLLoader is what you want. FLAKit is really just a way for me to avoid using event listeners when I load my data, since it loads everything ahead of time. It uses URLLoaders under the hood.


(Jacob Albano) #26

I feel like this thread already has enough in it, but I wanted to suggest an alternative to your switch statement.

var worlds:Dictionary = new Dictionary();
worlds["SECTOR_41"] = SECTOR_41;
// etc.

FP.world = new worlds[levelname]();

(Bora Kasap) #27

thanks again… class compiling problem solved completely :smiley: :smiley: :smiley: i’ve removed my all level classes from project file and i’m working on a template level class to load any xml level, so, i’m gonna publish my game with a level editor inside…


(Bora Kasap) #28

i’ve just used this dictionary stuff for something other, thats great!


(Ultima2876) #29