[PLUGINS] Data Structures

Completed plugins, behaviors and effects.

Post » Tue May 24, 2011 10:32 pm

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.

Download!
[url=https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=MLKA8US3Y734U&lc=US&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted:3he506ta]Donate![/url:3he506ta]
B
5
S
2
G
5
Posts: 221
Reputation: 2,272

Post » Tue May 24, 2011 10:47 pm

Ahh, pushing and popping the stack.
Reminds me of my old z80 Machine Code days.

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

Krush.
B
2
S
2
G
3
Posts: 406
Reputation: 2,062

Post » Tue May 24, 2011 11:00 pm

So awesome once again Arsonide! Data Structures plugin will prove incredibly useful! My head is already spinning with ideas.
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

Post » Tue May 24, 2011 11:02 pm

sounds great :)
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610


Post » Tue May 24, 2011 11:55 pm

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. :P

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.
B
5
S
2
G
5
Posts: 221
Reputation: 2,272

Post » Wed May 25, 2011 12:35 am

Awesome stuff.
Should make recursion a breeze.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Wed May 25, 2011 10:59 am

Thanks for the plugin, but I don know how could I use it, I don't understand it :oops: . 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.
ImageImage
B
25
S
6
G
8
Posts: 773
Reputation: 6,643

Post » Wed May 25, 2011 1:09 pm

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.
B
5
S
2
G
5
Posts: 221
Reputation: 2,272

Post » Wed May 25, 2011 3:55 pm

Thanks these plugins will be very useful :D
B
2
S
2
G
1
Posts: 121
Reputation: 1,092

Next

Return to Completed addons

Who is online

Users browsing this forum: No registered users and 0 guests