Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

loadsave boolean value nil, help!
Started by dodi_games Sep 30 2018 04:44 PM

5 replies to this topic

Best Answer Rob Miracle , 01 October 2018 - 12:00 PM

Can you do a:

print( json.prettify( myTable ) )

and share the results?

 

Rob

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 324 posts
  • Corona SDK

hi guys I have a situation whith loadsave functions that I do not understand. 

 

I have a music button created in scene create with a manageMusic "tap" listener

local loadsave = require( "loadsave" )

local myTable = {}

local function manageMusic()
	if audio.getVolume( { channel=1 } ) == 0 and
	   audio.getVolume( { channel=2 } ) == 0 then
		   audio.setVolume( 0.4, { channel=1 } )
		   audio.setVolume( 0.4, { channel=2 } )
                   musicBtn.fill = loads.musicOn

		  --save music state to JSON
 	  	  myTable.musicIsOn = true
 		  loadsave.saveTable(myTable, "myTable.json")
 		  print("Music is on == ", myTable.musicIsOn )
	else
		  audio.setVolume( 0, { channel=1 } )
		  audio.setVolume( 0, { channel=2 } )
                  musicBtn.fill = loads.musicOff

	  	  --save music state to JSON
	  	  myTable.musicIsOn = false
		  loadsave.saveTable(myTable, "myTable.json")
		  print("Music is on == ", myTable.musicIsOn )

	end

end


-- show()
function scene:show( event )
  local sceneGroup = self.view
  local phase = event.phase
  if ( phase == "will" ) then
      myTable = (loadsave.loadTable("myTable.json") )


      print( myTable.musicIsOn )

When I load "myTable.json" and print variables with numeric values I get the numbers printed but when I print a boolean the output is nil   :huh:

 

Thanks in advance

DoDi



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,969 posts
  • Corona Staff

  Best Answer

Can you do a:

print( json.prettify( myTable ) )

and share the results?

 

Rob


  • dodi_games likes this

[TOPIC: post.html]
#3

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 324 posts
  • Corona SDK

Can you do a:

print( json.prettify( myTable ) )

and share the results?

 

Rob

19:36:24.110  File found: myTable.json
19:36:24.110  {
19:36:24.110    "livesNumber":2,
19:36:24.110    "sceneNumber":"8"
19:36:24.110  }

no musicIsOn true or false



[TOPIC: post.html]
#4

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 324 posts
  • Corona SDK

I see that the problem is every time a value is saved in "myTable", "myTable" is deleted and replaced by a new .json file. I have managed to write the current level number and the current lives number satisfactorily to "myTable" because those values ​​are present and are updated in all the scenes. However I can not see how to write the value of "musicIsOn" through the scenes. It is a simple game to try everything I could learn from "Corona SDK". I understand that I must pass the value of "true" or "false" to the scenes for each time "myTable" is written, "musicIsOn" value be saved too, but...

I do not know how to do it.

Thanks in advance
DoDi

[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,969 posts
  • Corona Staff

I don't know that I can tell enough from your code snippets to get a full context of where myTable is and isn't in scope. JSON supports boolean values so it doesn't make sense that your true/false values are not being saved.

 

It would useful for you to go into the loadsave module and print the string being read from the file before it gets decoded to see what the JSON content actually is.

 

Rob



[TOPIC: post.html]
#6

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 324 posts
  • Corona SDK

I think I found a way to destroy all scenes and make a full save of .json table, but I'm re-writting my 10 levels.

 

The 

print( json.prettify( myTable ) )

was very very useful, thanks @Rob...If I make another mistake I will comment here.




[topic_controls]
[/topic_controls]