How to add player name in action script 3 - android

i want to make a game that
when some one write his/her name in a text input it shows in next frame:"Welcome(player name)to the game
What should i do now?
Help me please as much as u can.
Thank U.

Store it in SharedPreference and use it wherever you want to use it.
take a look at this :
http://developer.android.com/reference/android/content/SharedPreferences.html
Simple example code :
//save player name
SharedPreferences sharedpreferences = getSharedPreferences("MyPREFERENCES", Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();
editor.putString("name", "player name");
editor.commit();
//fetch name
sharedpreferences.getString("name","defaultName");

Related

How can I save data from an EditText component so it shows up when the app is reopened?

I am using Android Studio and programming in Kotlin. I haven't been able to find a way to save the data entered by the user so it appears when they reopen the app. Thank you ahead of time!
You have to store your data in shared preference when any click event listen or on edittext textwatcher you can set your character in preference but best way is on any click event save data on preference and when activity open set data from preference on edittext.
Store it in Shared Preferences
SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
use this save the value..
Editor editor = sharedpreferences.edit();
editor.putString("key_name", "value"); //here give name and value to save
editor.commit();
use this to get the value.
String edittextvalue = pref.getString("key_name", null); //put edittextvalue where ever you what to show the value.
use this step to remove or clear the value
editor.remove("name");
editor.commit();

How do I save the progress already made in an app?

I'm doing a quiz where the user unlocked the levels, but when he closes the app all progress is lost, and he has to redo everything again. How can I fix this and make the user's progress automatically saved? Or with it by clicking a button, I do not know
You can save it in SharedPreferences and check the value of it every time application is opened.
To save value:
SharedPreferences sp = getSharedPreferences("YourFileName", Context.MODE_PRIVATE); //YourFileName= Any file name you give it
SharedPreferences.Editor editor = sp.edit();
editor.putString("levels", your_level_value); //levels=key at which data is stored, your_level_value=No. of levels completed
editor.apply();
To retrieve value:
SharedPreferences sp = getSharedPreferences("YourFileName", Context.MODE_PRIVATE); //YourFileName= Any file name you give it
String levelCompleted = sp.getString("levels", "0"); //levels=key at which no. of levels is saved.

Android save EditText text

I have a school planer app and I want to save the classes that are written in an EditText object. The problem is, the EditTexts are empty when I close the app and then open it again, and even when I press back. This may be a noob question, but I'm a beginner and I need help. Please answer quickly...
for saving edittext text you need to store the text into storage.
android support storage like
Database
Shared Preferences
For your problem you need to store your Edittext text into the storage when you change value.
And when you open it again you need to retrieve from the storage.
For you best option will be shared preferences. For more Go with This Example . This will make you understand save and retrieve shared preferences.
Short Example
Store Data
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
editor = pref.edit();
editor.putString("first_edittext", "value");
editor.commit();
Retrieve Data
SharedPreferences pref = PreferenceManager
.getDefaultSharedPreferences(getBaseContext());
pref.getString("first_edittext", "");

Shared Preferences saving an int?

I saw this on stack Need to save a high score for an Android game
This is what it told me
//setting preferences
SharedPreferences prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
Editor editor = prefs.edit();
editor.putInt("key", score);
editor.commit();
//getting preferences
SharedPreferences prefs = this.getSharedPreferences("myPrefsKey", Context.MODE_PRIVATE);
int score = prefs.getInt("key", 0); //0 is the default value
I was wondering, should "key" be the string where the highscore is located? and does it matter what i name my prefs key.
Thanks for your time.
The Android Developers documentation is an excellent place to start with any question like this. SharedPreferences can be found here. SharedPreferences is a simple Key-Value pair storage, so if you put an int into your shared preferences as with the key "high score", then in the future, if you want to get that int, you need to use prefs.getInt("high score"). It doesn't matter what you name your keys, but it is generally good practice to use private static final string variables to store keys you will use on a regular basis.
You can name the string whatever you like. Click here for documentation. You can name it anything from "foo" to "bar".

How to retrieve name from Edittext for further manipulation?

i have almost completed my game and now i wish to do something with the scores and name so i want to have a high score list...
The problem is that i cannot retrieve the name when i m trying to draw the name using alphabet bitmaps what i have preprared!!!
now the problem occurs when i m tryin to use the getSharedpreferences and m not able to copy the name anywhere in the whole project so that when in the activity of showing the high score i can draw it!!!
is there a simple way to do it please suggest!!!!
thank you!!!
The best way to store a value which will be available all around your application is, as you said, the SharedPreferences.
To store your name user you can do this:
SharedPreferences mPrefs = getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("username", "your name");
editor.commit();
To retrieve your username you can do this:
SharedPreferences mPrefs = getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);
String username = mPrefs.getString("username", "");

Categories

Resources