Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Issue with datamaps, arrays and saves

I know, it looks like a mess because it is... I'm struggling to create an inventory system.

What I want to do is:

1. User finds weapons or items, grab it. It's stored, but not equiped.
2. He/she select between those items, and decide if the character will equip, drop it, etc.

This is what I have up to now.

In a startup passage:
$weapons to (a:),
$max_weapons to 12

<!-- some weapon -->
(set: $iron_knife to (datamap:
"name","Iron Knife",
"desc","A random iron knife",
"slot","rh")) <!-- right hand -->

<!-- creates a link -->
(set: $i_iron_knife to "(link-reveal: 'Iron Knife')[
    (if: $max_weapons is $weapons's length)[NO SPACE, SORRY]
        (set: $weapons to it + (a: $iron_knife))

With this, I can use something like "Hey, you have found a weird $i_iron_knife, maybe it's a good idea to take it" anywhere. The problem is when I use something like this to retrieve data:
[code]Slot 1:{
(set: $slot1_name to $weapons's 1st's name)
(set: $slot1_desc to $weapons's 1st's desc)
(set: $slot1_slot to $weapons's 1st's slot)

It works, but if I save and load the game, the "$weapons's 1st's name" and so on became invalid, because the datamap works like an array. "You can only access position strings/numbers ('4th', 'last', '2ndlast', (2), etc.) and 'length' of an array, not the string "name"."

Is it an expected behavior? Or am I doing something wrong?
Sign In or Register to comment.