[solved] How do I place text automatically?

Get help using Construct 2

Post » Thu Oct 22, 2015 1:47 am

For example in this game 'simple idle game' in the arcade, which I cannot post a link to for lack of repuation, each object has three numbers neatly paced by each of the objects.

Either the writer painstakingly placed a number of text boxes or he had some automatic method where the code made them. I had a search but couldn't find anything that didn't reference just changing the contents of a manually placed text box.

So how did the programmer do that? Thanks! :)
Last edited by Callan S on Sat Oct 24, 2015 9:07 pm, edited 1 time in total.
B
51
S
14
G
4
Posts: 191
Reputation: 5,537

Post » Thu Oct 22, 2015 2:35 am

Hey Callan,

Have you tried the create object? it will let you pick the spot to spawn it...

You can pair that with cords for where you want to spawn it. (If you need a example just ask.)
Justin
Eat ALL THE BACON!
B
47
S
17
G
3
Posts: 290
Reputation: 5,068

Post » Thu Oct 22, 2015 6:14 am

Hi antares,

But how do we distinguish each text box from one another? If an object spawns two text boxes, how do we make one contain X and one contain Y, when they are both 'text box'?
B
51
S
14
G
4
Posts: 191
Reputation: 5,537

Post » Thu Oct 22, 2015 8:19 am

Many ways to do this..
If you can see the difference between one instance and the other, you are able to tell the computer which one you mean..

I usually give the text-object an instance variable "function" on creation and set the variable to whatever the function is: "highscore" "time" etcetera..

Sometimes it's easier to have an object in a container, so it is automatically picked when picking the other object..
Other times you might want to change the contents based on where the text-object is on the layout..

Picking the right instance consists of knowing which instance you mean and making that known to the computer in the event..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Thu Oct 22, 2015 8:32 am

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,882

Post » Thu Oct 22, 2015 2:05 pm

This is the easiest way I found when working on my project...
Let's say you have a item you want text over, and be able to change it...

Give your other item a instance variable of Text_UID (or something similar)

Then create your Text object.
Then set your other item's instance variable to that text object's UID.

That way, when you want to change it, just find that text, with "Pick by Unique ID" (it will be the UID in the instance variable)


Sorry, this seems kinda complicated... I might make a video next week, explaining this...
Eat ALL THE BACON!
B
47
S
17
G
3
Posts: 290
Reputation: 5,068

Post » Thu Oct 22, 2015 11:14 pm

I don't understand why some engines have to make this stuff hidden away - stencyl was like this too.

In game maker you could just do 'worker=instance_create(x,y,object);'

And worker would equal the objects ID.

Then you could just do 'worker.x=400;' to change the value x or whatever value inside the object. Really easy.

Why other game engines have to make it really hard to do the same thing, I do not know?


RamPack - what happens if any instances are created that aren't recorded in that global (say instances which you don't want to manipulate)? It'd seem the system wouldn't work if any instances get created but aren't tracked?
B
51
S
14
G
4
Posts: 191
Reputation: 5,537

Post » Fri Oct 23, 2015 8:14 am

Instead of using a global variable you could just give the text boxes the UID of the "lamp" that is creating them - my example was to try to show the idea of tieing /grouping several objects together using instance variables.

As @Littlestain said there are many ways of doing this including the built in container (not sure if containers are in the free version of construct ?)
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,882

Post » Fri Oct 23, 2015 8:30 am

here you go an updated capx using containers.

https://goo.gl/XaQv7C
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,882

Post » Sat Oct 24, 2015 9:07 pm

Thanks, @RamPackWobble!

Containers are in the free version and I added a container to a practice object, put a text object inside it and in a simplified form copied parts of your code and managed to get it to work - two objects using a text box, but with a random number sent to their text boxes, and they showed different numbers than each other as they should.

I'd still really like to just be able to have one object directly manipulate the variables of an object. But this solves my initial problem!
B
51
S
14
G
4
Posts: 191
Reputation: 5,537


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo and 39 guests