How to get all keys values of the player prefs in unity [java script ] - unity3d

in the first test game I've developed if the player passed all the levels and win , he must enter his name ... so his name and his score will be stored in a player prefs :
there is another scene that displays the names and scores of all the user passed the game :
I've searched from the morning and try all the ways I know and finally I failed to perform this .... is it possible to display all the keys values previously stored in the player prefs ???
or can someone provide me by a JavaScript to do this ????
thanks...

The easiest way is to create your high score structure the way you want to, serialize it to string using json and save that string in playerprefs
use either of these to serialize
http://json.codeplex.com/
System.Runtime.Serialization.Json

You can use a custom script called ArrayPrefs2 on the Unity3D Wiki to store arrays of data as a value in a PlayerPref's key.
Using this method you don't need to try to figure out how to pull heaps of random PlayerPref key\values. For your case you could have two key->Value pairs as such:
HighScoresName \\ String array
HighScoresValue \\ int array

Related

How can i connect an "in pair table" into one string

heres what i've come up to but i still cant figure it out
for i, v in pairs(game.Players:GetChildren()) do
print((table.concat(v, "\n")))
end
table.concat is used to combine an array of objects into a string.
game.Players:GetChildren() will give you an array of all of the current Players in a game. While you could pass this array directly into the table.concat function, you should probably convert it into an array of the players' names first. That way you know what will actually get printed out.
-- create an empty table to store the names
local names = {}
-- get the players' names
local playersArray = game.Players:GetChildren()
for i, player in ipairs(playersArray) do
table.insert(names, player.Name)
end
-- join all the names together into a string
local playerList = table.concat(names, "\n")
print("Found these players :\n", playerList)
And if you ever get stuck and you don't know how to use some Lua functions, you can always look at the Lua Manuals, like this one :
http://lua-users.org/wiki/TableLibraryTutorial

Swift string with key-value, is this format standard ? How can I get it as a dictionary?

I work with an array of string, each string var is a coded object.
I want to decode the object, when I print a string var I get something structured like that :
"firstName=\"Elliot\" lastName=\"Alderson\" gender=\"male\" age=\"33\",some description I also need to get"
Is that a standard format to store key value properties ? I can't find anything on internet. The keys are always the same so that's not a big deal to get theses values as a dictionary but I would like to know if there is like a best practice method to get theses data instead of just searching for each key and then reach value from the first quote to the second one (for each value)
Because my file is 30000 lines so I better choose the more optimized way.
Thanks !

How to Send a Glympse from the Automate App

From the app Automate, I would like to send a Glympse. Automate's App Start block takes the following inputs. I assume not all of them have to be specified.
Package
Activity Class
Action
Data URI
Mime Type
Category
Extras
Flags
What should I set for the above values?
I am reading some code and looking at some documentation. I figured out that the Package should be com.glympse.android.glympse and the Activity Class should be com.glympse.android.intent.Create. The extras input should be set to a dictionary object. The dictionary should have a message key with a string value. The duration key has a long value which holds the number of milliseconds to share the location. I haven't figured out the rest of the keys or their formats.
Here are the steps...
Create a dictionary named recipient with these keys:
type with a string value of sms
address with a string value of 5425551212 // replace with the actual phone number
Create another dictionary named options with these keys:
recipients with a string value of jsonEncode(recipient) // this will convert the recipient dictionary into a JSON string
message with a string value of whatever you want to say
duration with a long value of the number of milliseconds to share the Glympse location (e.g. 1800000 for 30 minutes)
Use the App Start block with the following inputs:
Package is set to com.glympse.android.glympse
Activity Class is set to com.glympse.android.intent.Create
Action is set to Run
Extras is set to options // the dictionary created above
This will cause the Glympse screen to show up so that the user only has to hit the Create button.

Update string with firebase swift

I am trying to update a string with firebase swift but I am getting an error that I do not know how to get rid of.
I have this code part that is getting an error:
self.dbRef.child("feed-items/\(dataPathen)/likesForPost").updateChildValues("likesForPost": "7")
The error I am getting is expected "," seperator just before the :. I am using dbRef in another code part so I know i works and the dataPathen is being printed just before the above code part, so that is working too.
Can anyone help me with this bug?
Just change
self.dbRef.child("feed-items/\(dataPathen)/likesForPost").updateChildValues("likesForPost": "7")
To
self.dbRef.child("feed-items/\(dataPathen)/likesForPost").updateChildValues(["likesForPost": "7"])
And if you are only looking for incrementing a particular value at a specific node you might wanna check my answer's :- https://stackoverflow.com/a/39465788/6297658, https://stackoverflow.com/a/39471374/6297658
PS Prefer runTransactionBlock: to update properties like likeForPosts as there might be a moment when two users try to like same post at the same moment (Highly Unlikely, but still a possibility...),using updateChildValues might end up just updating like only from one user. But runTransactionBlock: keep firing until the changes of that thread have been committed to the node
updateChildValues accepts [AnyHashable:Any] dictionary:
self.dbRef.child("feed-items/\(dataPathen)/likesForPost")
.updateChildValues(["likesForPost": "7"])
Whenever updating values at any reference in Firebase Database, you need to pass a dictionary parameter for updateChildValues method as [AnyHashable: Any] for your path reference. So just update your code of line as below:
self.dbRef.child("feed-items/(dataPathen)/likesForPost").updateChildValues("likesForPost": "7")
Also if you need to update more than 1 key-value pairs then you can pass those key-value pairs inside dictionary by seperating using comma as below:
self.dbRef.child("feed-items/(dataPathen)/likesForPost").updateChildValues(["likesForPost": "7", "otherKey": "OtherKeyValue"])

Matlab - Name variable same as File name?

I'm building a facial recognition program and loading a whole bunch of images which will be used for training.
Currently, I'm reading my images in using double loops, iterating through subfolders in a folder.
Is there any way, as it iterates, that the images file name can be used before the image is read and stored?
eg. I have an image person001.jpg. How can you retrieve that name (person001) then read the image in like: person001 = imread('next iteration of loop which happens to be person001');
Thanks in advance.
I strongly recommend not to use unstructured variables. First it's very difficult to do operations like "iterate over all images", second you can get strange problems covering a function name with a variable name. Instead i would use a struct with dynamic field names or a map. A solution with a Map propably allows all possible file names.
Dynamic field names:
dirlisting=dir('.jpg');
for imageIX=1:numel(dirlisting)
%cut of extension:
[~,name,~]=fileparts(dirlisting(imageIX).name);
allImages.(name)=imread(dirlisting(imageIX).name);
end
You can access the images in a struct with allImages.person001 or allImages.(x)
Map:
allImages=containers.Map
dirlisting=dir('.jpg');
for imageIX=1:numel(dirlisting)
%cut of extension:
[~,name,~]=fileparts(dirlisting(imageIX).name);
allImages(name)=imread(dirlisting(imageIX).name);
end
You can access the images in a Map using allImages('person001'). Using a Map there is no need to cut of the file extension.