0 votes
by (160 points)
i have attempted to make an rpg game and am trying to implement a save feature, it works fine until i save then try to load it.

it says

You can only access position strings/numbers ('4th', 'last', '2ndlast', (2), etc.), 'length', 'any' and 'all' of an array, not the string "stats".►I tried to access a value in a string/array/datamap, but I couldn't find it.

and i dont know how to fix this

1 Answer

+1 vote
by (154k points)
selected by
 
Best answer

Without code examples of:
1. how you're initialising the datamap
2. how you are accessing the "stats" property at the time you recieve the error.

... it makes it difficult to know the structure of the datamap and why that specific "stats" property reference fails.

eg. Assuming your datamap structure is something like the following.

(set: $player to (dm:
	"name", "Player",
	"stats", (dm:
		"strength", 10
	)
))

... and assuming you are using code like the following to access the properties of the datamap

Name: (print: $player's name)
Strength: (print: $player's stats's strength)

... then you should be able to use (load-game:) macro to load a Save create by the (save-game:) macro as long the "stats" property was part of the datamap's structure at the time the Save was created. (*)

*. If the structure of the datamap has been changed since the Save was created then the instance of the datamap within the Save will not contain those changes.

eg. If the structure of my $player datamap originally looked like this.

(set: $player to (dm:
	"name", "Player"
))

...and I created a Save then the instance of the datamap within it would only have a "name" property.

If I later chaged the structure of the datamap to be..

(set: $player to (dm:
	"name", "Player",
	"stats", (dm:
		"strength", 10
	)
))

... and I then loaded the old Save the structure of $player would be reverted back to how it was at the time the old Save was created...

(set: $player to (dm:
	"name", "Player"
))

...which would result in an error if I tried to access the now non-existient "stats" property.
 

 

by (160 points)

im initialising the datamap by doing

(set: $player to (dm:"playerdmg", 50, "lvl", 1, "maxhp",10,"xp",49,"stats",5, "str", 0, "def", 0, "luc", 0, "vit", 0)

and then accessing it later with 

(print: $player's stats) 

and it didnt work, it said the same as before. 

The information is still saved there i think but it changes the data map into an array maybe, as when i put 

(print: $player)

before i loaded the game it was printed out like this:

 

playerdmg	50
lvl	1
maxhp	10
xp	49
stats	5
str	0
def	0
luc	0
vit	0

and then after loading the game it was this:

playerdmg,50,lvl,1,maxhp,10,xp,49,stats,5,str,0,def,0,luc,0,vit,0

thank you for the help

by (154k points)

Your first example is missing a close parentheses ")" at the end of the line, I will assume that you really meant that example it to be

(set: $player to (dm:"playerdmg", 50, "lvl", 1, "maxhp",10,"xp",49,"stats",5, "str", 0, "def", 0, "luc", 0, "vit", 0))

... which your second example would display as the number 5.

I have just noticed from your Question Tags that you are using v2.0.1 of Harlowe . Did you mean v2.1.0 (which is the current version) or are you actual using an old version of both Harlowe and Twine 2.x?

If you are using an old version of Harlowe then I suggest you update your version of the Twine 2.x application which will also update you to the newer v2.1.0 of Harlowe.

by (160 points)
im sorry im not being  overly helpful am i?

the missing parentheses is that i copied and pasted badly

i am on 2.2 twine and 2.1 harlowe.

is there any other factors that can affect it? again, thanks for the help
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...