LoginLogin

Need help with saving

Root / Programming Questions / [.]

ArrowCreated:
Need to figure out how to make data arrays to create a save function so players can save progress

Hey is that you from Miiverse? Posted on my Digipets post. I'm wondering how to do this too.

What is your name in miiverse

Aaron.

Hey what's up anything new to report

DIM ARRAY[1]
DIM ARRAY1[1]
ARRAY[0]=6
PRINT ARRAY[0]
SAVE"DAT:ARRAY",ARRAY
LOAD"DAT:ARRAY",FALSE OUT ARRAY1
PRINT ARRAY1[0]
All i know about saving and loading arrays.

Here's my key 5k2kx3ry Here's the variables I need saved with an array atk,dfn,hp,hpm,coin,c,lvl Any chance could figure it out for me

Save the variables as elements inside the array, then save the array like i had shown.

What do you mean save as elements inside array

Um, well, an array is made up of elements in which you store information inside. Example:
DIM ARRAY[2] 'Creates two elements in the array
ARRAY[0]=4 'The value of ARRAY at position 0 is 4
ARRAY[1]=6 'The value of ARRAY at position 1 is 6
There, i had stored elements inside the array. You can use the code i mentioned before to save and load the array. To retrieve the information, you can do X=ARRAY[n], and X will equal the value of ARRAY at position n.

How to attach variable I want to save to the array so that they save

I need to see variables in the array to know how to save variables an array just showing me an array won't help

Need to know how to save variables for hp and maxhp to the array

Someone else want to give this a crack? I've tried everything i know to explain arrays.

An array is just a list of variables under one name. I make the arraySTATS with DIM STATS[5] The 5 in square brackets says that this array STATS is 5 items long. Each item in a list is accessed by referring to its index. The notation for index access is ARRAYNAME[index] When counting with arrays, indices start at 0 and go to length - 1. That is, you declared it to be 5 elements, but the array knows those elements as 0 to 4. So to assign a value to the first position in the array STATS,
STATS[0] = 50
While we're at it, we can fill up the rest
STATS[1] = 1
STATS[2] = 1
STATS[3] = 4
STATS[4] = 10
Our array STATS now contains [50, 1, 1, 4, 10] To then retrieve these values from their elements, you simply refer to them the same as you assign them.
VAR = STATS[0]
And you can make comparisons directly
IF STATS[0] < STATS[3] THEN RETURN

Arrays An array is like a list of numbers, it can hold a bunch of different values. An example array might look like this:
DIM ARRAY[5]
DIM creates an array. ARRAY itself is just a name, like a variable name. Using the square brackets [ and ], inside we say a number that says how many values are in this array / list.
DIM ARRAY[5]
'Creates an array called ARRAY
'It can hold five different numbers. That's what the five does.
Saving values to an array is simple, just use
ARRAY[0] = 123
or, if you need variables to be saved,
ARRAY[0] = atk
Note: When saving to an array, you access the 1st value with 0, the second with 1, the third with 2, and so on. It starts at zero and goes to one less than the array size. You want to save
atk,dfn,hp,hpm,coin,c,lvl
which is seven different variables. So you can basically make a 'list of variables.'
DIM VARIABLES[7]
'This defines a list called VARIABLES with room for seven values.
VARIABLES[0] = atk ' This saves variable atk into the list of variables at location 0.
VARIABLES[1] = dfn ' This saves variable dfn into the list of variables at location 1
VARIABLES[2] = hp ' This saves variable hp into the list of variables at location 2
VARIABLES[3] = hpm ' This saves variable hpm into the list of variables at location 3
VARIABLES[4] = coin ' This saves variable coin into the list of variables at location 4
VARIABLES[5] = c ' This saves variable c into the list of variables at location 5 
VARIABLES[6] = lvl ' This saves variable lvl into the list of variables at location 6 (one less than array size)
This code could take all of your variables atk, dfn, etc. and put them into the array VARIABLES. To save the array VARIABLES, you can simply use
SAVE "DAT:STATS",VARIABLES
'just type SAVE "DAT:filename",arrayname
And loading is pretty much the same thing.
LOAD "DAT:STATS",FALSE OUT VARIABLES
'false just makes it not notify you it is loading, OUT VARIABLES tells SmileBASIC
'to OUTput the list back into VARIABLES.
Getting the stats back into atk, dfn etc. you can just use the reverse of saving them in
atk = VARIABLES[0] 'gets value from location 0 and stores it into atk
dfn = VARIABLES[1] 'gets value from location 1 and stores it into dfn
hp = VARIABLES[2] 'location 2 into hp, etc.
hpm = VARIABLES[3]
coin = VARIABLES[4]
c = VARIABLES[5]
lvl = VARIABLES[6]
Does this help you understand how to save variables? EDIT: Lumage beat me to it D:

Got an error can one of you fix it and send me new key here's my key Q3XPX3E3

No one wants to write your code for you. The problem is unclear, you haven't provided typed relevant code samples (we have no idea where in the key you provided the problem is), so we don't know how to help you. Please ask questions in order to learn, rather than getting the solution for one case, or you will end up more stuck later.

So the syntax error I got was duplicate variables... Do I need to put the load screen before the save screen?

I have know clue I'm still trying to figure out saving myself