[Solved]How do I - Set individual text per object?

Get help using Construct 2

Post » Wed Jul 15, 2015 12:53 am

On start of layout, I spawn text for each object

How do I, for each object, set the text individually?

I can't seem to find anything relating to "for each unique IID".


Is this something where I would need to use an array, loop, or a function? (I'm not too keen on either one of those, so I assume that might be where my problem lies)
Last edited by SwatHound on Wed Jul 15, 2015 7:24 am, edited 1 time in total.
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Wed Jul 15, 2015 2:04 am

I don't know if this is the best way to solve it, but it was how I manage to pull this off.

Every time you are going to change the text, check if it's overlapping the object it's related to. This will select the text instance that is related to this particular object.

Hope it helps o/
B
17
S
7
Posts: 277
Reputation: 2,514

Post » Wed Jul 15, 2015 5:01 am

Thanks RayKi!

I'll try that. I hope I can figure out how to make it spawn each units variable.
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Wed Jul 15, 2015 5:58 am

Another way would be designating each instance of the text object with an instance variable set as a string, with it's value containing the text to be spoken, then you can have a blanket event essentially saying "let all 'text.objects' text = instance variable:'text'".

Then you can use the "pick nth instance" (I think that's what's used) and change the variables themselves to change each individual instance's text.

Hopefully that helps some, good luck SwatHound. :)

Regards,
Gideon.

Also, can I just say @RayKi , massive respect for the Scott Pilgrim avatar man, thumbs up for awesome taste. :D
B
10
S
1
Posts: 72
Reputation: 1,015

Post » Wed Jul 15, 2015 7:23 am

You lost me, @GideonG D:

'with an instance variable set as a string' ....

Uhm.. Haha whats a string xD. Looked it up, found no definition for solely string, just a lot of other definitions using it!

Edit: Nevermind, found it under expressions, was looking under system expressions -

'Text is also known as strings in programming, and Construct 2 also sometimes uses this naming convention.
Text in expressions should be surrounded by double-quotes, e.g. "Hello" '

Anyway uhh. Thanks guys, I was kind of dumb and hastey. - All I had to do was add another condition to pick the nearest sprite. (Thanks @RayKi, I couldn't find "if overlapping object" so used this instead, thanks for the idea)

--System - On start of layout
>Sprite - Spawn text on layer x imagepoint y
-- Sub event -- System for each sprite --
---------------------text - pick nearest to (sprite.x, sprite.y)

---Action----
----Set text to sprite.units


I still wish I could understand what you were trying to suggest Gideon D: - reading these things are hard, I think I'm more of a visual learner (images and videos, not so much text) Heehee probably why I failed math twice ;) -- thanks again for the help guys
B
6
S
2
Posts: 60
Reputation: 1,242

Post » Wed Jul 15, 2015 8:34 am

OH! Don't stress man, that's totally my bad on that one, it's listed as 'text' in C2, 'string' is more of a code term than C2 properties. I'm glad you found a solution! :D

If you're interested, this is what I meant - variable type can be set to text, which you can use to store data (like something to say) unique to each instance of an object.
Image

Also, don't worry about no understanding everything people offer as advice, everyone has to start somewhere and as a fellow beginner, I've found the community here is more than happy to try and explain stuff if you need it. In no time you'll be following along with more complex stuff before you even realise you've picked anything up.

Hope all goes well with your game. :)

Regards,
Gideon
B
10
S
1
Posts: 72
Reputation: 1,015


Return to How do I....?

Who is online

Users browsing this forum: David181 and 19 guests