Need help with random tiles

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • Gahsp. Only a fool discerns a post by its title.

    There are a gajillion and 1 ways to achieve your goal. Here's one.

    It store's the "tiles" in a single active and generates the map and startup, by randomly selecting an animation frame, pasting it into the backgroud, and repositioning the active at the right edge of itself ready to paste the next. You'll notice it can pick the same frame twice in a row which looks ugly, you'll need to add a check to prevent this. If this method digusts you, tell me it does and I'll come back at you with something else.

  • Sorry for the late response guys

    First of all thank you Bertard and Thank you ChrisBurrows for taking the time to help me. I appreciate it!

    To Bertard: looks cool, but not exactly what I was looking for, but thank you =]

    To ChrisBurrows: cool Ill take a look at it, that sounds interesting, I'm definitely gonna try it out and let you know =]

    Edited 2 times, last by Circus_Potato (August 25, 2015 at 4:02 PM).

  • Gahsp. Only a fool discerns a post by its title.

    There are a gajillion and 1 ways to achieve your goal. Here's one.

    It store's the "tiles" in a single active and generates the map and startup, by randomly selecting an animation frame, pasting it into the backgroud, and repositioning the active at the right edge of itself ready to paste the next. You'll notice it can pick the same frame twice in a row which looks ugly, you'll need to add a check to prevent this. If this method digusts you, tell me it does and I'll come back at you with something else.

    I checked it out just now and it's what I was looking for. Thank you so much!!!

    One question though. Would I have to create a series of premade platform for this to work?

    What if I was using single tiles?

    I'd be very insterested to see other methods that you may have if you don't mind =]

    Edited 3 times, last by Circus_Potato (August 25, 2015 at 7:07 PM).

  • This is a little more complicated, I'll run you through it.

    Please login to see this picture. Please login to see this picture.

    "Areas" are stored in external text files. For each "Tile" within an area, 3 lines of text are required, one for it's name, and two for it's x,y position relative to the beginning of the area. At the end of the file, the command "#WIDTH" indicates the next line will define the width of the entire area, deciding at what x position to create the following area.

    All the possible area names are stored internally in a list object called "Area Pool". The loop "MapGen" randomly selects one of the two first areas in the pool, creates it, and then moves that area name to the end of the pool. This prevents the same area being created twice in a row, while still producing areas at random.

  • Thanks so much for the description

    I took a look at it and what I'm getting from this so far is that each text file represents an "area" or a building, it's name, each piece of the building in that area, and it's coordinates.

    and the #WIDTH is the width of the entire "area".

    However I notice that the width in #WIDTH is larger than the actual width of an area. Is the extra width what creates the gaps in between each area?

    Also

    I was looking at the code and I noticed something called "blit". What is "blit"?
    -----------------

    just a couple more questions.

    In
    line 6
    can you explain to me a bit about what is going on with that line? I just want to make sure I'm understanding all this.


    finally,
    I tried switching "start of frame" in Line 5 for the mapgen to "always" but it runs very slow and lags. How do you make it infinitely loop?

  • Sure. First up, if you're unaware, Fusion reads events from top to bottom, and executes actions within each event, from top to bottom.
    Double click any action to view it a list of actions for that event. I changed the icon of the Area Pool list object to red for readability.

    Please login to see this picture.

    Please login to see this picture. : Set RandomNumber to Random(2)
    Random(x) is function which generates a random number between 0 and x-1. So this assigns a global variable called RandomNumber to 0 or 1.

    Please login to see this picture. : Set AreaName to List Line Text$("Please login to see this picture."), Random Number)
    Retrieves the line from the Area Pool list object corresponding to the value of RandomNumber, and stores in a global string called AreaName. It's worth noting I changed the base index (the first line) to have an index of 0 rather than 1, the reason being Fast Loops have a base index of 0 and it makes comparisons easier. You change it in the List Object properties.

    Please login to see this picture. : Delete line RandomNumber
    Deletes the line corresponding to the value of RandomNumber

    Please login to see this picture. : Add Line AreaName
    Reinserts the deleted line, whose contents was stored in AreaName, back into the list object, at the end.

    Please login to see this picture. : Create Please login to see this picture. at (0,0)
    A weird bug I discovered while making this example is that if you load multiple external files into a List object within a single fast loop, only the first file is loaded!!! Until after the loop, when Fusion loads the most recent file you asked for. So, if you create and destroy a new List Object each time you need to load data into it, it solves the problem.

    Please login to see this picture.: Load list file Apppath$ + "\Data\" + AreaName + ".txt"
    Loads the external file AreaName.txt into the newly created List Object, this is the Area Contents list.

    Please login to see this picture. : Start Loop "Blit" List NB Lines ("Please login to see this picture.") times
    Starts a nested fast loop called "Blit", and runs it as many times as there are lines in the Area Contents list. Blit simply means to draw to the screen from a source, which is exactly what the Blit loop does, creates and pastes Active objects all about the place.

    Please login to see this picture.: Destroy
    Clean up. Destroys the current Area Contents list, ready to create the next one. It is very important to understand that this action isn't executed until the entire Blit loop (started above) has been executed.

    So, that's it. This entire list of actions is contained within a single fast loop called MapGen, which is run 20 times at Start of Frame to create the map. If you change it to always, then on every single frame (60 times per second) you are creating 20 more Areas, a total of 1200 areas each second, and that's explains the framedrop. You may as well create the entire level at start up. And correct, the extra width is to accommodate for the gaps between areas.

    If none of that made any sense, you should read Please login to see this link. article on fast loops. Good luck man.

  • To be honest, once you start doing anything remotely advanced in Fusion, the workspace gets reaaaaally ugly, and worse, exponentially unreadable. I simply had no idea how truly beautiful code could be until I began learning real languages. I mean I just had no idea. Their structural perfection is matched only by their potentiality, and the collaborative forethought and innovation truly moves me. Dawn stings these bloodshot eyes, yet in awe, they stare into my terminal, marvelling at the literally unobtainable body of knowledge within it. I commit this post to the void with a glad heart. For within each seed, there is a promise of a flower, and within each death, there is a new life.

    LB, Tigerworks, Sketchy, Nifflas, they're all dead. I should reach the frontier in about six weeks. With a little luck, the network will pick me up.
    This is Christopher Burrows, nomad, thief, programmer, and wild organism, signing off.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!