The Musings of a Non-Programmer

0 favourites
  • 13 posts
  • I'm an artist. Lemme just throw that out there first and foremost. I don't code, and I very nearly failed the one Computer Science course I attempted to take (to be fair, that was in-part due to the teacher).

    Still, I'm trying out Construct to see if I *can* do this at all.

    The first thing I did was go through the Ghost Shooter tutorial, and that was relatively helpful, but left a lot of things open.

    Currently, I'm trying to take baby steps through a project of mine (a mashup of Advance Wars and Nethack, complete with procedural level generation). Figuring that terrain generation would be the hardest thing to achieve for me at first, I went ahead and got started. I want to use the Diamond-Square algorithm for creating my maps, but I don't know enough about how to handle arrays in C2 in order to even get started.

    So here's question #1 (of many, many to come): how on Earth do I fill an array with variables? Does it start filled with 0? And how do I key each number to be relative to a sprite?

    Here's my barren and pathetic excuse for a capx. It's got my sprites, though, and the little dog from one of the Zelda games acting as my camera for viewing the map (once I can manage to get it generating). Based on the algorithm, I was attempting to set each corner of Map to 4, and then I was going to set up something to 1). execute the algorithm itself, and 2). set each element in the array to translate to a sprite somehow (0 being water, 1 being sand, 2 being grass, and 3 being mountains). I'm starting simple, like I said. It'll look nicer and be much more complex later on, but for now I can barely get started.

    I really appreciate you guys bearing with me on this (those of you who read through my whining). Thanks a lot.

  • Hey, welcome to the forum :)

    Figuring that terrain generation would be the hardest thing to achieve for me at first, I went ahead and got started.

    If you're not familiar with how events work, procedural generation is kind of jumping in to the deep end. I think it's best to start with simple projects and build your way up from there, otherwise you will quickly get stuck!

    o here's question #1 (of many, many to come): how on Earth do I fill an array with variables?

    It all comes down to setting up some events that call the 'Set at XY' action (for a 2D grid, anyway).

    oes it start filled with 0?

    Yep.

    nd how do I key each number to be relative to a sprite?

    Do you mean actually creating the sprites from the data in the array? A 'For Each Element' (on XY axes) event should do that. Each iteration compare the current number in the array, and create a sprite based on that number. Subevents are good there.

    I was going to explain this, but I just added it in to your capx. Try this: http://dl.dropbox.com/u/15217362/tileengine.capx

    You should be careful about creating lots of sprites, though. Having too many sprites can slow down the game a lot. I'd recommend waiting until the next release or two when we add 'snap to grid', then maybe put it together in the layout editor, using tiled backgrounds wherever possible for large areas of sprites. Otherwise, the sheer sprite count could slow down performance.

  • Thanks, for both the welcome and the advice.

    I think I kinda see how I can do this now... but as I said, there are undoubtedly more questions to come. Again, thank you for bearing with me.

    The edit to my capx was very helpful.

    I'll post here again when I run into another wall.

    EDIT: How did you create subevents underneath of the subevent? Under the For Each loop of the Array you made, there are more subevents that handle the actual placement of tiles, but I can't see how you did that.

    EDIT2: I found one way I could do it, although I'm sure there's an easier way (create the subevent and then just drag it over to the right until the black line becomes an arrow).

  • Select a sub-event, right click and you can "Add sub-event". (or "Add blank sub-event")

    If you go for some "moving" of block in the sub-levels (if you know what I mean):

    Click on a block and keep your left button down.

    Move your cursor over the white part (stating the actual event) of an event block.

    A black line will appear with an arrow shape at one of its end under the event you're overing, meaning that releasing the left button will move the selected block as a sub-event of the overed event. (ouch, simple concept, hard to put in words ^^)

    Edit: Ninja'd

  • Hehe, thanks Kyatric. Good to know.

    Alright, so I've got a simple random generator going... or I would, at least, if I didn't get this error: "Assertion failure: No default instance when creating object."

    As with most errors, it's *just* vague enough to let me miss what it's trying to tell me. Not sure what's going on.

    Capx.

  • The errors tell you that you are trying to create an object, but this object has no default instance (meaning, it doesn't even exist anywhere on your layout).

    And it is true. The sprite in the left corner with the other terrain sprites is nammed "Sprite5".

    In the right window, click the tab "Projects" and check the folder "Object". It has many more objects than it appears.

    Two solutions : either change the code when Map.CurValue is 1 to create a "Sprite5" object.

    Or (and advised) delete every unused object from the tab Project (including the object Sand), then rename Sprite5 to Sand and complete your code (the line at Map.CurValue = 1 should have disapeared). Simply select the line above (creating water) hold ctrl and drag/drop to copy it.

    This should do the trick.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It works!

    <img src="http://filesmelt.com/dl/success11.png" border="0" />

    Step 2: Actually plug in the algorithm (not sure if I want Perlin noise or the Diamond-Square yet).

    Step 3: Add transition tiles to make it more natural.

    Step 4: ???

    Step 5: profit.

    Thank you, Kyatric. I've cleaned up the objects, the only things left are the things that I'm actually using.

    • snip -

    Scratch all of that, I found an Action that System can perform that rounds numbers up. Now, to figure out how to translate the formula into terms Construct can translate...

  • Well the function random(x,y) returns decimal numbers.

    Ceil() rounds number up to an integer, floor() rounds number down to an integer and round() rounds to the nearest integer.

    For example:

    random(0,3) will return a decimal.

    round(random(0,3)) will return an integer.

  • Awesome, thanks.

    Yet another question: is there a way to create a seeded random number generator?

  • No, you can't seed C2's random number generator yet.

  • Alright, cool.

    So, part of the functionality of it is being able to write custom scripts and plug them into the Event Sheet, amirite? Or was that just with Construct Classic, and hasn't yet made it into Construct 2 yet?

    If it is available at the moment, how does one go about it?

  • You can extend Construct 2 by writing plugins in javascript - no inline scripts in the editor yet.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)