Saving Sound & Music settings with Webstorage

0 favourites
  • 8 posts
From the Asset Store
Grenade Sound Library contains: 135 sounds 50 grenade sounds and 85 surface sounds
  • I'm having trouble for some time now trying to save my sound & music settings so that the users setting preference stay if they exit the game.

    I've had numerous attempts at this but just can't get it to work. I would appriciate it if someone can show me how to do this as i want to know why it isn't working for me as i've used Webstorage just fine when it comes to saving a highscore.

    I've provided a capx file that i've quickly made so it stays under the 2mb limit if needed.

    Hope someone can help as i've been having trouble with this for a while now.

  • I couldn't run your capx. because I'm on a stable release of C2 but,

    Create a global variable to manage it. "Paused"

    System > Paused = 0 > Sound > Set not Paused

    System > Paused = 1 > Sound > Set Paused

    Use the web storage to save the value of the global variable "Paused" just like you would in a high score example.

    This is a simple example but you could have multiple variables to control multiple sound settings.

  • Thanks for the reply. I already have global variables to manage my music & sound settings. I have tried saving the global variables value but I can't get it to work. It may be something I'm doing wrong because I've done the same thing as I've done for the Highscore.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Hi SteveKane,

    After looking at your capx, I can see several things that need to change.

    First, all of your events for changing the sound\music settings (except for the touch event itself) run every tick - it would be better for them to be sub events of the touch event.

    Second there is nowhere that I could see where you are saving those settings to WebStorage.

    Here's a thread where I helped another Constructor with a similar question. I hope it will help you on your way as well

    how to save settings in a game

    Another thing that I noticed (although not related to your question here) is with regard to your high score.

      1) To display the high score you are retrieving the settings from WebStorage (good) and displaying it via SpriteFont (good), but doing so every time the event sheet runs (every tick - bad). Better to retrieve the value once and only update the display when it changes. 2) To save the high score you are checking the TotalDistance variable compared to the value stored in WebStorage, and if it is higher saving the result back to WebStorage - Every Tick. It would be better to check the highscore at the end of the run, and if it is higher then save it.

    Some good reading here that will help immensely in your game making!

    Hope the capx helps and, happy constructing...

  • Thank you for the advice and response. I should mention that the capx i provided is one that i just quickly made so it's not that most practical work you'll see Also with this capx, i'm aware that there is no work of trying to save settings with webstorage, thats because i provided a capx without that so you can see what i'm working with and can hopefully find a solution for my problem without my incorrect attempts getting in the way.

    I admit i'm still a beginner and still learning, i do appriciate the advice but i'm still a little confused with the example in the thread you've linked as that uses Functions which i am not using.

    Would it be possible if you can do this for the capx i've provided if it's not too much trouble. I'd like to learn how to do this as i didn't think saving Sound & Music would be this much of an issue.

  • I think you need to show what you have tried that didn't work. Maybe just a screen grab of the event that does the saving/loading?

    See the attached capx for a simple example. Hope it helps.

    Edit->

    1. Enter a value

    2. Click Save

    3. Enter a different value or delete it

    4. Click Restart to load last saved value

    I just noticed your comment about functions. I also have used very simple 1 or 2-liner functions in the sample. I think you should definitely use them. They aren't hard. Maybe you can use my example as they are very basic. They also stop events running 'every tick'.

    I also included a "Log" function. If you want, delete the 2 "Call 'Log'" lines and also the Log function, to simplify the sample even more (but logging is essential for debugging IMO).

  • Hi SteveKane,

    No problem, we are all learning.

    To help out a bit I have modified the example you posted. I should add that it is substantially altered as there are a number of things you are doing that are really not ideal .

    For simplicity I have changed it so it gives the results you are looking for without using Functions. I hope it helps you in some way.

    [attachment=0:27tnju6r][/attachment:27tnju6r]

    However as codah says functions are really quite easy and super usefull. I would encourage you to study the examples posted, and also the manual entry on function - it will help you a great deal for all your projects.

    Please note that in your example you were using separate spritefonts for each text(10) you wanted to display, but they were all exactly the same source image. In this case you can use instance of the same spritefont and use instance variables so that you can reference them in code if needed.

    I have modified the example to use just one spritefont. Take your time to see how that is working.

    Also I changed the sound and music sprites so they each contain the On\Off state images, this makes it easier to display the current user preference. I also used smaller images 32x32 instead of 300x300. The larger images are not such a problem with a simple layout, but if they are ever displayed on the game layout you are using up a lot of your graphics budget (4 images 300x300 - which in terms of memory usage = 4 512x512 images) just for a couple of buttons. See Ashleys blog remember not to waste your memory for more info on that.

    The capx is well commented, hope it helps.

  • codah michael Thank you both for your replies, its really helpful and i'll definately start learning more about functions.

    Also thanks for the capx file, appriciate all the work you've put into this. It's made me realise that i should start tyding up my work a bit more as it looks much better your way

    Thanks again.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)