[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 5150: file_get_contents(https://freedomsponsors.org/api/project/294): failed to open stream: HTTP request failed! HTTP/1.1 502 Bad Gateway
Force update certain $pref for users - Forums | Torque 3D

Force update certain $pref for users

Scripting questions, discussions, etc
10 posts Page 1 of 1
Duion
Posts: 698
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Mon Jan 18, 2016 4:01 am
Can I force update some of the user preferences somehow when a user downloads a new version of the game?
I changed it so the user preferences get stored in the users home directory independent from my game, but now I plan to change some of the values, but when someone who had a previous version of the game upgrades to the new version, he keeps the old preferences, so I need to force overwrite them with the new ones somehow.

Especially this one for example is annoying: $pref::Video::unavailableTexturePath = "core/art/unavailable";
I moved that texture to another directory, but if someone with an old prefs file opens the material editor the game crashes immediately, since he has the old path in his settings.
Duion
Posts: 698
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Mon Jan 18, 2016 4:18 am
I don't really know if those values are relevant, since it worked when I tested recently with wrong values, but I also had crashes because of wrong values for file paths in the prefs.
Poponfu
Posts: 2
Joined: Fri Feb 12, 2016 6:38 pm
by Poponfu » Fri Feb 12, 2016 6:45 pm
Legions does it something like this: There is $Pref::PrefVersion = #. When you need to do something like your case, you add to the updatePrefs function with another check. So in your case where they do not have it yet, you say if $= "", $pref::Video::unavailableTexturePath = <your new thing> then set their $Pref::PrefVersion to 1. Next time you would say if != 2.. change these things, then update their $Pref::PrefVersion to 2
Duion
Posts: 698
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Fri Feb 12, 2016 9:13 pm
So I make a list with pref variables I changed in the current version and hat have to be force updated and then I add a new pref version variable that gets added after I force updated the variables, to make sure the next time it loads the variables to not get force updated again, while checking against the pref version?
Sounds like a logic solution, I may try that some time later.
Poponfu
Posts: 2
Joined: Fri Feb 12, 2016 6:38 pm
by Poponfu » Fri Feb 12, 2016 10:25 pm
You make a new function like this that gets called somewhere early every startup.

Code: Select all

function updatePrefs()
{
   if($Pref::version $= "")
   {
      <change some prefs>
   }
   
   $Pref::version = 1
   //so now they are 1 and it knows whatever got changed
}



Next time you need to update some prefs, you add to the same function.

Code: Select all

function updatePrefs()
{
   if($Pref::version $= "")
   {
      <change some prefs>
      $Pref::version = 1
   }
   
   if($Pref::version == 1)
   {
      <change some prefs again>
   }
   
   $Pref::version = 2
   //so now they are 2 and it knows whatever got changed
}

Last edited by Poponfu on Sat Feb 13, 2016 10:25 pm, edited 1 time in total.
Duion
Posts: 698
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Fri Feb 12, 2016 11:53 pm
Ah thx, I will try it for my next version, since I will need it then.
Duion
Posts: 698
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Wed Mar 30, 2016 9:04 pm
I will use that system now, it seems to work.

Another question I have is, if it is possible to also delete the whole entry of a certain pref in total per script? It is just spam prevention, but since I change things a lot, it may be nice to have cleanup functionality.
Duion
Posts: 698
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Sun Apr 03, 2016 2:35 pm
Anyone has an idea how to force update certain keybindings in the config as well?
I found that the bindings config file generated for the user does not get updated, if new keybindings are added.
My solution so far is to just execute a restore defaults, if the pref version is outdated, but this will discard all the changes the user may have made to his bindings.
rlranft
Posts: 298
Joined: Thu Feb 05, 2015 3:11 pm
 
by rlranft » Sun Apr 03, 2016 5:59 pm
That's tricky - new keybindings might conflict with user selected bindings.

When you say "new keybindings" you mean "I've added a key binding to play a new animation or other new thing," right? I made a quick tool that removes the key constants from the OptionsDlg and puts them in a separate file but you could do that by hand (this file would need to be exec() from the OptionsDlg.cs file, preferably at the top). Then you just replace this file and let the user open and change their keybindings from the options dialog to "import" the added defaults without stomping on their selected preferences.

For example:
https://github.com/RichardRanft/Project ... Dlg.cs#L22
https://github.com/RichardRanft/Project ... /keyMap.cs

So, user updates to the new version of the game, opens his options dialog and the system should load his settings from the generated config file. Then when he saves his keybindings it should update the config correctly. It's a manual step for the user - worst case is they don't do it and therefore the new keybind is unavailable.

The key map modification tool is available here: https://github.com/RichardRanft/T3DKeyMapMod
Duion
Posts: 698
Joined: Sun Feb 08, 2015 1:51 am
 
by Duion » Sun Apr 03, 2016 6:45 pm
No, you cannot expect the user to take a step, the whole point is to making it fully automatic.
Many new keybinds I have are new ones that have not been used before, but even though they keys for them are not already bound to something else, they do not get added to the config.
The new mappings for vehicle and spectator are instead added automatically to the users config file, they are just appended to the config file, but somehow you cannot append some new configs to the old movemap config.
What I had in mind was to simulate a force rebinding of certain keybinds through script as it would happen when the user does it manually, which only happens once the user starts the new version from an old version.
In the end I thought just resetting it once would be the easiest option, since a lot has changed.
10 posts Page 1 of 1

Who is online

Users browsing this forum: No registered users and 2 guests