how can implement game setting in my game?

problem solve with settings…tnx all…,

last problem is.

global score… gudlak to me…
i dont have idea… 

If you Google “corona save game settings” you get several answers, including Rob’s tutorial.

Regarding having “global” like data that persists between modules see:  http://www.coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

Regarding working with scores: http://www.coronalabs.com/blog/2013/12/10/tutorial-displayingsavingloading-scores/

Rob

Hi juario_soul,

I think this tutorial can be adapted to your needs:

http://www.coronalabs.com/blog/2013/12/10/tutorial-displayingsavingloading-scores/

Brent

sir Brent… not game score…

what i need is game setting…
like how to on/off sound and background music…
 

using checkbox…

Hi,

What I used in a app I was playing was sqlite to store the settings and then set event listeners to checkboxes to update the settings.

Here is a tutorial about sqlite:

http://developer.coronalabs.com/content/data-storage

Then under the settings screen I have a check boxes that asks the user if he should use vosotros or not (a conjugation used in Spain but not Latin America):

local useVosotros = widget.newSwitch { left = 0, top = 82, -- 50 + 32 \* counter style = "checkbox", id = "vosotros", onPress = onSwitchPress, initialSwitchState = b } useVosotros.text = display.newText( "Use vosotros?", 40, 82, native.systemFontBold, 18

The event listener looks like this:

local function onSwitchPress( event ) sqlite.switchSettingState(event.target.id) end

And in the sqlite.switchSettingState I reverse it:

function sqlite.switchSettingState(value) local statement = "" if value == "vosotros" then if sqlite.returnUseVosotros() == 1 then statement = "UPDATE settings SET useVosotros = 0" else statement = "UPDATE settings SET useVosotros = 1" end end

It’s probably bad coding to return the vosotros value in the sqlite.switchSettingState, I should probably change it so sqlite.switchSettingState accepts the value (1/0, true/false) as a parameter instead and updated the value accordingly however I think this might help you get things started.

Best regards,

Tomas

Sir Tomas…  when i uncheck the check box?

where’s the condition to cancel or off the music?

Hi,

Read this documentation:

http://docs.coronalabs.com/api/library/widget/newSwitch.html

So for example if you’re planning on using a Checkbox use this code:

local widget = require( "widget" ) -- Handle press events for the checkbox local function onSwitchPress( event ) local switch = event.target print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) ) end -- Create the widget local checkboxButton = widget.newSwitch { left = 250, top = 200, style = "checkbox", id = "Checkbox", onPress = onSwitchPress }

So when the checkbox is pressed the event listener will be called and you need to do some changes in that listener.

local function onSwitchPress( event ) local switch = event.target if switch.isOn == true then -- Start music here elseif switch.isOn == false then -- Stop music here end end

Best regards,

Tomas

I save all my settings in a Lua table and then use this technique to save and load the settings:

http://omnigeek.robmiracle.com/2012/02/23/need-to-save-your-game-data-in-corona-sdk-check-out-this-little-bit-of-code/

Rob

sir Rob what is Json? it is the same with sqlite?

if it is the same…
im comfortable to use sqlite…

tnx all for the info…

sir Tomas & Rob ^^

sir Tomas where this come from?

sqlite.returnUseVosotros() 

?

It’s a function I have in my own program. In Spanish there are 5 pronouns used in Latin America but 6 pronouns used in Spain, “Vosotros” being the 6th so this function returns the value to use vosotros or not and later on in the application, when I show the conjugations of a verb, it uses this value to show vosotros or not.

So it’s just a function within my program.

Best regards,

Tomas

Here is a JSON tutorial if you’d like to know more:

http://www.coronalabs.com/blog/2011/08/03/tutorial-exploring-json-usage-in-corona/

JSON - or JavaScript Object Notation is a standard way to represent data in an text format to make it easy to transport between computers.  Many people go look up JSON and immediately freak out when trying to read it and understand it.  Making up JSON on your own when you are not familiar with it is a scary process.   However, in the case of Corona and Lua, it’s really simple.  You don’t worry about what JSON is, you just need to know how to use the tools to use it.

What makes JSON popular with Lua people is that it’s very compatible with Lua tables.  They are nearly identical data structures, just one is represented in its binary form (Lua tables) vs. the Text representation (JSON string).  Corona SDK provides two JSON functions:

local json = require(“json”)

local myLuaTable = json.decode(myJSONstringOfData)

or

local myJSONstringOfData = json.encode(myLuaTable)

If you are working with REST services, they frequently produce JSON output or ingest JSON data in to them.  In PHP, a common server scripting language, they have two similar functions:  json_encode() and json_decode() which do the same thing to PHP arrays as the lua versions to to lua tables.

Now in this case, if you are saving just a number, like a high score, its easy enough to write that to a file, and read it back in and convert it back to a number.  But when the data becomes complex, and you want to save multiple values to a single file, you have to spend a lot of energy writing parsing code and figuring out how to store the individual data bits and make sure you know how to read them back in.  Using JSON all the parsing is done for you and you don’t have to even think about it.  Read a JSON string from a file and decode it to a table.  Take a table encode it to a JSON string and write the string out.   Very very easy.

How does this compare to SQLite?

SQLite is great when I have a lot of data and I’m only interested in little bits of it at a time, say 10,000 records of contacts and I only want to find ones who’s postal code is “23456”.   But for something like settings where you’re going to read the whole thing in and typically save the whole thing every time, SQLlite is more overhead and a more complex way to do it.

But if you’re comfortable with using SQLite, by all means use it, it will work too.

Rob

when you check the checkbox… it is permanent when you exit ur game then you come back to play again

… its always check?

problem solve with settings…tnx all…,

last problem is.

global score… gudlak to me…
i dont have idea… 

If you Google “corona save game settings” you get several answers, including Rob’s tutorial.

Regarding having “global” like data that persists between modules see:  http://www.coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

Regarding working with scores: http://www.coronalabs.com/blog/2013/12/10/tutorial-displayingsavingloading-scores/

Rob

Remember that, if you use JSON, you must have permission to write on device, take look at this discussion: Trouble with updating the game

  android =
  {
    usesPermissions = {
      "android.permission.WRITE_EXTERNAL_STORAGE"
    },
  },

Renato