Callback array

0 favourites
  • 8 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Ok just like with variable I do know how to do callback with those.

    But currently i am using CVS to array and I have three different array being created the same way and yes i do have ajax on the start to load them all up using rex plugin.

    Here the question. Let say two of the array are just stats providing the bare bone of the base number for each character.

    and the last array is for your own party.

    How do i call back in specific areas of that array without having to use number value such as this in the party array I have it set up to where in slot X=2 is health column and Y= 1 row is the party member order #1. And let say that you r person is name bob which is located in Party array 1,1 slot.

    And in my other array I want to retrieve the data for Bob which is a Row name and Id like to call back the column as well.

    so in other word if array containing Bob is on Row 1 id like to add that in to the function of in the event of adding from one data of array to another without having to load value number of the row n column to shorten event load time. as in i do not want to do 500 stupid event just for input values in every slot of the party member spot. But rather a callback function that would know where to plug in data from one array to another using Names of the column and rows. Cause i doubt creator of rpgs dont have like thousand of event for array alone.

    If this is confusing i am sorry this was the best i could explain it.

  • Basically you do not know *where* Bob is in the array? I had a similar challenge when I attempted modelling customizable spacecraft. Instead of creating an object for every module, with its own variables, I stored everything from stats, sprite ID etc. to description in an array.

    If you have the name in row 0 (y=0) of your array you can just use array.indexof("bob") as shown in the capx:

    Some explanation on the capx. When you click on the button it retrieves a random name from y=0 of the party array. It stores that random name as a text string in the buttons variable. Then the same name, as text, is passed to the ReturnPartyMemberName function as a parameter, stored as a text variable "name" (the function.param(x) expression can in some cases not be retrieved within a function event after some sub-event or actions, so it is best to store the parameters in local variables located in the fun just in case) and array.indexof(name) will retrieve the x index of the name. ... .capx?dl=1

    If you have names stored in another row, or worse, if you have names all stored in column 0 (x=0), or any other column, with each row a different party member, you need to do a custom search function for retrieving the index. It is a bit more difficult but not impossible.

  • I did take a look at your example problem is that your example only shows one array while im trying to use two different array One for party and one for game data stats. I have no problem using a call back for one array and then using a variable that the easy part. but im trying to retrieve value from an array into another array that part i cannot figure out or least knowing what code to use

    another explantion i can give is that let say i have an array like this



    As you can see bob has 100 hp but the value of bob Y is at (1) and the hp is X (1)

    So in other word i want to use a function callback that if when bob is in the party then I want to load his stats from a call back such as this instead of saying retrieve value of 1,1 which is bob's health. I want the function callback to find it for me just by using ("Name") and then ("Hp") Most likely in a for each loop so that if when I add more data for new member to use it can still use the callback without needing to add in each single value as a event/action You can imagine how large of an event sheet that would be.

    And the above array is just purely stats that will be the same but will only change on the party array.

    I know this is semi possible because I have done it in the past of using instance variable with the reference value but id like not to do that because I know when i go to re order the value the variable might be off. And two this would save me on a-lot of recoding which is why I turned to cvs to array just to lessen the burden of seeing a very hard to visualize the making array in the program can get.

    If there a way I think your "Index of" might be it but I want to be sure without pulling hairs lol

    Because I think or least so far I think the code would have to be something like [insert value in party member 1,2 (which is bob hp slot)to retrieve" is bob),"hp" (which is hp in the stat) So that it should read it as (1,1) but as call back using name as the primary finder I am fine having to recreate this only a couple of time for health,power,speed. That is still a four hundred less to code. And if the name isnt bob but rather Kitten then the call back should reroute the new array positional to a new Y number without me having to make a whole new event one. Again if i confuse you please let me know this is best way to explain it. And thank you for your help. This is the last piece of my puzzle of making an rpg.

  • Gearworkdragon

    I have been working on a database application in C2 and ran into the same problem. There is no "easy" solution, but there are a few ways to get close to what you want. First, you could try using the Dictionary object. It allows you to define names, then get the value associated with that name in an expression:

    so, you would have a Dictionary with: "bob":1 "kitty":2 "joe":3 "mary":4... "HP":1 "power":2 "speed":3...

    then, when you want to lookup bob's HP you would use:"bob"), Dictionary.Get("HP"))

    Since I am working with a MySQL database, I have the calls to the database return the field names as well as the data, then use TokenAt to find what I am looking for, because the query could return fields in different positions depending on what I ask for - so I can't assume they will always be in the same place.

    EDIT: and of course, you can create a general purpose Function called LookupStat (or whatever) and pass in the name, and the stat you want.

    then you could have: value = Function.Call("LookupStat", "bob", "HP")

    in the function you would have Function.Set Return Value to, Dictionary.Get(Function.Param(1)))

  • Not that difficult if you store nothing on the X-axis (only using it as index). Most of this code is making the array and displaying results. The list is just to make the array in a lazy way and to avoid typing in the search box (also lazy). ... .capx?dl=0

    Or ? Do i not understand the question ?

  • Hmmm 99Instances2Go

    ....I was thinking. Since i am using Ajax and CSV Is it quite possible to return a Whole single column index on the X axis on an array into a CSV stand alone and then Have AJAX pull it out from CSV and then insert into the desired new array X index ?

    Cause that would be a nice work around or is that not possible due to how data Is done

    Is it possible and if it is how would one do it ?

  • Dude, you do know that you now ask a pro-question coming from a pro to a beginner. I have not handled CSV yet.

    Besides that. There are plugins to translate CSV to an array (or a dictonary). I did not arrive to those yet in my path of learning construct.

    What i wanted to show you is this. If you dont store values on the X-axis, you kinda upgrade the array to a 2D list. A list containing lists. Pretty easy to acces in the way you need to acces it.

    I am stil not sure if you only need to find the index of "BOB". But lets assume you do. Then.

    You could also use a dictionary. With 'BOB' as the key, and in the value an temporal dictionary as AsJSON.

    Finding 'BOB' in the dictionary is easy, not as index but as 'key'.

    When found, set a temp dictionary to the 'value'. And there are all your values.

    See what i mean? Hope i show you some options.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Solved thx you guys the and Array.index was it. Oh and I used variable to find the other Y number and I just had it repeat based on the array Height and then added one to the variable so that It would continue down the line.

    In other word what would have to be originally 32 something event/action is now just one line and a function

    But yes I was asking for the impossible when I realized something I could have extracted the Value of X for from a variable that i was already using.

    Im just wondering how come there isnt more of this type of tutorial rather then having to trail n error defferent effect to achieve min effort for a grand effect. I mean for all the RPG developer should really adopt the CSV to array and then function in If not already explain else where.

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