How do I get text objects to display simple variables?

0 favourites
  • 8 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
  • 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.

  • 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

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

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

  • Any advise?

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

    Yes

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Nicotine if you are new to C2 you will find lots of tutorials here

    https://www.dropbox.com/sh/eioscti86bpr ... 7YPza?dl=0

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

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