I'm making a game with a saving system in Python, but it doesn't work as intended.
thingcount = saveArray[0]
The code above is supposed to set thingcount to 5454, as shown in the saveArray:
[5454, 0, 1]
But it only sets thingcount
to 5. Does anyone know how to do this?
CodePudding user response:
As some of the comments have noted, if saveArray
truly equals [5454, 0, 1]
, then the command print(thingcount)
will yield your desired output of [5454]
If thingcount[0]
yields an output of 5
, then at some point in your code, saveArray
is being set to 5454
only - Maybe as a string, but not the full list of [5454, 0, 1]
Below are two code snippets for a comparison example:
Desired Output
saveArray = [5454, 0, 1]
thingcount = saveArray[0]
print (thingcount)
Console output:
5454
Code that will yield the output you're seeing
saveArray = '5454'
thingcount = saveArray[0]
print (thingcount)
Console output:
5
In any case, I would check what saveArray
is being set to - At some point in your code, its being set to a different value, not your full target list of [5454,0,1]
On getting the first element from a list in Python - Below is a link to another thread that discusses getting the first element of a list, if that is helpful: