dcsimg
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: PokemonFlash Game: Storing All this data?!

  1. #1
    Member
    Join Date
    Jun 2007
    Posts
    30

    PokemonFlash Game: Storing All this data?!

    Ok, so lately i've been working on a pokemon flash game. Haha :P

    I just wanted to know if anyone had any good ideas for storing all the data that i'm going to need.


    Need to store all the pokemon you catch: health, attack, def, and experience

    Need to store basic stats of all the pokemon that will be in my game

    Need to store the levels of all the pokemon you put in your storage box.

    Among other stuff..

  2. #2
    jtnw's Avatar
    Join Date
    May 2002
    Posts
    1,328
    Hi, there are three options:
    -Local Storage (cookies)
    -encode data into save string
    -server side storage

    Hope this helps a little; I dont have that much time for a complete explination, remember google is your friend

    jtnw

  3. #3
    Senior Member
    Join Date
    Mar 2001
    Location
    Location : Location
    Posts
    131
    I'd probably go for XML ... neat and compact ...
    this[MCr.i + 'm_not_ok']._lyric = "you sing the words but you don't know what they mean";

  4. #4
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    Anything constant should be XML/Flat files, anything that changes should be shared object or server side.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  5. #5
    Member
    Join Date
    Jun 2007
    Posts
    30
    oh thanks everyone.
    Anyone happen to know where i can find a GOOD tutorial on importing .xml data?
    Cause all the ones i find never work :/

  6. #6
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    give a list of sample values you want to store and I can write you a simplified XML and Actionscript for reading.

  7. #7
    Member
    Join Date
    Jun 2007
    Posts
    30
    well if you could just it anyway that would include the str, def, hp, total hp, and level of all my pokemon

    As such. I want to basically have a list of of my pokemon with a value for their name with attached str, def, level, hp, and total hp of each one

    kinda understand?
    like i can pool the data from pigeyroute1 would be Pigey, 1, 3, 4, 10, 10
    where name, level, str, def, hp, total hp

    something like that?
    just wing it haha

  8. #8
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    ok here is your example code (works,- tested it)
    create a new textfile and rename it to "pokemon.xml" (make sure that your Computer displays file extensions), open it with notepad and enter the following text:
    PHP Code:
    <pokemon active="1">
        <
    p name="Keshi"    str="55" def="15" hp="5/4" lvl="1"/>
        <
    p name="Putera"    str="1" def="3" hp="5/10" lvl="2"/>
        <
    p name="Altaria"    str="5" def="3" hp="2/10" lvl="1"/>
        <
    p name="Denryu"    str="1" def="3" hp="5/10" lvl="99"/>
        <
    p name="Agehanto"    str="5" def="32" hp="5/10" lvl="1"/>
        <
    p name="Fushigidane"    str="5" def="3" hp="1/2" lvl="1"/>
        <
    p name="Kyatapi"    str="21" def="13" hp="1/10" lvl="3"/>
        <
    p name="Hinoarashi"    str="52" def="3" hp="5/2" lvl="1"/>
    </
    pokemon
    save it

    create a new Flash file (as1 or as2) and save the fla in the same folder as the XML file.
    in the first Frame of the flash movie paste this code:
    PHP Code:
    function loadXML(file){
        
    _root.xml = new XML();
        
    xml.ignoreWhite true;
        
    xml.onLoad = function(ok){
            if (
    ok){
                
    parseData();
            }
        }
        
    xml.load(file);
    }

    function 
    parseData(){
        var 
    node xml.firstChild.childNodes;
        
    // your data from the xml file now in variables
        
    var active Number(xml.firstChild.attributes.active);
        var 
    pokemons node.length;
        
        
    trace("active pokemon: "+active);
        
    trace("total pokemons: "+pokemons);
        
        
        
    _root.array = new Array();//the pokemons together in a array
        
    for (var i=0;i<node.length;i++){
            var 
    = array[i] = new Object();//object container to put all the variables into
            
            
    array[i].name node[i].attributes.name;
            array[
    i].str Numbernode[i].attributes.str );
            array[
    i].def Numbernode[i].attributes.def );
            
            var 
    hp node[i].attributes.hp;
            array[
    i].hp1 Numberhp.slice(0,hp.indexOf("/")) );
            array[
    i].hp2 Numberhp.slice(hp.indexOf("/")+1,hp.length) );
            array[
    i].lvl Numbernode[i].attributes.lvl );
            
            
    //output
            
    trace("name : "+a.name+" ,str: "+a.str+", def: "+a.def+", hp1: "+a.hp1+", hp2: "+a.hp2+", lvl: "+a.lvl);
        }
    }
    loadXML("pokemon.xml"
    hope you can follow the code somewhat- besides the xml stuff I used arrays- a shortcut (shortcut is a in: [I]var a = array = new Object();) and functions.

    if you need to recieve a certain pokemon later (make sure that the xml file is loaded before) you could use a function like this to easier fetch it:

    PHP Code:
    function getPokemon(nr){
        return 
    _root.array[nr-1];
    }
    trace("the 3rd pokemon is called: "+getPokemon(3).name); 
    of course the variables depend on the ones that were store before in the _root.array array.

    good luck with it

  9. #9
    Member
    Join Date
    Jun 2007
    Posts
    30
    wow. You are AMAZING for typing that all out for me.
    Thanks so much.
    Quick questions.

    Do i have to start a new .fla then load that into my current game?
    Or can i just throw that stuff in with my preloader frames?

    And once i Trace a number from the source do i set it to a var to use it?
    If so how?
    Like
    trace("the 3rd pokemon is called: "+getPokemon(3).name);
    enemyname = //what?

    sorry i never use trace.

  10. #10
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    ok my tip:
    if you already have a preloader,- load the xml file right after the preloader is done (e.g in a frame right after the preloader but still before the game- like this:
    (e.g 2nd frame):

    PHP Code:
     stop();//stop the movie here until the XML is loaded and parsed

    function loadXML(file){ 
        
    _root.xml = new XML(); 
        
    xml.ignoreWhite true
        
    xml.onLoad = function(ok){ 
            if (
    ok){ 
                
    parseData(); 
            } 
        } 
        
    xml.load(file); 

    function 
    parseData(){ 
        var 
    node xml.firstChild.childNodes
        
    // your data from the xml file now in variables 
        
    var active Number(xml.firstChild.attributes.active); 
        var 
    pokemons node.length

        
    _root.array = new Array();//the pokemons together in a array 
        
    for (var i=0;i<node.length;i++){ 
            var 
    = array[i] = new Object();//object container to put all the variables into 
             
            
    array[i].name node[i].attributes.name
            array[
    i].str Numbernode[i].attributes.str ); 
            array[
    i].def Numbernode[i].attributes.def ); 
            var 
    hp node[i].attributes.hp
            array[
    i].hp1 Numberhp.slice(0,hp.indexOf("/")) ); 
            array[
    i].hp2 Numberhp.slice(hp.indexOf("/")+1,hp.length) ); 
            array[
    i].lvl Numbernode[i].attributes.lvl ); 
        }
        
        
    gotoAndPlay(3);//goto the main content

    loadXML("pokemon.xml"
    in the frame after that (e.g 3) put this function somewhere in the main timeline (can be seperate layer but must be typed into the e.g 3rd frame):
    PHP Code:
    function getPokemon(nr){ 
        return 
    _root.array[nr-1]; 

    if you did all this, your movie should jump to the 3rd or more frame (depending what you used the example used 3) where your game starts.
    Within that frame you can then use things like this (button script):
    PHP Code:
    on(press){
        
    trace("the 7th pokemon is called: "+getPokemon(7).name);

    or this
    PHP Code:
    on(press){
        
    trace("current pokemon is called: "+getPokemon(Number(xml.firstChild.attributes.active)).name);

    (erh looks complicated but can be simplified as well, just store the variables somewhere once and then you can access them anytime)


    personally I usually have 3 frames in each Flash Movie
    1st: preloader for the whole Movie
    2nd: preloader for the xml file
    3rd: the actual content
    wich is why I suggested frame 3,- but try to apply it to your situation

  11. #11
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    I assume that things like Health and active pokemon will change over the course of the game and therefore need to be stored in a shared object, not permanent files.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  12. #12
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    I assume that things like Health and active pokemon will change over the course of the game and therefore need to be stored in a shared object, not permanent files.
    I second that
    @Hiei676: you can use the xml files for loading data once into the game but if you need to save it later on somewhere it can be complicated.
    So in my oppinion it would make sence for using the XML as general Pokemon list (the ones that are available in total)- and inside the shared object wich you can save just some id´s to wich ones the clients player has.

    The advantage XML has and the reason so many flash developers use it because it easy to read with a texteditor and therefore easy to edit. You dont need to run FLash for it and you dont need to re- export your movie (compiling). Instead just opening the file, make changes and save it- then upload and you are done with the changes.

    Shared objects come in usefull when you need to store smal data (arrays, variables and strings are usually very smal). Inside a shared object you can save most Flash Object types inlcuding XML (but wich I wouldn´t advise here).
    If you take my example I gave you I would store for example just the _root.Array into the shared object and perhaps some other variables like the amount of pokemons and the current one.

    some references for shared objects:
    http://www.kirupa.com/developer/mx/sharedobjects.htm (kirupa is always nice)
    http://www.permadi.com/tutorial/flas...ect/index.html
    http://www.adobe.com/support/flash/a...shared_object/
    http://articles.techrepublic.com.com...2-5061241.html

  13. #13
    Member
    Join Date
    Jun 2007
    Posts
    30
    well renderhjs, thank you so much for all your help.
    See my goal was to use this .xml to store all the random pokemon that will appear for battle. These stats will be unchanged no matter how the game is played. In this sense, xml is perfect.
    But I already thought about it and i know i'm going to have to use something entirely different for saving the PLAYER's pokemon and i didn't really give much thought into developing that.

    I'm a little noobie when it comes to data mangement. I never used flash and massive data management in the same sentence. :P

    I guess i'll try the tutorials and figure it out once i have my timer working properly for my battles.

  14. #14
    Senior Member
    Join Date
    Apr 2006
    Posts
    1,059
    xml is about the worst option for this imho. I would just set up a mysql database and set up a few linked tables...

    I dont think SO(shared object) is a very secure option if your at all worried about hacks.

  15. #15
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    xml is about the worst option for this imho. I would just set up a mysql database and set up a few linked tables...
    Off course, storing the data in tables doesn't exclude XML at all, the data could still be output to XML format.

    Something else to consider : editing an XML file is quicker than editing data in tables, even if you create an admin tool. At least for someone who is fluent in editing textfiles, like a coder should be. It's also less stress for the server, but this probably shouldn't matter (much).

  16. #16
    Senior Member
    Join Date
    Apr 2006
    Posts
    1,059
    Something else to consider : editing an XML file is quicker than editing data in tables, even if you create an admin tool. At least for someone who is fluent in editing textfiles, like a coder should be. It's also less stress for the server, but this probably shouldn't matter (much).
    hmmm i figured it would be more server intensive to rewrite the xml files over and over again....but apparently im wrong...so xml file rewriting would be the least intensive?
    good to know... i feel like a jackass now :P

  17. #17
    crossconscious
    Join Date
    Sep 2005
    Location
    Belgium
    Posts
    1,188
    Not what I meant... Outputting to urlencode or xml format should be equally intensive, if you're sending to the browser. If you save them as files from your script (ie caching) it wouldn't matter either.

    But if you manually edit the xml-files versus creating the output dynamically from a database, there is a difference. But not a difference you should generally worry about, unless you have massive amounts of requests.

  18. #18
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    I think both joran and fallx have misunderstood the problem. We would be absolute morons to suggest XML if this was a serverside database, however this is just the client side list of Pokemon, much like you would store XML maps for a game of moderate size along with the .swf.

    These files are not going to be written to, or manipulated in any way, only read and kept client side.

    Suggesting MySQL for this case is as nonsensical as telling someone to store their music collection inside oracle.
    Last edited by 691175002; 03-03-2008 at 10:20 PM.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  19. #19
    Member
    Join Date
    Jun 2007
    Posts
    30
    Quote Originally Posted by 691175002
    Suggesting MySQL for this case is as nonsensical as telling someone to store their music collection inside oracle.
    For what I am using the xml for, that is correct.

    The xml is going to be used for a list of permanent vars (constants) that shall be called into my game.

    Now on the other hand I am going to need another idea for saving all my player's data (his pokemon and their stats) to something.

  20. #20
    Member
    Join Date
    Jun 2007
    Posts
    30
    quick question on the xml.

    if i have something like this.
    Code:
    battlehpstring = battlehpstring - (getPokemon(2).str + random(3))
    That gives me battlehpstring as undefined. What is my error? Am i not fetching the number properly?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center