Order values in an array

For questions about using Classic.

Post » Thu Aug 08, 2013 1:18 am

I have to apologize for having so many questions these past few days - I don't mean to clutter the forum, but I'm very much an amateur when it comes to this stuff, haha.

So what I'm looking to do is determine turn order for a turn-based kind of game. The idea I have is taking all the speed stats of the players/enemies and storing them in an array at the coordinates (1, 1), (1, 2), etc. I want to make the value at (1, 1) the largest, then (1, 2) the next largest, and so on. Then, I'd have a value called "Turn" which stands for whatever the turn number is - after each turn, I'd add 1 to it, and the game would check which value in the array is at (1, "Turn") to find out who goes next (obviously it'd need to be a bit more intricate than this, since the values need to refer back to whoever has that particular speed stat, but... this is just a start, haha).

This is my current idea, anyway. Regardless of whether I stick with this method or not, I'm going to need some way to order the speed stats - I'm figuring an array would make sense here, but I'm not entirely sure.


Also, so I don't have to make any other topics for this (and the questions are sort of related), I've been looking into the "S" plugin because it sounds like something that could be very much helpful to my cause of making an RPG... but I'm not entirely sure how it works, it seems fairly detailed and complicated. Are there any caps out there that demonstrate its functionality or anything? Or tutorials or something? I couldn't find anything particularly helpful through searching, but maybe I just wasn't looking close enough.

Thanks guys, appreciate the help you've been giving me.Jalopes2013-08-08 01:19:30
B
10
S
2
Posts: 22
Reputation: 644

Post » Thu Aug 08, 2013 4:47 am

Not sure what you mean in terms of the array there. Can you explain more of the game mechanics you're trying to achieve and I might be able to think of another way to do it?
"Construct 4 lets YOU make advanced games! (but not play them)" Construct Classic - Examples Kit
B
113
S
39
G
17
Posts: 2,184
Reputation: 19,217

Post » Thu Aug 08, 2013 7:06 am

Sure. Basically what I'm trying to do is determine turn order for an RPG battle system. As in, one character takes his move, then the next, then the next, etc. The order that they take their turns in is determined by a "Speed" statistic. Whoever has the highest takes their turn first, then next highest goes next, and so on. Once the last turn is taken, it repeats from the beginning.

Using an array for this might not even be possible - I've never used the array object, and though I basically understand what it does, this might not be an ideal use for it. My idea was to take each individual speed statistic and order them in an array from highest to lowest. The value at (1, 1) would be the highest speed stat, the value at (1, 2) would be the second highest, (1, 3) the third highest, etc. In the game, I would check whose speed stat is at (1, 1) to determine the first turn, (1, 2) to determine the second turn, and so on.

The biggest thing here is being able to take a bunch of values and order them from highest to lowest. If I could do that, then I think I would be ok.
B
10
S
2
Posts: 22
Reputation: 644

Post » Thu Aug 08, 2013 9:59 am

Regarding sorting of arrays you might want to download my example game "Verve!".
It contains a lot of helpful tricks and general algorithms. And of course it also shows a way of sorting an array. It uses an optimized algorithm for sorting large arrays in a very short time. If you just have something up to 10 or so entries, you might just want to use bubble sort:
Basically compare a number with all the numbers in the array. If it is higher then you found the right position. If it is lower compare with the next position, etc.
How to re-arrange/re-structure the array to insert the number is shown in "Verve!"

Link: Verve!
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Thu Aug 08, 2013 8:43 pm

The simpler comparing method would probably be fine - I don't think there will ever be more than 5-10 values I'm going to have to sort.

It makes sense, but I'm having trouble imagining how to construct that with events - I hate to ask for more, but could you maybe give me an example or demonstration of how it could be done? Arrays are still kind of a new concept to me, so... yeah, haha. And Verve's events for sorting seem kind of above my level of comprehension at the moment... but I'm gonna keep looking at it, it seems like I could learn quite a bit from it.

Thanks man.
B
10
S
2
Posts: 22
Reputation: 644

Post » Thu Aug 08, 2013 11:47 pm

Here's an example. It is more simple in terms of learning curve. It uses two arrays. The first array contains the values that need to be sorted and the second array will contain the sorted values. During the process of sorting the content of the first array will be destroyed.
Therefor you should either use that first array as a cache, or copy the resulting second array back to the first, whatever is the easiest for you (or makes more sense for your game's needs).

sort_array.cap
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Thu Aug 08, 2013 11:50 pm

Awesome, I'll have a look at this. Thanks so much man!
B
10
S
2
Posts: 22
Reputation: 644

Post » Fri Aug 09, 2013 12:09 am

You're welcome
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests