How do I pull a value from y based off of x position.

Get help using Construct 2

Post » Sun Mar 15, 2015 4:32 pm

I'm having a problem trying to figure how to pull a value from a y column picked by the x of a string in an array.

Here is my array.

Code: Select all
{
"c2array":true,
"size":[3,4,1],
"data":[
[
["weapon"],["Anim_Name"],["ATK_Mel_Max"],["ATK_Mel_Min"]
],[
["Longsword"],["ID_1"],["10"],["4"]
],[
["Axe"],["ID_2"],["9"],["6"]

]]
}


I have an object that has different animations(different weapons). They are identified by "ID_0" and so on. When a player equips a weapon, I want to pull from an array the stats of the weapon by its animation identifier, In this case "ID_1" or "ID_2", and place the needed integers in the character's variables. In this case "ATK_Mel_Max" and "ATK_Mel_Min".

I've been reading on 'For' and 'token' the past two days, thinking that something needs to happen there, and really haven't figured out a way to get this done. I've done several tutorials on loops, but haven't really found an application here.

Thank you for your time.
I must not fear. Fear is the mind killer.
B
10
S
1
G
1
Posts: 22
Reputation: 966

Post » Sun Mar 15, 2015 5:17 pm

Hi,

Array.At(Array.indexOf("ID_1"), Y Index of needed value) should work.
B
14
S
4
G
2
Posts: 190
Reputation: 3,938

Post » Sun Mar 15, 2015 5:38 pm

Thank you for your response, beufreecasse.

I've entered that for my variable value, but I'm getting a return of '0' when its updated.

This is what I have entered on my event sheet using the array I posted earlier.

https://www.dropbox.com/s/jsezcqmlxqi0isk/function.png?dl=0

This is pulling from the array I linked prior.

Am I doing something wrong?
I must not fear. Fear is the mind killer.
B
10
S
1
G
1
Posts: 22
Reputation: 966

Post » Sun Mar 15, 2015 9:24 pm

Do you have a sample capx so I can check what is going wrong?
B
14
S
4
G
2
Posts: 190
Reputation: 3,938

Post » Sun Mar 15, 2015 9:57 pm

I made a quick example, that pretty much encompasses what I'm attempting to accomplish.

After loading the JSON, the player clicks on the item.

Trying to set the instance variable "ATK" on the player to the animation, "ID_1", over one spot to the value of "10".
You do not have the required permissions to view the files attached to this post.
I must not fear. Fear is the mind killer.
B
10
S
1
G
1
Posts: 22
Reputation: 966

Post » Mon Mar 16, 2015 1:02 am

Ok, It looks like my biggest issues are:

1) Searching for a string in an array and identifying its index.
2) Using that index to locate another index by adding or subtracting from the y or x.
3) Taking the value placed in the new index and applying it to an instanced variable.
I must not fear. Fear is the mind killer.
B
10
S
1
G
1
Posts: 22
Reputation: 966

Post » Mon Mar 16, 2015 9:29 pm

I'm actually having this exact problem. I'm trying to add skins(costumes) using a JSON file which contains the ID, name and price of each skin. Every time I try and get a value from the Y column using an X value I always get a 0.
It's weird because I can get values from column 1 (which contains the name) of the array, but columns 0 and 2 always returns a 0. I'm not sure if it has something to do with it being a string.
B
17
S
5
Posts: 47
Reputation: 1,109

Post » Mon Mar 16, 2015 9:52 pm

@vybr I'm glad I'm not the only one, lol.

beufreecasse replied again to my other post with specific questions about the command here:

https://www.scirra.com/forum/viewtopic.php?f=147&t=126834&p=897819#p897819

@beufreecasse Thank you again so much for taking the time to respond.
I must not fear. Fear is the mind killer.
B
10
S
1
G
1
Posts: 22
Reputation: 966

Post » Mon Mar 16, 2015 11:32 pm

It seems that index of only works if your ID is on the first Column.
I changed your example
You do not have the required permissions to view the files attached to this post.
B
14
S
4
G
2
Posts: 190
Reputation: 3,938

Post » Mon Mar 16, 2015 11:51 pm

Oh, I forgot to put square brackets around my array values. Silly me, it works now. :)
B
17
S
5
Posts: 47
Reputation: 1,109

Next

Return to How do I....?

Who is online

Users browsing this forum: Emerson97, krombanna, newt, onweare, tarek2 and 5 guests