â Trying to save location data using JSON. Need help!
I am very new to coding, and I need to make 3 different scripts (or one script with all 3 functions) for an assignment, but am very stuck on one part. I need to be able to store object locations, player, NPC and world space into JSON. I managed to get a stats script to save, but referencing the location and saving is the barier. Any ideas? I attach my script for the inventory.
16 Replies
What doesn't work about it?
Also, Unity I presume?
can't you just copy over the location from the original object to your own save data object?
The inventory script works, just wondering if I can tweak it to add location too. I don't know how to reference it properly in order to get it to save.
That's the thing, I don't know.how to write it đ
. I can understand code, and know how things work, but for the life of me I can't write it out
as you already have
SaveToJson
and LoadFromJson
, i'm pretty sure you can simply assign the Vector3
to the object before serializing it, and then assign it back to the target object after de-serializing itWhat would that look like?
Again, I can't write proper lines to save my life
dunno if this counts as spoon-feeding, but i hope not... ^^'>
assuming
this
is the object you want to serialize
then after you de-serialize it, you'd just do the opposite
oh wait you're serializing a single field of a object
well i'd save it all to a single json file, something like playerdata.json
i recommend using JSON.NET instead since it's much more powerful if you do need to serialize something complex
with the default JsonUtility
, it only serializes fields
meaning you'd have to do something like PlayerStateSnapshot
that would copy all the data that you need to save
the methods that this class would implement would be as follows:
with JSON.NET you would be able to avoid this thoughI see. I'll try it and come back if anything goes wrong. Thanks for the input đ¤
Got this so far, but its telling me "gameObject" cannot be found, missing assembly reference? What have I got wrong?
Can I replace it with a certain tag? So I can just tag NPC and Player and have it take those coords and store it
uuuh, well, that's a field
are you sure you familiarized yourself with C#? i'd recommend learning OOP + C# before going into unity :p
the syntax for a field member is
<modifiers> <type> <name> = <object initialization, appended to the constructor>
see this is for my college course, I'm more of an art guy, but this module is mandatory đ
Im just tryin to pass the module so I can go further into design next year
oh, i see
if you have some time to spare take a look at https://www.youtube.com/watch?v=GhQdlIFylQ8
freeCodeCamp.org
YouTube
C# Tutorial - Full Course for Beginners
This course will give you a full introduction into all of the core concepts in C# (aka C Sharp). Follow along with the course and you'll be a C# programmer in no time!
âď¸ Contents âď¸
â¨ď¸ (0:00:00) Introduction
â¨ď¸ (0:01:18) Installation & Setup
â¨ď¸ (0:05:03) Drawing a Shape
â¨ď¸ (0:17:23) Variables
â¨ď¸ (0:30:06) Data Types
â¨ď¸ (0:37:17) Working With S...
if not then the sololearn.com course is also pretty good :p
do you have experience with other langs?
We touched on java in the first year, but that was almost 2 years ago
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.