0

I'm making a batch game and I need to know how to make an inventory.txt. So far I can write the inventory but not delete certain lines to remove things from inventory.

@echo off
if not exist inventory.txt GOTO :write
echo Date/Time last login:
type inventory.txt
del inventory.txt
:write
echo %date%, %time%. >> inventory.txt
pause
RetroCraft
  • 327
  • 1
  • 2
  • 13
  • Welcome to Stack Overflow. Can you give an example of what you have tried (from a "cannot delete certain lines to remove things from inventory." point of view)? I think you might be hard pressed to do line updates within a file from a batch script. You can do OS specific/whole file specific manipulation, but file modification isn't cmd.exe strong suit. Try this? http://stackoverflow.com/questions/11235153/how-to-find-if-a-string-is-in-a-list-of-strings-in-a-dos-batch-file – kgdesouz Nov 27 '13 at 15:57

2 Answers2

1

You could build a function to write your inventory file.
So when your inventory changes you call this function. And when all your inventory variables begin with the same prefix you could use a simple set <prefix> command to list them all.

set "inv.sword=1"
set "inv.bread=3"
set "inv.other="
call :inventoryChanged
....
exit /b

:inventoryChanged
(
  set inv.
) > inventory.txt
jeb
  • 78,592
  • 17
  • 171
  • 225
0

If you want to make an inventory, at the beginning of the game on a page that does not display, take anything you want to be in the inventory and say

set item=false

Then, have a shop or something that would go to a "purchase(itemname)" page when you press a certain key. Input this to that page:

set item=true (Next is if you have money...) set /a money-=(price)

Make sure you have the - before the =

Now for the Inventory. Make a page called :inventory and in it input this:

if item=true echo (item name here)

That means that it will only display it in the inventory if the player has actually gotten the item.

Or if you want to display something that stacks, input this:

echo (item) - %item%

it would say this for an example...

Arrow - 23