2 identic arrays are different

For questions about using Classic.

Post » Fri Apr 29, 2011 10:44 pm

I'm having a problem with arrays

I started by making my array directly on events, just to test my game


Then I moved on to creating it on a separate file, so I made an array editor:


But then the game stoped working

I saved both arrays, and they happen to have different sizes:


And different content:


But I loaded each of them into my array editor and both showed the same numbers

Why is this happening?
B
83
S
21
G
15
Posts: 1,039
Reputation: 15,134

Post » Fri Apr 29, 2011 11:38 pm

It could be because the array is stored differently when held in memory than when saved from a text box. However, I notice that you use a 3 dimensional array which can get pretty compicated. Might be worth drawing the 3 dimensions out on paper to note what data is stored where.

If you're still early in development and need another solution for map saving, I'd recommend using INI files, here is an example cap: [url:2zzgd9uw]http://www.scirra.com/forum/viewtopic.php?f=8&t=1721&p=12302#p12302[/url:2zzgd9uw]
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Sat Apr 30, 2011 7:20 pm

Your array editor looks like it's saving the values as text instead of numbers. It shouldn't make much of a difference though as construct easily converts text into numbers.

However you will run into an issue when you try to add two array values together and they are both text. The text will be concentrated together instead of added numerically. The solution is to convert the values to integers with int().

Ex:
Array(1,2)="10"
Array(1,3)="11"

Set Text to Array(1,2) + Array(1,3)
// Text will be "1011"
Set Text to int(Array(1,2)) + int(Array(1,3))
// Text will be "21"
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 2 guests