Show "Empty" in the inventory panel

LoveMeTende
10 Nov 2022, 20:56

So, I tried to figure it out by myself but I think it's out of my noob possibilities at this point.
When the player has no items in its inventory, I want the game to display "empty" in the pannel. My idea was to create an "Empty" object which would be not droppable nor usable in any way. Then I thought to use some kind of change script to check if the inventory is empty everytime it updates. If so, I would add the "Empty" object. Then, whenever the player takes something, I would remove th "Empty".
I am missing the part of the change script, I cant find an "inventory attribute" on the player object to work with.
Please, anybody have an idea how to solve this?


mrangel
11 Nov 2022, 08:55

There isn't an inventory object. You would probably want to make this run as a turnscript, so that it's done after every command.

Alternatively, I might suggest using CSS. It's a long time since I played with this, but I think you could add something like this to your stylesheet:

#lstInventory:not(:has(li)) {
  content: "<li>empty</li>";
}

LoveMeTende
11 Nov 2022, 10:08

Thank you for the reply!
I really don't know how to edit the style sheet or where can i find it. Is there a guide somewhere?
I found this: https://docs.textadventures.co.uk/quest/ui-javascript2.html
I enabled DevMode and opened the HTML Tools, but I cant figure out where and how to put the code you kindly provide. I'm sorry, I'm very noob at this.


LoveMeTende
11 Nov 2022, 11:30

Meanwhile, I tried using a turn script as you kindly suggested.
This is the code I used. I set a variable with the result of a function, which I found it gives the number of items in the inventory.
The player starts the game with the "empty" obj in its inventory. So, each turn, the code checks the number of items the player is holding. If there are more than 1 (so basically when the player picks up a new item) and the player is holding the "empty" obj, then I remove it. But when the invcount is null (when the last item is dropped) then the "empty" obj is added.

invcount = ListCount(GetAllChildObjects (player))
if (invcount > 1) {
  if (Got(empty)) {
    RemoveObject (empty)
  }
}
else if (invcount = 0) {
  AddToInventory (empty)
}

I'm curious to know more about CSS. However, I feel like this turn script solution might be useful for someone else, so I'm posting and explaining it. I tested it and it seems to work fine ^^


mrangel
11 Nov 2022, 13:48

I suspect the easiest way to handle the CSS would be to put it in the UI Initialisation script (on the game's "Advanced Scripts" tab), so it runs whenever the game starts. You could just output the CSS, although that's a bit inelegant.

msg ("<style>#lstInventory:not(:has(li))::after {  content: \"empty\"; }</style>")

I forgot the ::after initially; but it seems to kind of work now (although in this case the "Empty" is just text, not an item, and so can't be selected)