bartk Posted October 29, 2015 Share Posted October 29, 2015 Hey, I've got a weird problem with loading a text into a variable from the cache. Slight background, I started with a txt file called test1.txt which contained the text "This is a test". (Just to try out the functionality)Later I changed the text to a part of lorem ipsum to experiment with longer texts and to improvise pagination in a dialogue bubble. However, the variable kept returning "This is a test". My code:game.load.text('test1', 'txt/test1.txt');...text = game.cache.getText('test1');speech = game.add.text(0, 0, text, { boundsAlignH: "left", fontSize: '12px', fill: 'black', wordWrap: true, wordWrapWidth: 160 });I keep failing to make it recognise that the txt file's contents have changed, anyone know what I'm doing wrong? Link to comment Share on other sites More sharing options...
chongdashu Posted October 29, 2015 Share Posted October 29, 2015 Sounds like it's been cached in the browser.Could you try doing a clear cache in whichever browser you are using? Otherwise, try renaming it to test2.txt and see if it works - if it does, it should confirm it is the browser, which is caching the .txt file. Link to comment Share on other sites More sharing options...
bartk Posted October 29, 2015 Author Share Posted October 29, 2015 That does indeed solve the problem, thanks Would this be solved by calling game.cache.removeText('test') before game.cache.getText('test') every time? Link to comment Share on other sites More sharing options...
chongdashu Posted October 29, 2015 Share Posted October 29, 2015 I'm not sure, but I think removing it from the game's cache may not necessarily mean it gets removed from your browser's cache.if you're deploying this for people to play, one way is to use versioning (e.g., http://www.html5gamedevs.com/topic/7754-preloaded-image-doesnt-change/) Otherwise, if it's just for debugging, you can either disable caching in your browser, or clear it each time. Link to comment Share on other sites More sharing options...
jmp909 Posted October 30, 2015 Share Posted October 30, 2015 you can trygame.load.text('test1', 'txt/test1.txt?' + new Date().getTime())if you need to get a fresh version each time with versioning eg ?v=1 , that version will get cached Link to comment Share on other sites More sharing options...
bartk Posted October 30, 2015 Author Share Posted October 30, 2015 Oh thanks jmp, that's a good idea. It is just for debugging and possible future editing, but it's a slight headache to clear the cache every time. Both of yours' help is much appreciated Link to comment Share on other sites More sharing options...
drhayes Posted October 30, 2015 Share Posted October 30, 2015 If you're using Chrome, you can open the devtools and find an option "Disable Cache (while devtools are open)": https://developer.chrome.com/devtools/docs/settings From then on you can keep your devtools open (maybe as a separate window in the back, even) to keep the cache disabled while you're working on your game. chongdashu 1 Link to comment Share on other sites More sharing options...
chongdashu Posted October 30, 2015 Share Posted October 30, 2015 If you're using Chrome, you can open the devtools and find an option "Disable Cache (while devtools are open)": https://developer.chrome.com/devtools/docs/settings From then on you can keep your devtools open (maybe as a separate window in the back, even) to keep the cache disabled while you're working on your game. Yes, I'd suggest using this approach while developing because if not, your browser cache will fill up considerably quickly given the number of times you'll expect to be launching the game while debugging.Safari also has the option to disable cache, too (and I suspect Firefox would probably have it too) Link to comment Share on other sites More sharing options...
WombatTurkey Posted October 30, 2015 Share Posted October 30, 2015 Right click refresh icon on chrome, click Hard Reload. Only works when dev tab is open though Or, the Date.now() method works too Link to comment Share on other sites More sharing options...
Recommended Posts