Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+1)

good evening all! question regarding the use of dd.chat. I've got a table (inventoryGrid) with the columns "inventory" and "itemInfo" (formatted as strings), and have written a few button scripts that add items when clicked. I made a separate button that will display a list of whatever items are in the table, and display the description when selected. so far, my code looks like this:

on click do
 dd.open[deck o]
 dd.say["Hallo, traveller."]
 if itemHave.value
  dd.close[]
  dd.open[deck r]
  dd.chat["These are the items you're carrying." (raze inventoryGrid.value)]
  dd.close[]
 else
  dd.say["Huh? My friend, you're not carrying anything. Pick something up and come back if you want me to tell you about it."]
  dd.close[]
  end
end

and I'm sure it could be simplified, but it works as intended! as for my question: I'd like to be able to have a final option at the bottom of the list that says something like "I'm leaving, now." that can be selected and trigger a final line of dialogue followed by dd.close so that you don't have to read through all of the options in order to exit the menu. I'm kinda lost trying to figure out how to script this due to using (raze.inventoryGrid.value). I'm not sure how to edit it in a way that will function. what's the best way to go about this?

(+2)

raze of a table (like the .value of a grid widget) makes a dictionary mapping the first column to the second column. For example,

 insert k v with "Apple" 11 "Banana" 22 end
+----------+----+
| k        | v  |
+----------+----+
| "Apple"  | 11 |
| "Banana" | 22 |
+----------+----+
 raze insert k v with "Apple" 11 "Banana" 22 end
{"Apple":11,"Banana":22}

the dd.chat[] function will exit if the value corresponding to a key in that map is a number (instead of a string or rtext), so we just need to add another entry to that dictionary.

If you have a dictionary in a variable, you can modify it in-place:

 d:raze insert k v with "Apple" 11 "Banana" 22 end
{"Apple":11,"Banana":22}
 d["Cursed Fruit"]:33
{"Apple":11,"Banana":22,"Cursed Fruit":33}

You can also perform the equivalent amendment if the dictionary was yielded by a subexpression, as long as you wrap it in parentheses:

 (raze insert k v with "Apple" 11 "Banana" 22 end)["Cursed Fruit"]:33
{"Apple":11,"Banana":22,"Cursed Fruit":33}

You can also construct a dictionary functionally using "dict" and then take the union of some other dictionary and the new dictionary with ",":

 (list "Cursed Fruit") dict 33
{"Cursed Fruit":33}
 (()["Cursed Fruit"]:33) # (yet another way of saying the above)
{"Cursed Fruit":33}
 (raze insert k v with "Apple" 11 "Banana" 22 end),((list "Cursed Fruit") dict 33)
{"Apple":11,"Banana":22,"Cursed Fruit":33}

Or you could make a second table and join its rows to the original (also with ",") before razing:

 raze insert k v with "Apple" 11 "Banana" 22 end,insert k v with "Cursed Fruit" 33 end
{"Apple":11,"Banana":22,"Cursed Fruit":33}

Many ways to peel this particular apple. I strongly recommend using the Listener to experiment with examples like these whenever you find yourself puzzling over a tricky expression; building things up in little pieces helps you verify an idea as you go.

Do those examples make sense?

(+1)

thanks so much for the quick response! I think I'm beginning to get this a little more, and the various examples were super helpful! I was able to add the line by using your second suggestion, and look forward to messing around with dicts some more, haha. thanks again!