Transferring array values to instance variables

0 favourites
  • 10 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I've tried searching for how to do this, but there wasn't very much I could find and even then the examples I found where hard to understand.

    How do I use "tokenat" to get a value from an array, say the number 60 stored at 3, 1, 0?

    A tutorial or a method of making the expression easier to understand would be very helpful for me.

    EDIT: MY intention to take a value from an array (say again, 60 at 3, 1, 0) and store the found value in an instance variable.

  • you dont need tokenat for this. Look at the Array entry on the manual it has a way to get the value at a given position youd just use that to set the value of the instance variable.

    tokenat is for strings that contain certain characters you want to use to split that string into multiple values. Like the token at 1 in the string "a,b,c" would be "b" if the string was split up at commas

  • At(X, Y, Z)

    Or

    would it be Arrayname.At (X, Y, Z)?

    Edit: Okay, I get it partially.

    I have the value, now how do I transfer to the instance variable? Setting "Playerstats.At (2, 0, 0)" as the value of an instance variable doesn't appear to work.

  • LaDestitute, hope I'm not misunderstanding you here, but if you have a variable (ex: var1) of an object (ex: Sprite1), you can set the value of that variable to the array index as follows:

    Sprite1.var1 = Playerstats.At(2,0,0)

    Does that help?

  • Yes, somewhat.

    Now, I managed to get it to work almost but the value always reads "1".

    <img src="http://dl.dropbox.com/u/5899974/Graphics/Isthisright.png" border="0" />

    Did I do this right?

  • If I understand you correctly, I think it should be:

    Set Player.MaxHP to Playerstats.At(2,0,0)

    This will set the Player.MaxHP from the array

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If I understand you correctly, I think it should be:

    Set Player.MaxHP to Playerstats.At(2,0,0)

    This will set the Player.MaxHP from the array

    I don't know what's causing it, but when I set "Playerstats.At(2,0,0)" directly as the value of Player.MaxHP, I get a zero.

  • Because if you are using only the X (width) size of an array to stock values, you don't need to indicate the Y and Z locations.

    So

    Set Player.maxHP to Playerstats.at(2) is enough

    Getting a 0 out of an array cell often means the cell doesn't exist/is blank.

    Also if Player.maxHP is a number instance variable you might need to cast the result returned from the array.

    The values stored in arrays are string, you need to convert them when affecting them to numbers.

    Set Player.maxHP to int(Playerstats.at(2))

    (int() will return integer number, float() will return a float number)

    In the how do I FAQ, section "Arrays" you have several topics on the subject that explains the very same thing.

    You can, for example, find that commented capx.

  • I only had the y axis because I have multiple stats, so I wanted a row for each so I wouldn't have to reorder the array for new values later on.

    Edit: Nevermind. I fixed my problem, it was a group I had the stat storage in. It was never getting calculated since it was at the bottom instead of being the first group.

  • I'm glad that you have fixed the problem. You have to be careful how you order your groups. I had a similar issue recently!

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