ID:2131000
 
(See the best response by Nadrew.)
        var/marcielle
marcielle = list(0="How are you today?",1="The weather has been so eratic lately don't you think?",2="My husband, The Elder, Has been extremely busy lately with problems showing up all over town!")
Click()
var/x = rand(0,2)
src<< "[marcielle[x]]"


Problem description:I have been trying to make it so when an npc is clicked it runs through a list and randomly chooses a response but i keep gettin a runtime error: cannot read from list




runtime error: cannot read from list
proc name: Click (/mob/NPC/Marcielle/Click)
usr: the adfasdf (/mob/Player)
src: Marcielle (/mob/NPC/Marcielle)
usr.loc: the floor1 (40,14,1) (/turf/floor1)
src.loc: the floor1 (40,15,1) (/turf/floor1)
call stack:
Marcielle (/mob/NPC/Marcielle): Click(the floor1 (40,15,1) (/turf/floor1), "mapwindow.map", "icon-x=16;icon-y=19;left=1;scr...")


Best response
BYOND lists are 1-based indexes, and not 0, so when you put that "0=" there you're breaking things pretty bad. You don't need the "[num]=" part at all, actually. Just the text.

You can use pick() to pick a random item from the list.
List indices start at 1, not 0. You also don't need to specify the index for each item in the list.
var list/responses = list("A", "B", "C")

Click()
// output one of the responses randomly
// response index is a number from 1 to the number of items in the list
usr << responses[rand(1, length(responses))]

// the above is equivalent to this:
usr << pick(responses)