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

Get help using Construct 2

Post » Fri Sep 19, 2014 11:44 pm

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
You do not have the required permissions to view the files attached to this post.
Last edited by CrazyVulcan on Tue Nov 04, 2014 2:24 am, edited 2 times in total.
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

Post » Sat Sep 20, 2014 8:57 am

Im not really sure what you are trying to do.

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?
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sat Sep 20, 2014 11:39 pm

nimos100 wrote:Im not really sure what you are trying to do.

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
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

Post » Sun Sep 21, 2014 9:47 am

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?

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>)
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Thu Sep 25, 2014 9:00 pm

nimos100 wrote: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.

nimos100 wrote: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.
You do not have the required permissions to view the files attached to this post.
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

Post » Fri Sep 26, 2014 10:22 am

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

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.

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.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Sat Sep 27, 2014 8:50 pm

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
B
10
S
2
Posts: 80
Reputation: 995

Post » Tue Sep 30, 2014 2:29 am

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
B
16
S
5
Posts: 28
Reputation: 1,256

Post » Fri Oct 10, 2014 5:48 am

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 :x Ive noticed a *at the end of my project name on the right hand side. Does this mean anything?
You do not have the required permissions to view the files attached to this post.
"Were all mad here. I'm mad, your mad." "How do you know I'm mad?" Asked Alice. "You must be" Said the Cheshire Cat. "Or you wouldn't have come here"-Lewis Carroll: Adventures In Wonderland
B
7
S
2
Posts: 113
Reputation: 1,245

Post » Fri Oct 10, 2014 2:54 pm

CrazyVulcan wrote: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 :x 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 :D

The * on the right side next to the project name just means there are unsaved changes to the project.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Next

Return to How do I....?

Who is online

Users browsing this forum: richardfu and 28 guests