[PLUGINS] Data Structures

This forum is currently in read-only mode.
0 favourites
From the Asset Store
a complete set of modular graphics, perfect for all kind of levelbuilding
  • So I disappeared for a week or so, had to take care of some real life stuff. So to make up for it, I whipped up three quick and easy plugins that give Construct users access to some fairly basic programming concepts. The data structures included in this pack are stacks, queues, and deques. There is a fairly comprehensive tutorial cap included. These structures are all one dimensional and sound extremely basic at first, but they open up many more possibilities than they seem to at first glance. I have given them the ability to store integers, floating point decimal numbers, and strings.

    A stack is a simple structure that can be visualized as a stack of dinner plates. It is one dimensional, and when you add an element, it is added on top. When you remove an element, it is also removed from the top. Therefore the more elements you add, the more you bury your first element. Your first element will always be your last one out of the stack.

    A queue is just the opposite. It's kind of like a line of people at the movie theater. When an element is added, it is added to the back. As elements are added, they are pushed forward, and elements are removed from the front. The first element you add will be the first one removed. Just like a movie line - unless someone cut in front of you.

    A deque is just like a queue, except elements may be added from either end, and removed from either end. The word stands for "Double Ended QUEue". It's pronounced "deck". When an element is added it is pushed towards the center of the deque. Deques also have a special property that stacks and queues do not - a stack and a queue only give you access to the top element (in a stack), or the front and back elements (in a queue). All of the other elements are stored, but you can't access them, like you would an array. A deque gives you access to any element in the deque. So it's kind of like an array that you can add elements to on either end. It's complicated - but if you play around with the included cap file, you will understand in time.

    You add elements to these structures using the "push" action. You remove them using "pop" actions. Then you can access the structures via expressions to see what is inside them.

    The interactive cap file will explain these concepts more than I ever could with text. So have at it! And thank newt for the idea - he gave it to me. Now I will start finishing up with Muse.



  • Ahh, pushing and popping the stack.

    Reminds me of my old z80 Machine Code days.

    I'm sure they'll come in very handy.



  • So awesome once again Arsonide! Data Structures plugin will prove incredibly useful! My head is already spinning with ideas.

  • sounds great

  • NICE!

  • The deque expression "at" is not working, due to the word "at" being reserved by Construct for some other purpose. I'm going to upload a new version in a minute that fixes that expression by changing the word to something else.

    EDIT: Fixed. New version is up - at was changed to Deque.element - remember that particular expression is 0 indexed, and that accessing anything that doesn't exist (this also goes for stack tops, and queue front/backs - though the only time that would matter is if the stack or queue is empty), will always come up as 0.

  • Awesome stuff.

    Should make recursion a breeze.

  • Thanks for the plugin, but I don know how could I use it, I don't understand it . Could someone give me an example? Like when I really should use this in a game, because if I did the same thing without the plugin, it would be too tedious, hard to make.

  • The latest example of a stack that I've used is parsing a mathematical expression with nested parentheses. I would receive a string from the user of a mathematical expression, such as (5+2*(4/(1+1))).

    Now rather than let the compiler handle this on it's own, I can manually parse this using a stack. I had to do this because it was not actually a mathematical expression but a ruleset for the name generator in Muse. After the stack was filled, it looked like this: ((())).

    It was a stack of parentheses, and in a for loop I would wait until the last one was a ( and the current one was a ). At that point I would solve everything in between them since I was in the inner most pair of them, then replace that section of the expression with the solution, and start over again after popping them off the stack.

  • Thanks these plugins will be very useful

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sounds like it could be helpful, but I'm not sure what for.

  • Here's a quick demo to show how each plug handles data differently. Just toggle the corresponding events for each plug type.


  • Thanks for the example newt.

  • Thanks newt, it's emberassing, but I still don't know how to use in in a game. I understand the concept, but don't know where it'd be helpful. For what should I use it - score table? For what it'd be ideal? Usually, my head is full of ideas, but I can't think of one for this plug. Could someone give me a few?

  • Well basically you want to use it when you want to keep track of a list of things that don't exist as objects. For example, scores, coordinates, colors etc. Now we have other objects that can do that, but SQD offers a different way to access that data on the fly, and either use it, or change it without having to worry about preserving order.

    A good example might be powerups. Say you have a ship that gets a powerup when it collides with an object, but you don't want to use the bonus right then, like only when a player presses a button.

    With Stack you can do that like a bullet clip, where the first bullet in is the last one out.

    +> Ship on collision with bonusbomb

    ->stack push bonusbomb

    +>Ship on collision with bonusfireball

    -> stack push bonusfireball

    +>M&K on space bar pushed

    ->Ship spawn object(stack.top)

    ->stack pop top

    So with that if the ship ran into a fireball, then a bomb, and then another bomb, when you pressed space it would spawn a bomb, then another bomb, and then a fireball, but then the stack would be empty, just like a clip.

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