Map stored as a table..

smurftedsmurfted Member, PRO Posts: 570

So I'm making a game that builds the world from a map.

I'm thinking of generating the map in a table so what's shown onscreen is read from the table & rendered on screen.

Has anyone tried this yet?

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2017

    Sure, but it depends what you mean by "map." For instance, I've build a first-person maze where the walls are images selected by data from a table "map" if you will.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • smurftedsmurfted Member, PRO Posts: 570

    Excellent. How did it work out?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2017

    I thought it worked pretty well. I made it three years ago when I was still pretty new to GameSalad. Note that the graphics got messed up a bit but you get the idea hopefully:

    The table for the walls looks like this:

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • smurftedsmurfted Member, PRO Posts: 570

    Nice one, it reminds me of those amiga exploration games like Hired Guns..

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    When I was 12, I was in a summer programming class at UC Berkeley and my partner was this wiz kid who figured out how to randomly generate and display a 3D maze like the one in my GameSalad game using Pascal. I was totally blown away back then. And really, his accomplishment is still much more impressive than anything I've done with GameSalad. :p

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • smurftedsmurfted Member, PRO Posts: 570

    I'm trying something pretty out there with this experiment.

    I am trying to read from a table and then render the outcome, re-assigning actors each game cycle. I'm not sure if GS can handle it, but i like pushing the boat out a bit..

    First of i need to write a loop that collects all the data from the map (table)..

  • smurftedsmurfted Member, PRO Posts: 570

    So i need to look in a table in a grid pattern say playerX-5 to playerX+5 & repeat that over a vertical area of the grid, from playerY-5 to playerY+5.

    Recording anything that registers more than 0.

    So what would be the most efficient way of doing this do you think?

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @smurfted

    two main things will affect how you should approach it.

    1. does the complete check have to be performed every draw cycle, or can the check be staggered over a few draw cycles.
    2. is it more likely that something will be found, or more likely that nothing will be found?

    Depending on the above, the right combination of "Loop (with Max loops/frame set)", "tableSearch", and "tableColSum" will give you very good, low overhead, performance.

  • smurftedsmurfted Member, PRO Posts: 570

    if the character is moving we need to be reading the map, and it will be much more likely to find nothing than something...

    "tablecolsum" would be to right off checking that column at all i guess, clever..

  • smurftedsmurfted Member, PRO Posts: 570

    Okay so i have made a loop that looks across columns close to playerY and its picking up the data from the map.

    I know i cant loop loops (unfortunately). But i copied the group with the loop in it and changed which row it looks at manually.

    For some reason it only records the info from the first loop?! Any ideas what this could be?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    You can't easily loop loops but you can use multiple "checker" actors, one for each row of values. That's essentially what I did with my maze spawner/checker.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • smurftedsmurfted Member, PRO Posts: 570

    whats that?

  • smurftedsmurfted Member, PRO Posts: 570

    well bugger, i thought i had it for a minute, then it failed me again. looking like it gets stuck in the loop..

  • smurftedsmurfted Member, PRO Posts: 570

  • smurftedsmurfted Member, PRO Posts: 570

    It works just fine till i turn on the "if it finds something in the cell" bit, then it freezes.

    in there there is just a table cell check if there is anything there on the map...

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2017

    @smurfted said:
    in there there is just a table cell check if there is anything there on the map...

    That's the most important part to share. ;)

    If it's freezing, it's likely trying to check the value of a table row or column that exceeds the size of your table. Or it's trying to check row zero.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • HopscotchHopscotch Member, PRO Posts: 2,782
    edited April 2017

    @smurfted

    Looking at your loop (until all) conditions, and the way your scanX and scanY increments -
    your loop will never fulfill the exit condition since scanX gets reset if it is > 4 before scanY gets incremented.
    Therefore scanY will endlessly increase and crash the program when it is out of bounds.

    Take the scanX>4 condition out of the loop rule, since you handle that in the code further down.

  • smurftedsmurfted Member, PRO Posts: 570
    edited April 2017

    I started in the middle of the map so no 0 cell searches can happen. Been there before and that was a crash :#

    @Hopscotch my loop was indeed flawed, i have now pre-calculated the min and max positions as integers. That way i could be precise with the conditions of the loop. It's working a little better now.

    I added a limit of 222 to check if the loop was working. It should finish on 81, and now it does..

    Now to turn on the table searching again...

  • smurftedsmurfted Member, PRO Posts: 570

    so i have refined it and gotten it working, though it does seem to get a bit laggy... :/

Sign In or Register to comment.