Reputation: 337
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
Upvotes: 0
Views: 167
Reputation: 3
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
Upvotes: 0
Reputation: 82307
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
Upvotes: 1