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

0 favourites
  • 12 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • 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.

    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.
  • Hi,

    Array.At(Array.indexOf("ID_1"), Y Index of needed value) should work.

  • 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.

    This is pulling from the array I linked prior.

    Am I doing something wrong?

  • Do you have a sample capx so I can check what is going wrong?

  • 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".

  • 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'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.

  • 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:

    beufreecasse Thank you again so much for taking the time to respond.

  • It seems that index of only works if your ID is on the first Column.

    I changed your example

  • Oh, I forgot to put square brackets around my array values. Silly me, it works now.

  • Beautiful. Thank you beufreecasse so much for having the patience to help us here.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • So, now when I use the ID in the first column, then select the next column over to retrieve the name "Longsword" it is returning a value of 0 and not the string. My variable is set up for a string, and I know I'm calling it right.

    spr_player -> set currentWeapon to arr_playerWeapons.At(arr_playerWeapons.IndexOf(spr_equipWeapon.AnimationName), 1)

    currentWeapon is a string variable.

    What am I doing wrong here?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)