Log In  
Follow
Fawfulish
[ :: Read More :: ]

I've written some functions based on Dylan Bennet's tutorial "PICO-8 Top-Down Adventure Game Tutorial - Bonus Step - Text". I tried to adapt it to taking gold out of chests (I know the next video in the series partly covers that, but that solution assumes every chest in the game gives the same amount). Ideally they should output a certain number based on an x,y coordinate, which other functions could use.
'''
function set_chests()
chests={}
add_chest(7,3,9)
end

function add_chest(x,y,num)
chests[x+y*128]=num
end

function get_chest(x,y)
return chests[x+y*128]
end
'''

get_chest should return 9 when the coordinates (7,3) are put in, which could then be added to another variable. Instead touching the chest at (7,3) does this:
RUNTIME ERROR LINE 13 TAB 6
return values[x+y*128]
attempt to index global 'values' (a nil value)

I'm not in any rush to fix this, but the fact I have no idea why it's happening bothers me. Advice would be very appreciated.

P#106413 2022-02-06 06:39 ( Edited 2022-02-06 06:50)