Newbie asks about scrolling

Hey there! I’m new to Corona and programming in general, but this system seemed like a good way to start.

I had a game in mind that you’re supposed to be playing with friends, when you’re together. I was inspired by a i role-playing card game where a few players are the werewolves, and they need to eliminate all civilians.

I wanted to make a mobile version of this game (story-based instead of turn-based, unlike the werewolf game).

However, I have run through the whole guide without getting answered the following questions;

  • How can I let the player add some input? I want people to fill in their names, so that the game uses their names in the story.
  • I want to give the players jobs. This gave me the question whether variables (starting with local) stay local in just the file, or that they also work in other files as long as the scene stays active.
  • How do I make scrolling text (including buttons, boxes and images)? I tried to look some stuff up, but I couldn’t find a real clear tutorial.

Hopefully these questions are clear and not asked too frequently. I hope I could get some feedback.

This post has been reuploaded. It was not certain if the other one came through.

Hi and welcome to Corona SDK!
Answers to your questions:

-You could ask the names in the beginning and store them in variables. That way, you can just add concatenate the text with the variables!

-Local variables only exist in their scope. So they would not be accessible inside another scene. But you can pass params in the “composer.gotoScene()” command to kind of copy those variables into the new scene.

-Srolling text, images etc… Can be made with the scrollview widget!

I hope this helps you :slight_smile:

Thanks for the answers! :D  I like the gotoScene() idea, although I’m not sure how it would work with multiple variables… I read something about making a “global” variable file, but I can’t get it quite to work (even if I literally copy-paste what it says),

I know how to add their names into the text, it’s just that I don’t know how to let a player fill in an input. How do I create a text bar where they can type their name (which will be stored in a String)?

I tried to look up how widgets work, but I can’t get my hands on them. Do I need to download extra files in order to make coding easier? Or does the game automatically load them from the Internet?

The thing is, global variables are seen as a “bad thin” to do. You could make a variable global by simply leaving “local” infront of the variable name! I also like to declare my global variables at the top scope oofy scene :slight_smile:
But before you jump right into using them, try reading this: https://coronalabs.com/blog/2014/10/14/tutorial-saving-and-loading-lua-tables-with-json/
Scroll down to “Table load/save functions”, this is a method to save local variables and call them even beyond different runtimes!

You can ask for userinput by using a textfield for example. You can make a textfield by calling “native.newTextField”, you can find more information about it here: https://docs.coronalabs.com/api/library/native/newTextField.html

You don’t need to download any additional files for widgets. You simply have tl require them. You can do that by calling: local widget = require(“widget”). Now you can simply call: widget.newScrollView()
Ofcourse you’ll have to pass in some arguments, check this link to find out more about that: https://docs.coronalabs.com/api/library/widget/newScrollView.html

I hope this helped! :slight_smile:

There’s nothing wrong with global variables as long as they’re used in a controlled manner.

--globals.lua-- local g = {} g.firstName = "Tony" g.lastName = "Harris" g.age = 36 g.job = "Dentist" return g --other scenes-- local glo = require("globals") glo.age = glo.age + 1 print (glo.firstName.." "..glo.lastName.." - "..glo.job.." ("..glo.age..")"

You can access the ‘glo’ table from any scene where you ‘require’ globals.lua. Any values you update or add will persist in other scenes.

Hi and welcome to Corona SDK!
Answers to your questions:

-You could ask the names in the beginning and store them in variables. That way, you can just add concatenate the text with the variables!

-Local variables only exist in their scope. So they would not be accessible inside another scene. But you can pass params in the “composer.gotoScene()” command to kind of copy those variables into the new scene.

-Srolling text, images etc… Can be made with the scrollview widget!

I hope this helps you :slight_smile:

Thanks for the answers! :D  I like the gotoScene() idea, although I’m not sure how it would work with multiple variables… I read something about making a “global” variable file, but I can’t get it quite to work (even if I literally copy-paste what it says),

I know how to add their names into the text, it’s just that I don’t know how to let a player fill in an input. How do I create a text bar where they can type their name (which will be stored in a String)?

I tried to look up how widgets work, but I can’t get my hands on them. Do I need to download extra files in order to make coding easier? Or does the game automatically load them from the Internet?

The thing is, global variables are seen as a “bad thin” to do. You could make a variable global by simply leaving “local” infront of the variable name! I also like to declare my global variables at the top scope oofy scene :slight_smile:
But before you jump right into using them, try reading this: https://coronalabs.com/blog/2014/10/14/tutorial-saving-and-loading-lua-tables-with-json/
Scroll down to “Table load/save functions”, this is a method to save local variables and call them even beyond different runtimes!

You can ask for userinput by using a textfield for example. You can make a textfield by calling “native.newTextField”, you can find more information about it here: https://docs.coronalabs.com/api/library/native/newTextField.html

You don’t need to download any additional files for widgets. You simply have tl require them. You can do that by calling: local widget = require(“widget”). Now you can simply call: widget.newScrollView()
Ofcourse you’ll have to pass in some arguments, check this link to find out more about that: https://docs.coronalabs.com/api/library/widget/newScrollView.html

I hope this helped! :slight_smile:

There’s nothing wrong with global variables as long as they’re used in a controlled manner.

--globals.lua-- local g = {} g.firstName = "Tony" g.lastName = "Harris" g.age = 36 g.job = "Dentist" return g --other scenes-- local glo = require("globals") glo.age = glo.age + 1 print (glo.firstName.." "..glo.lastName.." - "..glo.job.." ("..glo.age..")"

You can access the ‘glo’ table from any scene where you ‘require’ globals.lua. Any values you update or add will persist in other scenes.