Need help with saving
Root / Programming Questions / [.]
ArrowCreated:
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 6There, 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.
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] = 50While we're at it, we can fill up the rest
STATS[1] = 1 STATS[2] = 1 STATS[3] = 4 STATS[4] = 10Our 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] = 123or, if you need variables to be saved,
ARRAY[0] = atkNote: 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,lvlwhich 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",arraynameAnd 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:
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?