PDA

View Full Version : loading text from a file


Disjuku
02-01-2004, 10:58 PM
I am wondering if anyone would know how I can get info from a text file etc, ie. I want flash to read a bunch of characters, each representing a "tile" in flash and build a map out of it

example of the text file

xooooooOOOoooooooooox
oxxxxxxxxxxxxxpxxxxxo
oxxxpxxxxxpxxxxxxxxxO
OxxxxxxxxxxxxxxxxxxxO
OxxxxxxxxpxxxxxpxxxxO
Oxxxpxxxxxxxxxxxxxxxo
xooooooooooooOOOoooox

where the x may be grass, the o a rock, and the O a tile which makes the user go to a different level thing, and the p a tree etc

Then flash reads this and fills a grid according to what characters were in the text file

splict
02-01-2004, 11:10 PM
The best way to do this is with an array. If you wanna pull stuff out of a text file you can.

The common way is of course LoadVariabless. you could have the string like
&grid=oooooooooooooooxxxxxxxxxxxxoxoxoxoooxxooOOO
or
&row1=oooooooooooooxxxxoxooxx&row2=oooxoxooxooxxxx
etc. Then just read the letters and manipulate them with the various String and or Array functions.

If none of this was what you were asking, but instead want to know what to do once its inside flash then, sorry, ignore that and ask again :o

-splict

CyanBlue
02-01-2004, 11:16 PM
I see that splict is beating me all day long... I think it's time for me to retire... :D

Don't get confused though, splict... This is F5 forum... :p
You know what that means, Disjuku??? Go get FMX at least... You are missing too many things and you are wanting too many things... :p


Yeah... What splict says... But you'd need to use loadVariables() function instead... There are tons of threads that tells you how to load text file into F5 since you are not the first one who's asking that... :p

So, let me skip that part, but here is the tone downed version with the array...str = "xooooooOOOoooooooooox|oxxxxxxxxxxxxxpxxxxxo";
map_arr = str.split("|");
map_arr[0] = map_arr[0].split("");
map_arr[1] = map_arr[1].split("");
trace(map_arr[0]);
trace(map_arr[1]);

splict
02-01-2004, 11:28 PM
i don't know why I always do that when Disjuku posts. but actually i immediately went back and adjusted it for flash 5 (loadVariables and no onData) i thought i had done it quick enough that no one would notice. :o

And yeah, there are still a couple versions of code you could use, CyanBlue's probably being the best and most common - I just wanted to make sure I got the question right before I got into code.

Anyways, my posts today have been a bit off - SuperBowl drinking and all, (though I had my face in my new book the whole time :) )

CyanBlue
02-01-2004, 11:47 PM
Hehe... The basic rule of thumb is to edit the post before you actually see that annoying 'Last edited by ...' line... If you edit the post and you see that line, you've done it too late... :p

Well... Yeah... AS.org has been online long enough... I guess at least 75% of the so-called 'unique' problems are already discussed in the past... It's just the people who do not/can not search the forum to find the right answer AND the crude search capability built in this vBulletin... :(

Hey, nothing wrong with the posts going off... It is sort of a trend thesedays... 7/10 threads go OT with no apparent reason like this thread... :D

Well... Good night, everybody and splict... I've got to call it a day... :)

Disjuku
02-02-2004, 03:26 AM
lol, its been crazy in here :|, I generally cant find what I am after with the search, it either brings up heaps of MX stuff or I am unable to find anything good which I can manipulate for my own useage, or the last person to ask worded it differently from how I did :/ - and yeah, I need flash MX lol, I have been working for a bit, just about to buy my own laptop, then I will have no money again, and I will be at uni, so I dont see any money to buy it with coming my way in the near future :(, anyway, I will go off and try to work out what you have said above :)

Man I ask a lot of questions here, at least I am learning as I go, and I do try to contrubute more than I use :P - pitty the three games I have been working on have kinda come to a stand still, the first one ended up with too many things I cant do, second one I am still building up the courage to hit the AI of the computer player, and this third one (a bit like zelda etc, more like graal if you have ever played that) is going to be so horrible I doubt I will ever make it past the character movement, but the main thing is that I am learning how to do things, I managed to complete most of the second game on my own, where as the first one was nearly all done through help on here, anyway, thanks! lol

CyanBlue
02-02-2004, 09:01 AM
Well... The only suggestion for you, Disjuku, is that you really have to spend time to find the information that you are seeking from the forum... I've been watching your questions and lots of them looked like you didn't really need to post the thread since they were answered before... One more thing about the search is that you learn by browsing other people's posts as well... :)

I know how tough it is to get the new program if you do not make enough money... But you should be able to get the educational version when you go to school... So, get it that way no matter how much it costs... You should not really stay with F5 for your own good... :)

As for your projects, it doesn't really matter whether you've done it with other people's help or not... You learn something while you do the project... That's all that matter... :)

Well... Thank you for your contirbution at the forum and good luck on your journey... :)

Disjuku
02-02-2004, 04:47 PM
lol yeah, I should get a job when I come down for holidays, might just be able to stick some of that money aside ;P