Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In Register

Loading multiple positions within a pair of Save nodes

edited May 2018 in General
Okay, this kinda is an thought for loading the positions for many things through just two save behaviors- say we have a random world generator. It will have to be finite in size no matter what.

Up to 81 positions (a 9 by 9 square) could be saved with a pair of Saves, one for each axis. And if you want it to support multiple blocks- up to 9 types.

Say our first block was in the position 1,1

Save X: 1
Save Y: 1

Every block after 1,1, would have its position, then multiplied by 10^x, then added onto the save.. depending on how far it is from the origin point, 1,1

So say we had the block at 1,1. But also wanted a block at 2,1 as well.

Save X: 21
Save Y: 11

Another at 3,2

Save X: 321
Save Y: 211

And when the saves are loaded, the individual digits are unpacked and are spawned where they were the previous session.

And this alone is just for a 9 by 9 tile chunk. To expand your game, you’d have to make multiple save pairs as well. Using expressions to add offsets to the spawning objects to allow everything to be placed without overlapping.

@Mhx Aîr Eureka

Can I get a tester to confirm this? This very idea could lead us to much more complex games.


  • edited May 2018
    My main thought, will integer overflow stop a save from saving 999999999?

    Because if so that could limit this, although I imagine all of the tiles saved in a single position would be pretty impractical.

    Hey @Wizardry with your 3D raycast example, we might be able to pull off a wolfenstein clone, where you build a fort, and defend something from enemies. You can SAVE the forts configuration!
  • Unfortunately, this would be very limited, as 9*9 is 81, so that means in order for every tile to be loaded, you’d have to have 81 different tiles loaded, can the engine handle this @grazer?
  • edited May 2018
    So I came up with a formula that works with a couple of expressions nodes


    Where A is the position of the tile on the axis.

    B is the amount of tiles before it.

    The number you get out of this is added to the number string before it (C), the sum of this is your new number string

    @Mhx Aîr, remember that calculator you made? Think of that.

    Here’s what I haven’t figured out yet- unpacking said string. You’d have to reverse the order of packing, but that’s trickier than it sounds... for me atleast
  • I'm not a math guy, so it doesn't quite make sense to me. I would be using individual saves for each block type. It sounds cool to grid the stuff around, but how would you decide if it is grass water or tree? My version writes grass, draws tiles that on collision turn grass into hillsides, and then draws water that turns grass into riverbanks and hillsides into waterfalls.

    Actually, I saw someone else do a map generator, was it PixelPizza or wizardry? It's cool to see everyone coming up with their own versions.
  • edited May 2018
    @Mhx Aîr

    If you wanted to do types, it would only work with up to 9.

    Instead of just a pair of Saves, it would be a trio- with each type being assigned a #.

    Literally the same thing goes for it.

    Also, this could be used in conjunction with a world generator, it is simply saving a bunch of objects positions with a pair/trio of number strings.

    If you were to combine this with the way you have your world generator, it would be INSANE, because now you have a detailed world, that not only remembers the way it was
    generated, but also rewrites itself according to how it was when it saved
  • edited May 2018
    The best thing I ever designed was an Animal Crossing random town generator, fully functioning, even the fruit trees are random and the clock and music would change with night, day, and rain.

    81 random map blocks sounds insane to me

    I could easily pull it off in flowlab, but last thing I need is to spend weeks on something for no reason, then get sued by Nintendo lol
  • If you pull it off, I'd love to see the logic behind it
  • edited May 2018
    @Mhx Aîr I have an engineering class, and I’m going to bring it up with my teacher, and see if we can come up with an equation to unpack a string

    Being that I’m 15, I may not be able to do this, as I still have much more to learn..

    Maybe, we should get an older string saved as well, so we can undo it
  • edited May 2018
    Grazer said the max int was 2,147,483,647 not 999,999,999 but 9 complete decimal places is easier I guess.

    Also I don't see how 9 decimal places equates to 81 locations if you use 1 decimal place per location going by your description, so at best it only works for a 3x3 grid or 9 positions.

    I thought of a way to pack 27 bits into a single Number component though, using 9 decimal places as the max. Imagine a 27x1 grid:

    A B C - D E F - G H I - J K L - M N O - P Q R - S T U - V W X - Y Z !

    for location A or 1,1 we can record a location by using value 1 if there is something there, or 0 if nothing
    for location B or 2,1 we can record a location using value 2 or 0
    for C we can record a location using 4 or 0

    These three bits are added together or multiplexed into a single decimal place that records all three position's data. For example this is all the possible outcomes:

    0 means A B and C contain nothing.
    1 means A contains something, and B and C contain nothing. A=1
    2 means B contains something, and A and C contain nothing. B=2
    3 means A and B contain something, C nothing. A=1 + B=2
    4 means C contains something, and A/B nothing. C=4
    5 means A and C contain something, B nothing. A=1 + C =4
    6 means B and C contain something. B=2 + C=4
    7 means A B and C contain something. A=1 + B=2 + C=4

    So this first decimal place can be between 0-7 and represent 3 positions. For the second decimal place you use the same values but multipled by increasing values of ten.

    the next group D E F uses 10,20,40. the third uses 100,200,400. the fourth 1000,2000,4000, and so on with the final 9th group uses 100,000,000 200,000,000 and 400,000,000.

    The way I imagined this being done was having recording blocks spaced out every 27 blocks, or alternatively and probably easier just a single recording block that moves throughout the map grid writing the data into Number components. Every 27 blocks it just restarts and writed onto the next Number component. After everything is done being written down these numbers can be saved and when it's tome to start the map and load, it reads these numbers in reverse to spawn out blocks in the location as it moves around the map grid. Each block type would potentially have to have its own write/read system though, but it should be as easy as making anew object, copy/pasting the code, changing the specific block type to the new block.
  • edited May 2018
    so 81 digits would definitely Overflow, so 3 by 3 would be far better? That works.

    All this math hurts my head.

    The reason 81 is present is because 9*9 is 81, so that means there are 81 posible positions, but because 81 digits goes far over the point where it overflows, 3 by 3 is 9, and 9 digits would not hit overflow, while 4 by 4 can’t work because 16 digits would go over too, so it looks like we found our maximum

    So let’s see here, 333,333,333 would not hit the overflow point by any means, and that would be the max value for a chunck, but that’s impractical again because all of the objects would be in one point, but by theory it’s possible.

    So in theory if overflow wasn’t a problem here, 9 by 9 could work, but 3 by 3 would be more suited because overflow exists.

    Still gotta figure out that unpack equation, which means we have to be able to remove all of the digits one by one... this equation is going to be much much much larger than I had originally thought.
  • edited May 2018
    I reread your version, but unpacking it seems to be just as hard as this, although you wouldn’t have to use it as much, because you’re going by a single dimension at a time, where I’m going by both.

    I need to rest, I’m fried...
  • This is beyond me. I gave up math after algebra and geometry. I joined flowlab because I'm a multimedia artist. I was a terrible LUA and C++ coder. I understand code logic and gates, because of it, but once you get to math, I can't help at all lmao. It's all on you guys and grazer.
  • This is keeping me up. @grazer any ideas?
  • I thought of a method to unpacking.

    Ya pretty risky, as You might end up with an endless loop.
  • @grazer how do you do exponents. ^ doesnt want to work
  • Use Math.pow(x,y) for x to the power of y
  • Error, unexpected eof
  • edited May 2018
    It's case-sensitive and kind of annoying to type out but I mean it works

  • I got it. Thanks

    Here’s what I’m working on, clicking the gear will generate 4-5 blocks, and you’ll be able to see the strings for them. It’s supposed to generate only 5, but whatevs

    Pressing space will cause the game to “unpack” although it won’t work, and will probably freeze your screen.
  • I just thought of a way to do it- and best part.... it will work.
  • edited May 2018
    Hey, I just saw this - sorry I'm late to the party. You mentioned that you've solved it, so I'm curious to see what you've come up with. Anyway, here's my two cents.

    1) The good news is that you aren't quite as range restricted as you might think. Your idea is very clever, but you could take advantage of the fact that numbers are binary to get more efficient storage. If you wanted to store all the x positions that are occupied in one number, you could set just the individual bits. This would let you store up to a 32x32 grid (2^31 = 2,147,483,648). I can explain this in more detail if you think it would be useful. but...

    2) The bad news is that this isn't enough information. You need to know not just all the x positions and y positions that are filled in, but the actual x,y pairs. Otherwise, you won;t be able to tell which x positions go with which y positions :(

  • If x: 2847292
    And y: 3849382

    Then 2,3 8,8 etc. there’s the order
  • edited May 2018
    Ok, I finished the unpacker @Mhx Aîr
    I plan to make changes- because it outputs each individual digit at a delay, I want it to be settable

    Everything should work, but for some reason... after the first time, the packer loses one of its numbers.
  • edited May 2018
    Something is pretty inconsistent..

    The packer should work fine. But it refuses to work for some reason

    The unpacker DEFINITELY works! But it seems the packer doesn’t want to work
  • An accurate depiction of me: image
  • edited May 2018
    Okay, turns out there was an ordering mistake I made, but it’s fixed, as a result, the tester is a lot more consistent, but still has an issue with spawning. Sometimes a new coordinate doesn’t update, apparently. That’s how I’m reading it.

    Click to go to the Compressed Numbers Tester

    @Mhx Aîr
    A great thing is now sometimes it works flawlessly. Sweet!
  • This is really impressive, @CrimsonBlackGames - I haven't had time to dig into it very deeply, but my initial guess is that the unpacking issue might be an ordering or timing problem
  • edited May 2018
    Evidence points towards it being a timing problem. For some reason, when unpacking, Y always triggers after X, but I haven’t found a way to fix this

Sign In or Register to comment.

| make games in your browser
@ 2017, All rights reserved.

Contact us

Get In Touch