Arrays with more than 3 dimensions

For questions about using Classic.

Post » Thu Jul 12, 2012 10:52 pm

It would really save me a lot of code for my project if I weren't restricted to arrays with only 3 dimensions. It is possible to get 4+ dimensional arrays in Construct Classic? I've looked around for a plugin or a mod or a workaround of some sort with no success.

Thanks.
B
1
Posts: 5
Reputation: 235

Post » Thu Jul 12, 2012 11:45 pm

When data constructions get that complex you shouldn't work with arrays. A better way would be to use custom classes (data structures). lucid's 's' or Python offer that. Ignoring technical aspects it also helps you in the development process to access data with something like
npc.villager(1).female.lefthand.fruit
instead of
array(1, 1, 2, 2, 4)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Jul 13, 2012 11:36 am

"S" looks like it will work just fine then, thanks a lot.

I'm strange, and although I would use data structures in CC for some things if I knew how, there's a lot of things I prefer to use numbers for anyway ^_^
B
1
Posts: 5
Reputation: 235

Post » Fri Jul 13, 2012 7:57 pm

You could use a 1-dimensional array.
Say you want a 4-dimensional array 5x6x3x2:

+ System: Start of layout
-> Array: Set size to 5*6*3*2 x 1 x 1

+ Function: On function "At"
-> Function: Set return value to 0
---+ System: Function.Param(1) is between 0 and 4
---+ System: Function.Param(2) is between 0 and 5
---+ System: Function.Param(3) is between 0 and 2
---+ System: Function.Param(4) is between 0 and 1
----> Function: Set return value to Array(Function.Param(1) + Function.Param(2)*5 + Function.Param(3)*5*6 + Function.Param(4)*5*6*3)

+ Function: On function "Set"
+ System: Function.Param(1) is between 0 and 4
+ System: Function.Param(2) is between 0 and 5
+ System: Function.Param(3) is between 0 and 2
+ System: Function.Param(4) is between 0 and 1
-> Array: Set index (Function.Param(1) + Function.Param(2)*5 + Function.Param(3)*5*6 + Function.Param(4)*5*6*3
, 0, 0) to Function.Param(5)

EDIT:
This is a zero-based array, if you want a 1-based it will require a bit of tweaking.R0J0hound2012-07-13 21:25:58
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Fri Jul 13, 2012 8:51 pm

It can get confusing, but you could use a string with nested tokenAt()'s, and different delimiters.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Fri Jul 13, 2012 8:58 pm

[QUOTE=R0J0hound]
----> Function: Set return value to Function.Param(1) + Function.Param(2)*5 + Function.Param(3)*5*6 + Function.Param(4)*5*6*3
[/QUOTE] Shouldn't this line be
----> Function: Set return value to Array(Function.Param(1) + Function.Param(2)*5 + Function.Param(3)*5*6 + Function.Param(4)*5*6*3)
?

(I omitted a solution like this because of the complexity. It really isn't very intuitive. But that's totally personal subjective view :D )tulamide2012-07-13 20:59:53
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Fri Jul 13, 2012 9:24 pm

@tulamide
That's correct, my mistake. I really should have tested it before I posted it to avoid stuff like that.
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 6 guests