QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: eddy498 on March 17, 2019, 06:42:41 pm
-
Hey guys i am looking for a way to hold an inventory in a text based game. I have looked around but cant quite understand other peoples ways of making it. if any of you know a tutorial i can use that explains how i can make inventory, and much better if it has an actual design or layout not just typed but like how you see in games let me know thanks.
-
just a thought, what about a structure that would have all the elements of the character including items.
-
Hi, I can show you the inventory system (and other more) that I use in my project , whose source code you can download from here:
https://www.qb64.org/forum/index.php?topic=241.msg1268#msg1268
basically I use an array, where I keep the code of the item, and some other player property/characteristics . I save it on disk with a format that you can find in '\ server \' inside the files '1.txt', '2.txt', '3.txt' etc, and so for each user.
to raise it to the array I use the function 'serverenviarinventario'
and to show it on the screen 'mostrarinventario'
Of course I use other functions for the screen design and how to manipulate the inventory
any questions are welcome!
-
Hi eddy498,
To follow up on what jack said, do you know about using TYPE... END TYPE definitions, also known as User Defined Types or Structures or Record Structures for databasing:
Sample from Wiki.
A playerType might be setup with any and everything you might want to track with each player.
With a Type defined, you can then setup an array of the playerType for all the players and track their status. Such an array can be saved to file to continue a game later or be displayed as needed during a game.
Say to just track x and y locations of each player:
TYPE playerType
x AS INTEGER
y AS INTEGER
pRadius AS INTEGER
pColor AS _UNSIGNED LONG
END TYPE
DIM SHARED nPlayers
nPlayers = 10
DIM SHARED player(1 to nPlayers) as playerType
move player 5 right 1 place:
player(5).x = player(5).x + 1
display all players as circles for which images could be replaced later.
FOR p = 1 TO nPlayers
CIRCLE (player(i).x, player(i),y), player(i).pRadius, player(i).pColor
next
The advantage of this system is that it keeps all data about player(i) under one labeled location.
-
Commandvom - Thanks ill look into that if i have questions ill let you know :)
bplus, no i didnt know about that type...end type definitions. But ill look into it since it seems like it will help greatly with creating save files in my games and such thanks.
-
Keep in mind with TYPEs that we still do not have the availability of arrays in user defined types, despite myself along with several others begging and pleading FOR YEARS! to have it added.
so you can not;
you can do
...
Dim PlayersInventory
(32) as Inventory
-
Cobalt, I see what you're saying. I assume this backback can only hold so many items? Maybe 10? Then you can set up item1, item2, etc etc?
Also, you could have one string of say 100 characters and have a list of item #s separated by some character, say like this
"23|16|114|1|12" and have a function that reads them all?
Another way that might not be efficient would be to have a type called item that holds a number for a player id and a description and have an array of them, then parse the array for player N when you want to see items they own?