How do I clone text for family objects

Get help using Construct 2

Post » Thu Dec 22, 2016 10:52 pm

I've run across a problem that I've developed a brute force solution to, but have to believe there is a simpler way. While my project is too convoluted at this point to post, the basic concepts can be easily described and recreated...

Step 1) Create 2 sprite objects.
Step 2) Add them to a Family called Characters
Step 3) Give Characters a number of Instance Variables (Type, Name, Armor, Weapon, Shield, Strength, Dexterity, so on...)
Step 4) Assign different values to each object, for example: Obj1.Type = "Player", Obj2.Type = "Enemy", Obj1.Name = "Doug the Invincible Conqueror" Obj2.Name = "Misfit Toy", etc.
Step 5) Create a text object for each Instance Variable in Characters. (Example: txtType, txtName, txtArmor, etc.)

The challenge is then displaying BOTH the player instance variables AND the Enemy instance variables at the same time without having to recreate individual text objects for each type, which is the brute force method I've got working now. In other words, rather than txtType, txtName, txtArmor, etc., I have txtPlayerType, txtPlayerName, txtPlayerArmor,... AND txtEnemyType, txtEnemyName, txtEnemyArmor,...

What I would like to do, but haven't found a way, is to have some routine which uses instances of the text objects themselves...
1) Checks the Character.Type.
2) IF "Player", use txtType(0), txtName(0), txtArmor(0), etc.
3) ELSE, use txtType(1), txtName(1), txtArmor(1), etc.

Obviously, with a lot of Character variables to display for each object, the brute force method creates long and tedious code. But I can't seem to tell the engine to use Instance 0 for all text objects if Character.Type = "Player", otherwise use Instance 1 for all text objects.

Any ideas would be appreciated!
B
6
S
1
Posts: 6
Reputation: 329

Post » Fri Dec 23, 2016 3:49 pm

Hey Treeves,

It's late here so it might be me but I'm not sure exactly what you are after. Do you want to use one text box instead of many little ones? If so you can still display all the variables you want by doing it like this :

"Type" & familyobject.Type & "Name" & familyobject.name & "Armour" & familyobject.armour & etc etc

If you wanted this to only display for your player then you would have a condition that said 'Familyobject.Type=Player' (which picks your family object to be used for the text).

If you can post a small example of how you have it set up i'll show you how if you like.
ImageImage
B
118
S
23
G
7
Posts: 1,070
Reputation: 12,964

Post » Fri Dec 23, 2016 4:23 pm

I don't know if I interpreted correctly your question, but here it's:
Image
https://dl.dropboxusercontent.com/u/47035927/Samples/text%20for%20object.capx
Image
B
106
S
23
G
17
Posts: 1,355
Reputation: 22,133

Post » Fri Dec 23, 2016 5:49 pm

Thank you both for your comments, but it's not quite what I'm after. I've put together a quick .capx to demonstrate the issue...

https://www.dropbox.com/s/s4mucsgtjlil5 ... .capx?dl=0

The first layout demonstrates one method, and the second layout demonstrates another method. Both work, but seem cumbersome. While there are only three text labels each, it's not a big deal and either method can populate the information. But if there are a lot of text objects per sprite (along with multiple player objects, enemy objects, NPC objects, etc.), then the coding to specify each text field becomes highly tedious.

Perhaps there is no better way to populate similar data in similar text objects, but I just keep thinking there has got to be a cleaner method that I'm missing.
B
6
S
1
Posts: 6
Reputation: 329

Post » Fri Dec 23, 2016 6:44 pm

It's exactly what I did in a clean and elegant way =]

I hate functions, so, you'll need to deal with it, ha! :D

Image
Image

https://dl.dropboxusercontent.com/u/470 ... 0text.capx
Image
B
106
S
23
G
17
Posts: 1,355
Reputation: 22,133

Post » Fri Dec 23, 2016 7:42 pm

I do understand you can combine the information in this example simply in one text field, however there is a reason why I need to have the text information in separate fields. I posted this as a quick example only. In the actual project, there are multiple icons interspersed and aligned with the individual text fields, so just dumping everything together isn't what I'm looking for. But again, thank you for your suggestion, it just doesn't quite address what I'm trying to accomplish.
B
6
S
1
Posts: 6
Reputation: 329

Post » Fri Dec 23, 2016 8:04 pm

For those who do not wish to download the example .capx, here is the layout and code...

Image

Method 1:
Image

Method 2:
Image

Again, it's important for the project to find a method that does NOT try to combine multiple data fields into one text field. Thank you!
B
6
S
1
Posts: 6
Reputation: 329

Post » Fri Dec 23, 2016 11:01 pm

It is important for the project that you learn to use instances.

https://www.dropbox.com/s/5fqmts3tkqaw6 ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Dec 23, 2016 11:11 pm

Show us a screenshot of you project and what you're trying to accomplish, without the code, just the visual of the game. Maybe it's simpler than you're saying and we are misunderstanding you.

If the game is not ready yet, make a mokup with all the items, texts, icons, etc, a complete example of the screen will give us a better idea than wall of texts.

The challenge is then displaying BOTH the player instance variables AND the Enemy instance variables at the same time without having to recreate individual text objects for each type, which is the brute force method I've got working now. In other words, rather than txtType, txtName, txtArmor, etc., I have txtPlayerType, txtPlayerName, txtPlayerArmor,... AND txtEnemyType, txtEnemyName, txtEnemyArmor,...

Manipulate and find instance variables are very simple, in all the samples it was made with a single condition, also, updating texts instead of creating them.

What I would like to do, but haven't found a way, is to have some routine which uses instances of the text objects themselves...
1) Checks the Character.Type.
2) IF "Player", use txtType(0), txtName(0), txtArmor(0), etc.
3) ELSE, use txtType(1), txtName(1), txtArmor(1), etc.

In the second example, I filtered the object and set the text without the need of setting anything, even a name for the text object, but if you want manipulate an existent text by searching an instance variable, it's even simpler.
In the screen bellow we have 3 objects with their static texts, an instance variable in each one to make us able to find who is who and fill them.

Image
Image
Image

https://dl.dropboxusercontent.com/u/470 ... %20it.capx
Image
B
106
S
23
G
17
Posts: 1,355
Reputation: 22,133

Post » Sat Dec 24, 2016 2:48 am

YES! Thank you 99Instances2Go and TELLES0808! You both nailed exactly the kind of thing I was after in somewhat different ways! I knew there had to be a more elegant method, but I'm still very new to Construct 2, so you both helped a lot! Happy Holidays!
B
6
S
1
Posts: 6
Reputation: 329


Return to How do I....?

Who is online

Users browsing this forum: R0J0hound, StillSarah and 30 guests