Family's & Arrays, item sorting and selection(Solved W/CPAX)

0 favourites
  • 15 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Family's & Arrays, A question of item sorting and selection.

    Howdy,

    This is a problem for my game that I have been struggling with off and on for a good three months now and have come to ask for assistance in getting this part of my game nailed down so I can move on.

    Below is provided a .cpax of my game that is the core issue I am trying to work though. The goal is that I can have a roster of items (Party Members) that is filtered so the only things you see in the menu is what you have available. The full game will be a multi player combat arena where each person will bring in groups and have them fight in tactical turn based combat. However first I must have it so you can only select the party members based on what you have unlocked/awarded. Listed below is a number of avenues that I have tried to use but still can not get to work.

    Remember that scalability is key as the final game will have 100+ choices and I also need the ability to update this list server side to add to that number. But we'll just get the foundation set before going crazy.

    I have each party member in a family with a family instance variable of either true or false. When the scene loads I run though a 2darray that includes every member in the family and based on that loop set the variable for each unlocked family member to True. Then when you select a slot for any of your slot a menu pops up that you can scroll though that lists all available persons. Chosen by a for loop for each family member that their varable="T"

    The problem I am running into is that I can not link my array and family. Meaning that I cant run though the array and have each row correlate to a member of the family. I have tried having each row being the UID of each member but I can not find a way to automate that idea. And simply having Bob.UID in the first part of each row does not work.

    I have also tinkered with RexRainbow's CSV plugin's hoping that later down the road each player can have a JSON string that can pull form a master file and self update when something like unlocking a new party member happens.

    But again how would I link the CSV and the Family? I can only put the CSV in as one string so I can not place variables embedded inside the string that the engine can read and use.

    I have looked into XML but it is still too new to me for me to understand what exactly I need to do in order to get the desired result.

    TLDR; How do I filter a family by a array or CSV string.

    Thank you for your time,

    CrazyVulcan

  • Im not really sure what you are trying to do.

    [quote:7uf79jho]The problem I am running into is that I can not link my array and family. Meaning that I cant run though the array and have each row correlate to a member of the family. I have tried having each row being the UID of each member but I can not find a way to automate that idea. And simply having Bob.UID in the first part of each row does not work.

    I don't understand what you mean that you want to link the array and family?

    The array hold whatever data you add to it, and can not be linked to anything, in theory any object in your game can use these data if you want them to, depending on your conditions for reading and making use of the content in the array. If what you mean is that you have stored some data to the array at some point and then when a character is available you want to use this to set some settings for the character, then you have to make sure that these characters UID matches the ones stored in the array, which it could sound like it doesn't.

    I get the impression that this is what you have been trying. But its very hard to troubleshoot when not sure how and what you store in the array.

    The family is also something that you cant link anything to, it more or less just a wrapper that can hold a group of other objects of different kinds but which share some common attributes, and therefore makes it easier to work on several different types of objects at the same time. So I don't understand what you mean with linking to it? If your characters are part of the family they are already "linked" to it through that and can be selected using:

    Pick Random FamilyCharacters

    Character1.UID = FamilyCharacters.UID (Assuming that the random Familycharacters chosen is a character1)

    Can you try to explain what you want to use the family for and when, and what the array hold of data that you need. And how and when you store the data, in correlation to when you need to read from it, think that would make it easier to help you?

  • Im not really sure what you are trying to do.

    [quote:3h7aws6w]The problem I am running into is that I can not link my array and family. Meaning that I cant run though the array and have each row correlate to a member of the family. I have tried having each row being the UID of each member but I can not find a way to automate that idea. And simply having Bob.UID in the first part of each row does not work.

    I don't understand what you mean that you want to link the array and family?

    The array hold whatever data you add to it, and can not be linked to anything, in theory any object in your game can use these data if you want them to, depending on your conditions for reading and making use of the content in the array. If what you mean is that you have stored some data to the array at some point and then when a character is available you want to use this to set some settings for the character, then you have to make sure that these characters UID matches the ones stored in the array, which it could sound like it doesn't.

    I get the impression that this is what you have been trying. But its very hard to troubleshoot when not sure how and what you store in the array.

    The family is also something that you cant link anything to, it more or less just a wrapper that can hold a group of other objects of different kinds but which share some common attributes, and therefore makes it easier to work on several different types of objects at the same time. So I don't understand what you mean with linking to it? If your characters are part of the family they are already "linked" to it through that and can be selected using:

    Pick Random FamilyCharacters

    Character1.UID = FamilyCharacters.UID (Assuming that the random Familycharacters chosen is a character1)

    Can you try to explain what you want to use the family for and when, and what the array hold of data that you need. And how and when you store the data, in correlation to when you need to read from it, think that would make it easier to help you?

    Thank you for replying,

    It very well could be that I am approaching the entire problem wrong but when I say I need to link the array and the family I simply mean that I wish to have a group of objects (Character Images/Avatars) and sort them so that they will appear in order on my menu.

    example if I have a array

    Name, Stat1, Stat2, Unlocked

    Bill,2,1,False

    Ted,1,3,True

    Sue,2,2,True

    And then have a command to build a populate a menu I need it to only list Ted and Sue, and exclude Bill. I also want it to on each menu tile to list Stat One and Stat Two in a textbox. Now each Avatar is located off screen and I need to pull them in and place them on every tile that is generated.

    So what I have done is make a sprite for each tile and move the sprite family to a pin point on that tile. How ever it will grab all the tiles and place them on the last tile generated. I have tied to use pick instance random and it will do as I wish, well it will place one avatar on each tile somewhat. But unless i want to create a family variable for all the sprites It will not work efficiently when I scale this up.

    I have tried using the UID (TedSprite.UID) and placing them in the array so I can say that when running a loop in the array the avatar sprite is linked that particular row in the array

    What I really want is to have a generic avatar that will be created for each tile and then change the sprite img form a URL in my project files. So using the above example I will create 2 tiles in my menu. Each tile will have the generic avatar pinned along with a textbox. Then tile0 will change the avatar to Ted and the text box will update with Ted's stats. then the next tile in the menu will be Sue's again doing the same.

    So to answer you question no, I do not really need the family but what I need is to be able to sort the array and have it correspond to a sprite. As I write this the idea came to me that instead of using the UID of sprites or IID of the avatar family. I will look into just having the avatars in a folder in my project file and pull their img form there to replace a generic avatar. thus negating the need of a family. Worth a shot so give me some time and I will report back

    Though if anyone has a solution that I am over looking please post.

    Thanks,

    CrazyVulcan

  • Ok so if I understand you correct you have X amount of characters available, at some point during the game, the player can unlock these, and use them in later games if they wish. So when the player starts a new game you would like to load each unlocked character and show them in a selection menu, which is a tilemap?

    [quote:2pkn6525]As I write this the idea came to me that instead of using the UID of sprites or IID of the avatar family. I will look into just having the avatars in a folder in my project file and pull their img form there to replace a generic avatar. thus negating the need of a family. Worth a shot so give me some time and I will report back

    You don't have to pull the image from an url, if you use a tilemap it is much easier to store each character in the tilemap it self.

    So in Tile0 you make an image which might say "Unavailable" which you use for all characters that haven't been unlocked yet. As they get unlocked you simply switch a given tile to another tile. So if the player unlock character 1 you switch the tile (0,0) to tile1.

    If I understood you correct, you only need to store whether a character have been unlocked or not in a file, so you know this whenever the player starts your game. If you keep the family containing you characters you don't have to use an array to store there stats. These stats you make in the family and whenever a character is loaded you simply read these values from the family it self (The specific character sprite).

    So after you have started the game, and found out that character 1 and character 2 is available, you can make a function that get the stats for each character. If you also need it to be placed at a certain position, you can pass this as well, so:

    Requires:

    Parameter 0 = Character.UID

    Parameter 1 = Position

    Function "Load character stats"

    Sub event 1:

    Pick character1.UID = Function.Param(0) (Will only select character1 if the passed UID matches it, else it will just skip it)

    --------- If Function.Param(1) = 1 (Will place character 1 at position 1)

    Set textbox_CharacterName_1 = Character1.Name

    Set textbox_CharacterHealth_1 = Character1. Health

    Set Tile.At(0.0) to Tile1 (Assuming that this hold the image of character 1)

    --------- if Function.Param(1) = 2 (Will place character 1 at position 2)

    Set textbox_CharacterName_2 = Character1.Name

    Set textbox_CharacterHealth_2 = Character1. Health

    Set Tile.At(1.0) to Tile1 (Assuming that this hold the image of character 1)

    Sub event 2:

    Pick character2.UID = Function.Param(0) (Will only select character2 if the passed UID matches it, else it will just skip it)

    --------- If Function.Param(1) = 1 (Will place character 2 at position 1)

    Set textbox_CharacterName_1 = Character2.Name

    Set textbox_CharacterHealth_1 = Character2. Health

    Set Tile.At(0.0) to Tile2 (Assuming that this hold the image of character 2)

    --------- if Function.Param(1) = 2 (Will place character 2 at position 2)

    Set textbox_CharacterName_2 = Character2.Name

    Set textbox_CharacterHealth_2 = Character2. Health

    Set Tile.At(1.0) to Tile2 (Assuming that this hold the image of character 2)

    Then you just create one for each character and each position. And then you just call this function every time you need to load a character.

    Call function("Load character stats", <FamilyCharacter.UID or specific character UID>, <Position of where you would like the character to be loaded to>)

  • Ok so if I understand you correct you have X amount of characters available, at some point during the game, the player can unlock these, and use them in later games if they wish. So when the player starts a new game you would like to load each unlocked character and show them in a selection menu, which is a tilemap?

    Yes that is in fact what I am trying to achieve. I am however having trouble with the tilemap obj. When I load a sheet of sprites to it and set the cell size and position all I get is a empty sprite in my workspace. I can not figure out what is not working as no matter what image I load every sprite object I place in the level is blank. I have made sure that initial visibility is true and that the tiles are the right size and place. the manual does not really go into troubleshooting this.

    So after you have started the game, and found out that character 1 and character 2 is available, you can make a function that get the stats for each character. If you also need it to be placed at a certain position, you can pass this as well, so:

    Requires:

    Parameter 0 = Character.UID

    Parameter 1 = Position

    Function "Load character stats"

    Sub event 1:

    Pick character1.UID = Function.Param(0) (Will only select character1 if the passed UID matches it, else it will just skip it)

    --------- If Function.Param(1) = 1 (Will place character 1 at position 1)

    Set textbox_CharacterName_1 = Character1.Name

    Set textbox_CharacterHealth_1 = Character1. Health

    Set Tile.At(0.0) to Tile1 (Assuming that this hold the image of character 1)

    --------- if Function.Param(1) = 2 (Will place character 1 at position 2)

    Set textbox_CharacterName_2 = Character1.Name

    Set textbox_CharacterHealth_2 = Character1. Health

    Set Tile.At(1.0) to Tile1 (Assuming that this hold the image of character 1)

    Sub event 2:

    Pick character2.UID = Function.Param(0) (Will only select character2 if the passed UID matches it, else it will just skip it)

    --------- If Function.Param(1) = 1 (Will place character 2 at position 1)

    Set textbox_CharacterName_1 = Character2.Name

    Set textbox_CharacterHealth_1 = Character2. Health

    Set Tile.At(0.0) to Tile2 (Assuming that this hold the image of character 2)

    --------- if Function.Param(1) = 2 (Will place character 2 at position 2)

    Set textbox_CharacterName_2 = Character2.Name

    Set textbox_CharacterHealth_2 = Character2. Health

    Set Tile.At(1.0) to Tile2 (Assuming that this hold the image of character 2)

    Then you just create one for each character and each position. And then you just call this function every time you need to load a character.

    Call function("Load character stats", <FamilyCharacter.UID or specific character UID>, <Position of where you would like the character to be loaded to>)

    If I read your example correctly you are suggesting that I create a function for each character with which sprite to chose and all. However when I will scale this up that is a lot of data for the engine to chew though and I am looking for a way to automate this proses as it is just a menu and I can not budget too many resources to it.

    Which brings me back to using a array. With a array I can have one object that contains all the needed data for any character. That or using the CSV plugin. I want a way to have the program call the array and say OK rows 1,2,4,and6 are valad and row one is this character and column 2, 3 and 4 are attributes for this one person. So this tile that has just been created will be the sprite for person form row one column one. and there are three textbox on this tile that are pulled form row one column 2,3 and 4. Then repeat for a new tile for row 2 onward for each row that that contains "true" in the column for "unlocked"

    But I am completely lost for how to say for each row in column "unlocked" where CSV.at("unlocked",CSV.CurRow) = "True" and then match each row to a associated sprite and text box that are created dynamically for each row and then move on to the next row and repeat till there is one tile for each row in the array.

    The img is a screen of my current layout, showing the empty tile map and a idea of what I am trying to do for those who did not download the .cpax. the brown tile and black avatar is destroyed at the start and I am trying again to create each with the needed info one at a time when I click the blue bttn.

  • [quote:2q7muwr1]Yes that is in fact what I am trying to achieve. I am however having trouble with the tilemap obj. When I load a sheet of sprites to it and set the cell size and position all I get is a empty sprite in my workspace. I can not figure out what is not working as no matter what image I load every sprite object I place in the level is blank. I have made sure that initial visibility is true and that the tiles are the right size and place. the manual does not really go into troubleshooting this.

    I cant open your Capx as you are using some plugins that i don't. So i can only look at the images that you posted, so this might not be as useful. But from the last screen shot it seems like you might have misunderstood the tilemap object and how it works.

    The tilemap is an image/object that is able to tile images based on certain settings. So you can save resources when using the same graphic elements over and over again. This is done by choosing an area that the tilemap should cover, lets say 1000x1000, which would be the size of the tilemap object.

    In the tilemap you in theory can have as many graphical elements ("sprites") as you want, and you use these to fill the tilemap it self, in this case the 1000x1000 size tilemap. The amount of tiles you can have in the tilemap is based on the size of each individual tile. Which you set in the "Tile height" and "Tile width", so for simplicity lets say both of these are 10.

    That would mean that our tilemap can hold 100 tiles in X and 100 tiles in Y. And likewise if these were set to be 100, it could hold 10 in X and 10 in Y.

    Looking at your screenshot you have the tilemap size set to 74,106, which doesn't really make sense as this is a very small tilemap with weird dimensions. And looking at the "Tile width" and "Tile height" you have these at 100 and 150. Which are actually larger than the tilemap itself, and therefore its blank as it doesn't have room to place any tiles in. And i assume that you use these values as its the size of the character sprites?

    But as i said i can only see the screenshots so might not be true for your actual program.

    So i would suggest either redesigning the way you present the characters if you want to use a tilemap. Maybe make it so the whole screen is filled with characters and when the player clicks one it could open up the stats for that character or something.

    Like you see it in League of legends, if you know that:

    You can still keep the dimensions that you have, just a good idea is to make sure the size of the tilemap fits this, so if you want 10 character in X direction and 15 in Y direction, make the tilemap size 1000x2250.

    Otherwise i would redesign the way you choose character to not using a tilemap at all, but maybe just use 1 sprite and make some buttons to flip through them.

    [quote:2q7muwr1]If I read your example correctly you are suggesting that I create a function for each character with which sprite to chose and all. However when I will scale this up that is a lot of data for the engine to chew though and I am looking for a way to automate this proses as it is just a menu and I can not budget too many resources to it.

    This wont use any resources as its a function so it will only do something when you call it. Otherwise it will just be there doing nothing.

    Since you already have characters sprites for each character, you could use these to hold the data for them, like name, health etc. And instead of using an array, you simply load each available character when you need them. And when a character is unlocked you can save it to the disk/server if these are dynamically generated during the game.

    If these are characters that you create before hand i would probably just add them to the game it self, and just check whether they have been unlocked or not when you need to show them, or maybe make it so they are loaded from the server/disk instead when needed.

  • Hey, I probably won't be much help here but maybe I can push you toward some insight.

    As far as using the CSV plugin to grab a certain set of data like you said for "unlocked" characters. You may want to look at Guizmus's dialogue tutorial/capx files to see how he grabs data from the CSV depending if it is a "speech, random, or choice."

    https://www.scirra.com/tutorials/833/mod-side-story-a-walkthrough-of-a-text-dialog-mod

    While the system itself is broken (it hangs on the third piece of dialog forever and I can't figure out how to fix it) you may be able to discern something useful from it

  • Hey Centra i'm trying that tutorial you recommended ...but I can't find the csv file they are using... let me know if you happened to get pass that

  • OK, I am approaching this from a new angle. That being instead of having a array for each character I now have a Dictionary for each one.

    Each Dictionary has 7 values and having 3 Dictionary when I run the for each Key where adding 1 to a variable gives me 21. However now when I try to narrow down that list to only add 1 for each key that has the string "T" in it I should get 3. Instead It will not run the block and my debug var stays at 0. I have tried using compare values, in both the dictionary and system. As well as compare current value that is in the for each loop section.

    I am starting to feel that I may have a bug as everything I try that should work will not in the way I understand it.

    EDT<<

    Damn, I just opened a new empty project and only added what I absolutely needed to test it and it worked just great. Sooo that means to the best of my knowledge all my problems more likely than not are instances where C2 is bugged.

    PS How many dictionary's can I have and the game still function? Because I may need a lot.

    EDIT2<<

    And now making yet another new file I now can not do the exact same thing I just did in the last new file Ive noticed a *at the end of my project name on the right hand side. Does this mean anything?

  • OK, I am approaching this from a new angle. That being instead of having a array for each character I now have a Dictionary for each one.

    Each Dictionary has 7 values and having 3 Dictionary when I run the for each Key where adding 1 to a variable gives me 21. However now when I try to narrow down that list to only add 1 for each key that has the string "T" in it I should get 3. Instead It will not run the block and my debug var stays at 0. I have tried using compare values, in both the dictionary and system. As well as compare current value that is in the for each loop section.

    I am starting to feel that I may have a bug as everything I try that should work will not in the way I understand it.

    >>EDT<<

    Damn, I just opened a new empty project and only added what I absolutely needed to test it and it worked just great. Sooo that means to the best of my knowledge all my problems more likely than not are instances where C2 is bugged.

    PS How many dictionary's can I have and the game still function? Because I may need a lot.

    >>EDIT2<<

    And now making yet another new file I now can not do the exact same thing I just did in the last new file Ive noticed a *at the end of my project name on the right hand side. Does this mean anything?

    Its very difficult to see what you are doing on the screenshot. But something could seem like there are no "T's" in the dictionaries, have you checked that there actually is or do you assume that there are?

    I don't think there are any limits to how many dictionaries you can have in your project, so dictionary away

    The * on the right side next to the project name just means there are unsaved changes to the project.

  • nimos100 I really do appreciate you helping me but I really need someone to open the .CAPX to see if something is wrong on my end. The only plugin you would need is Rexrainbows CSVtoDictinary and all that I am trying to do is at the start of the layout add CSV's to five Dictionary's. Then when you right click run a foreachkey loop that is only looking for the value "T". Each Dictionary has 4 keys with values.

    the exact keys are

    "UNLOCK, T

    A, 1

    B, 2

    C, 3"

    With five dictionary's when I run a for each key loop I have a var add one for each key giving me a value of 20. But when I add a condition for only values with the string "T" I get 0 when I run the loop.

    I honestly can not think of any simpler way to show what I am trying to do without someone looking at the .cpax

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You have a space after the comma so you're getting key: "UNLOCK", value: " T".

  • I honestly can not think of any simpler way to show what I am trying to do without someone looking at the .cpax

    Think you misunderstood me, I weren't referring to what was in the screenshot it self, more that it was so small that its difficult to read the code as some of it is really blurry.

    But anyway I think Ramones solved it.

  • ramones thank you so very much, to think it was something so small. I will work on the next part of my problem and report back on my progress later. In fact I may go back to arrays given that now I know where in the issue lies.

    Thank you all for your help.

  • Hello, I am just posting back here having finally solved the list of things I needed to figure out. And now it works exactly as I wanted I will write a tutorial when I get the spare time but for now this is a list of what I did to get this to work.

    To start here are the items you need to bring into the view port. A go button and blank avatar. A tileset with all your characters on it and one clone plus how many slots you plan to make. I made 3 so that is 4 clones of a tile set. A menu box, a tile for your avatars to sit on and highlight the stats of each. A CSV, found in the extensions from RexRainbow. And some text items to show your stats.

    For the tile you will need to make it a container holding all the text items that go with each stat.

    CODE===

    //First we need to destroy the first tileset and the sprite backround for our tiles as the math we will be doing can be thrown if they are present after the layout is loaded.

    On start of layout

    Destroy Tileset

    & Destroy Tile

    & Load CSV Table form String}

    CSV String

    ",Name,Unlock,Strength,Speed,Mana

    0,Bob,T,0,0,0

    1,Tim,T,0,0,0

    2,Sue,T,0,0,0

    //etc for each tile in your tile set. be sure that you list each character in sequence and tile 0 tile 1 and tile 2 will not only correspond to each image but will allow you to link that image to the CSV table for easy access to your stats.

    //now we have the tile as a container for all out text items (also I have tied my tiles to the avatars so you can scroll through the list so know you can also do it the other way)

    Every Tick

    Tile - Set position to X: Tilemap.TileToPositionX(0) Y: Tilemap.TileToPositionY(0)

    TextName - Set Position to Tile Image Point (1)

    TextStrength- Set Position to Tile Image Point (2)

    }

    //you get it

    Global Var's

    Total - value of 0

    TileSelect - value -1

    ActiveSlot - value -1

    Mouse LeftClick Slot0{

    Set Var ActiveSlot to 0

    Call Function "Menu1"}

    //repeat for as many slots you will want

    Function on "Menu1"{

    Set background to position 500,100

    >>>

    CSV For Each Row

    &

    Compair CSV.At("Unlock",CSV.CurRow)="T"{

    Add 1 to Total

    Create Obj Tilemap on Layer(1) At X: Background.ImagePointX(0) Y: Background.ImagePointY(0)+(150*Total)-150

    //This will add one to every run of the loop spacing out the placement of each avatar and tile

    Set Tilemap - to int(CSV.CurRow)

    Creat Obj - Tile on Layer(1) X: Tilemap.TileToPosition(0) Y: TileToPosition(0)+(150*Total)-150

    TextName - Set Text CSV.At("Name", CSV.CurRow)

    ValuStrength - Set Text to CSV.At("Strength", CSV.CurRow)

    //and so on

    Tile - Move to bottom of layer

    Background Move to Bottom of layer}

    }

    Mouse - LeftClick on Tilemap

    &

    ActiveSlot = 1{

    Set TileSelect to{ X: Tilemap.TileAt(Tilemap.PositionToTileX(Mouse.X)) Y: Tilemap.TileAt(Tilemap.PositionToTileY(Mouse.Y)}

    //let me go over this one real quick. Tile select is a Var that is used to note which image I click on. So looking back at the CSV, and note that each row is numbered. So by clicking on Sue the var TileSelect will be set to 2 and later you will see that by having row 2 and Sue's image on the tile map the same this allows me to quickly know where my data is coming from.

    Set Tileset to (TileSelect)

    //then set the text items next to slot one to each stat

    Set ActiveSlot to -1

    Destroy Obj Tile

    Set Total to 0

    CallFunction "Destroy Tiles"

    On Fun "DestroyTiles"

    Destroy Obj Tilemap

    Move Backround to -100,0

    //this function is there because when I have it in the other block it will only destroy the tile that I selected. This allows me to get rid of all of them.

    Repeat the last block for each slot that you have. This is all there is to it and I am happy that I managed to do this all with 13 blocks and 3 variables

    .CAPX needs CSV by RexRainbow to open

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