How do I get text objects to display simple variables?

Get help using Construct 2

Post » Thu Oct 15, 2015 1:23 am

Im very new to coding and construct 2 so i apologize in advanced for the noob questions. First off My game start screen I want to have the player be able to type in a text box their name. Save it as a global variable and be able to display their chosen name later on in the main game screen. Then the rest of the game will be using very similar concepts. Their will be a lot of stats saved as global variables and displayed, changing often and staying updated. Ive created the global variables but am a little lost on how to get the text objects to display the variables value and also retrieving the input-ed text from the text box and using the players input-ed value as the new value of a global variable.
Image
B
34
S
13
G
3
Posts: 46
Reputation: 3,907

Post » Thu Oct 15, 2015 1:33 am

Hey Nico,

So for a 'text box' object. If you have clicked it and input some text, You can then save it to a global variable (make sure it is a text variable not a number) by just adding an event (or a button) that records the full text.

Looks like this:

On Enter Pressed -> Set GlobalVariable to TextBox.Text.

--------------

Later when you want to show that variable in a 'text object' it looks like this:

On condition met (any condition you like) -> TextObject - set text to : GlobalVariable
ImageImage
B
112
S
23
G
7
Posts: 1,064
Reputation: 12,787

Post » Thu Oct 15, 2015 1:58 am

Ive done the first part successfully but the second part when i click set to: I select the variable and it asks for a value. I don't want to reset the value of the variable. I want to display the value.
Image
B
34
S
13
G
3
Posts: 46
Reputation: 3,907

Post » Thu Oct 15, 2015 2:14 am

Image
Image
B
63
S
23
G
7
Posts: 1,480
Reputation: 10,796

Post » Thu Oct 15, 2015 4:23 am

Thanks guys! I have an other question. I would like to create a random number. I want a text object to display a random number within the parameters I set. So I would say like 1-100 and have it display within that brackets. Any advise?

Also do text object have on click event? I want text to be able to be clicked on like buttons.
Image
B
34
S
13
G
3
Posts: 46
Reputation: 3,907

Post » Thu Oct 15, 2015 7:51 am

Any advise?

Check the manual/tutorials for information about random. but as a starting point try floor(Random(1,101))

Yes
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
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Thu Oct 15, 2015 9:44 am

Nicotine if you are new to C2 you will find lots of tutorials here

https://www.dropbox.com/sh/eioscti86bpr ... 7YPza?dl=0
B
245
S
37
G
15
Posts: 1,941
Reputation: 40,096

Post » Tue Jan 24, 2017 10:29 am

I'm finding that when I set a textbox to a global variable it makes it blank. Whipes all text.
The textbox type is Number.

set text was placed in a load of code. So i brought it out, set it to every tick to test, and it now cannot be set to 1, confirming that it is setting to blank.

How do I get the textbox to a global variable please. I want the box to remember last inputted number when recreated.
- Head of Tall Story Studios.

Creator of GOV, Project Abyss, Spiritlands & more!
B
27
S
12
G
1
Posts: 127
Reputation: 3,060


Return to How do I....?

Who is online

Users browsing this forum: Apollo14, ivanski1983, KTML5, Yahoo [Bot] and 3 guests