How do I clone text for family objects

0 favourites
  • 10 posts
From the Asset Store
OpenAI TTS
$9 USD
10% off
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • 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!

  • 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.

  • I don't know if I interpreted correctly your question, but here it's:

    https://dl.dropboxusercontent.com/u/47035927/Samples/text%20for%20object.capx

  • 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.

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

    I hate functions, so, you'll need to deal with it, ha! <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy">

    https://dl.dropboxusercontent.com/u/470 ... 0text.capx

  • 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.

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

    Method 1:

    Method 2:

    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!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It is important for the project that you learn to use instances.

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

  • 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.

    [quote:2cmi7vqd]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.

    [quote:2cmi7vqd]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.

    https://dl.dropboxusercontent.com/u/470 ... %20it.capx

  • 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!

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