Sharing Variables Between Screens and Functions

tutorial
beginner

#1

X has the ability to pass variables between screens. (Classic does not)

To do this setup an application with two screens. Screen1 and Screen 2.

In Designer:

On Screen1, place a label and a button. Set the text of the button to Go To Screen2

image

On Screen2, place a label and a button; Set the text of the button to Get Screen1 Text.

image

Blocks

Screen1

Set your variable. I entered basic text saying Nothing Entered so we know what state the variable is in when it is presented.

You will see here that we set the variable to what was entered in the text box once the Button is clicked. we then move to Screen2.

Screen2

Here we show a few more concepts.

  1. You see the variable from screen one is passed once we click the button. But we are calling a function.

A function allows us to group certain tasks together, and we can send information when we call a function for it to perform. Here we have said:

"When the button on Screen2 is clicked, please call the function named whatWasSaid and send the “Current Day of the Week” as the Extra Stuff information.

When the whatWasSaid function is called it takes the “Extra Stuff” (being the day of the week) and adds it to the variable from Screen1 (using the Join component)

To be able to add the Extra Stuff to a Function, use the little gear.

image

Drag the Input Name

image

Then rename the X by click and typing what you want. I put Extra Stuff

==================
Cross Screen Variables, and a Function all at once.

Here is the project to play with.

https://x.thunkable.com/copy/5394993b9f0848b721d8b464f83fd39a


#2

Thanks for sharing Cian!