Be a Supporter!

Array >string >base64 >string>array

  • 468 Views
  • 11 Replies
New Topic Respond to this Topic
Kwing
Kwing
  • Member since: Jul. 24, 2007
  • Offline.
Forum Stats
Member
Level 45
Game Developer
Array >string >base64 >string>array 2012-04-18 20:20:26 Reply

I want to make a saving system for an RPG game that uses codes rather than sharedObjects to save progress. To do this, my plan is this:

1. Put all of the player's stats into an array.
2. Convert the array into a string.
3. Convert the string to base 64.

Later, when the base 64 code is loaded, I need it to do this:

1. Decode the base 64 code into normal syntax.
2. Convert the string back into an array.
3. Assign the data in the array to the player's stats.

I'm not sure how this all works, but I don't think it should be -that- hard to do. Can someone just give me some tips on how to convert these data types? My guess is that changing data types around should be about as simple as this:

var myvar:String = "123"
trace(int(myvar)+1111);

If I offer to help you in a post, PM me to get it. I often forget to revisit threads.
Want 180+ free PSP games? Try these links! - Flash - Homebrew (OFW)

the1manwiththeplan
the1manwiththeplan
  • Member since: Jun. 10, 2008
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Array >string >base64 >string>array 2012-04-18 20:55:37 Reply

I think that no matter what format you convert your save variables to you will always require saving and loading from an external source (correct me if I'm wrong) whether its some kind of online storage or database or cookies on your computer.

I dont think converting your strings to base 64 in itself will save your variable for later access.


...

the1manwiththeplan
the1manwiththeplan
  • Member since: Jun. 10, 2008
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Array >string >base64 >string>array 2012-04-18 20:57:10 Reply

Just read your post again sorry i think i read it wrong you didn't say anything about not saving it externally forget what I just said.


...

the1manwiththeplan
the1manwiththeplan
  • Member since: Jun. 10, 2008
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Array >string >base64 >string>array 2012-04-18 21:04:18 Reply

I would convert all the variables into one long string with each variable separated by some kind of special character.

Lets say for instance the special character was "@" or Space " "

And then I would use a loop to read through each individual character of the string upon loading and distribute the variables where they need to go.
The loop would be instructed that every time it reached an "@" in the string
That it was distributing a new variable to a new place.

You could do the same for an Array or a range of different variables.


...

chesster415
chesster415
  • Member since: Jan. 19, 2008
  • Offline.
Forum Stats
Member
Level 15
Game Developer
Response to Array >string >base64 >string>array 2012-04-18 21:19:40 Reply

For As2
Download this
http://www.newgrounds.com/dump/item/4698e20d32ddb8b50ff027e7 3ca6f1ae

use String.split("delimiter") to make your String into an Array

I don't know AS3 'cause I can't afford it. Should be similar though.


I don't mind when I'm a hypocrite.

MSGhero
MSGhero
  • Member since: Dec. 15, 2010
  • Offline.
Forum Stats
Supporter
Level 16
Game Developer
Response to Array >string >base64 >string>array 2012-04-18 21:37:47 Reply

At 4/18/12 09:19 PM, chesster415 wrote: For As2
Download this
http://www.newgrounds.com/dump/item/4698e20d32ddb8b50ff027e7 3ca6f1ae

use String.split("delimiter") to make your String into an Array

I don't know AS3 'cause I can't afford it. Should be similar though.

AS3 is free...use FlashDevelop if you mean you can't afford Flash Pro. In AS3 it's still String().split(delim)

I didn't quite read the epic triple post up there, but you'd still be using a SharedObject to save the data unless you have a server or something. Is it really that important that the data is saved as a base64 String instead of a normal one or even an array?

the1manwiththeplan
the1manwiththeplan
  • Member since: Jun. 10, 2008
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Array >string >base64 >string>array 2012-04-18 21:46:29 Reply

I didn't quite read the epic triple post up there, but you'd still be using a SharedObject to save the data unless you have a server or something. Is it really that important that the data is saved as a base64 String instead of a normal one or even an array?

Epic triple post is epic


...

Kwing
Kwing
  • Member since: Jul. 24, 2007
  • Offline.
Forum Stats
Member
Level 45
Game Developer
Response to Array >string >base64 >string>array 2012-04-18 21:48:39 Reply

At 4/18/12 09:19 PM, chesster415 wrote: For As2

I actually work in AS2 myself. Your code damn near broke my brain but I think I'm beginning to grasp it just a little bit. It looks pretty brilliant, though, from what I do understand.

This probably seems kind of noobish, but as I've only learned enough AS to learn what I want to do, a bunch of these words are really alien to me. Could someone give me a brief rundown on what they do and what their parameters are, if applicable?

.charAt
.fromCharCode
indexOf
<< //I've used single < or > signs but never two consecutively. What does this signify?
& //This one is lost to me as well, is it similar to an && in an if function?
return //I assume this is similar to the trace function?
class
public
private
static //It must seem awful that I don't know what these last four do, but again I've never had to use them before.

Also, not knowing what classes are, I'm also not sure what this means:

Classes may only be defined in external ActionScript 2.0 class scripts.

Thanks for all the help, you guys are a lifesaver!


If I offer to help you in a post, PM me to get it. I often forget to revisit threads.
Want 180+ free PSP games? Try these links! - Flash - Homebrew (OFW)

Kwing
Kwing
  • Member since: Jul. 24, 2007
  • Offline.
Forum Stats
Member
Level 45
Game Developer
Response to Array >string >base64 >string>array 2012-04-18 21:50:56 Reply

At 4/18/12 09:37 PM, MSGhero wrote: I didn't quite read the epic triple post up there, but you'd still be using a SharedObject to save the data unless you have a server or something. Is it really that important that the data is saved as a base64 String instead of a normal one or even an array?

I don't want the code to be on someone's computer, I want it to be given to someone to write down so they can type it back into the game to pick up from where they left off. I'm making this game for a mobile device incompatible with sharedObject commands.


If I offer to help you in a post, PM me to get it. I often forget to revisit threads.
Want 180+ free PSP games? Try these links! - Flash - Homebrew (OFW)

the1manwiththeplan
the1manwiththeplan
  • Member since: Jun. 10, 2008
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Array >string >base64 >string>array 2012-04-19 00:18:48 Reply

Just out of interest?

Why would you want players to have to write down a long string of code that flash can already save to a file and store on your computer for you?


...

the1manwiththeplan
the1manwiththeplan
  • Member since: Jun. 10, 2008
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Array >string >base64 >string>array 2012-04-19 00:20:04 Reply

Oh mobile devices I see ignore last post. =P


...

Diki
Diki
  • Member since: Jan. 31, 2004
  • Offline.
Forum Stats
Moderator
Level 13
Programmer
Response to Array >string >base64 >string>array 2012-04-19 09:28:37 Reply

At 4/18/12 09:48 PM, Kwing wrote: This probably seems kind of noobish, but as I've only learned enough AS to learn what I want to do, a bunch of these words are really alien to me. Could someone give me a brief rundown on what they do and what their parameters are, if applicable?
.charAt

This returns the character at the specified position within the string. So if you have the string "hello world" and you do chatAt(4) you will get the letter "o".

.fromCharCode

The Adobe Docs will explain this better than I can.

.indexOf

This will return the index position of a passed value, if it is found.

<<

This is a bitwise left shift. I wrote a tutorial on them which you can read here.

&

This is another bitwise operator, namely the bitwise AND. It is covered in my tutorial that I linked to.

return //I assume this is similar to the trace function?

This does exactly what it sounds like: it returns a value, specifically: it returns a value from a function.
It has absolutely nothing to do with trace. They are not even remotely related.

class

This is kind of self-explanatory. It declares a class.

public/private

If you don't know what these are doing then you need to read up on Object Oriented Programming.
Essentially they make variables and functions more or less visible. If a function is public then anything that can access the class can access the function. If the same function is instead made private only the class in which the function is defined can access said function.

static

I also wrote a tutorial on this keyword, which you can read here.
Don't expect the grasp the concept immediately though; it can be confusing.

At 4/18/12 09:48 PM, Kwing wrote: Also, not knowing what classes are

This is really, really, really bad. I don't even know how you're making a game without knowing what a class is.

My only advice is to stop writing AS2, learn AS3 (and learn it properly), and start looking things up on the Adobe Docs.