Array Not Accepting Values?

New releases and general discussions.

Post » Sun Apr 05, 2009 8:35 am

Surely I must be doing something wrong, or I may have found a bad bug.

I have an array named "Characters", and at 3,0 there is the value 340 (I have an initializing event set up) . I also have a text object for testing if I did this right.

My string is this:
"Character's HP is " + str(Characters(3,0))
So, at 3,0 I should have gotten a value 340. Instead I have a 0, every time. I even tried other elements and got 0 for each one. To test further I saved the array to file and it was pretty much blank except for boxes and the text "ARR1.05".

Have I stumbled upon a bug or did I do something wrong?
B
2
G
3
Posts: 13
Reputation: 876

Post » Sun Apr 05, 2009 8:43 am

arrays no longer start at 0
start at 1 instead of 0 and it should fix the problem
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sun Apr 05, 2009 8:44 am

How do you initialize the value?

Also, you don't have to use + and str() to display text; just use &, which concatenates strings; it will automatically convert numbers to text that way. So,
"Character's HP is " & Characters(3,0)

Okay, I just realized it. The Array is 1-indexed; the 0 is out of bounds, it doesn't exist. Rows and columns begin at 1; you should be setting it to (3,1), not (3,0). Actually, you can skip the second number and it will automatically get the first row.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sun Apr 05, 2009 10:51 am

[quote="Mipey":rkswwre7]How do you initialize the value?

Also, you don't have to use + and str() to display text; just use &, which concatenates strings; it will automatically convert numbers to text that way. So,
"Character's HP is " & Characters(3,0)

Okay, I just realized it. The Array is 1-indexed; the 0 is out of bounds, it doesn't exist. Rows and columns begin at 1; you should be setting it to (3,1), not (3,0). Actually, you can skip the second number and it will automatically get the first row.[/quote:rkswwre7]

Oh wow, that did it. Didn't realize it was 1-indexed. That got it working.

That needs to be included in the Wiki, I don't know if I can add that in myself.
B
2
G
3
Posts: 13
Reputation: 876

Post » Sun Apr 05, 2009 10:58 am

Everything is (or at least should be) in a 1 based index now.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Sun Apr 05, 2009 3:11 pm

[quote="WontoonRoo":3e4u33pq][quote="Mipey":3e4u33pq]How do you initialize the value?

Also, you don't have to use + and str() to display text; just use &, which concatenates strings; it will automatically convert numbers to text that way. So,
"Character's HP is " & Characters(3,0)

Okay, I just realized it. The Array is 1-indexed; the 0 is out of bounds, it doesn't exist. Rows and columns begin at 1; you should be setting it to (3,1), not (3,0). Actually, you can skip the second number and it will automatically get the first row.[/quote:3e4u33pq]

Oh wow, that did it. Didn't realize it was 1-indexed. That got it working.

That needs to be included in the Wiki, I don't know if I can add that in myself.[/quote:3e4u33pq]

just glossed over my elegantly simple reply, didn't you?

just kidding


...you did though
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Sun Apr 05, 2009 3:30 pm

He did! *points accusingly*
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Mon Apr 06, 2009 12:13 am

[quote="Mipey":3puzmf2h]He did! *points accusingly*[/quote:3puzmf2h]

Mipey, Lucid, thanks for the responses! :O)
B
2
G
3
Posts: 13
Reputation: 876


Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 5 guests