new inverotry system (to madbrit)

Elexxorine
17 Jun 2005, 10:11
ok on finding that having lots of variables confuses quest, i have made a new (not quite) invertory system. this in vovles having a variable for intory slots. so say you can hold 8 items, the variables will be itemheld1-8.
i've mad some code to see if it works, but not tested them yet. there are 2 codes so far:

no.1: picking up a simple item(non-stackable).
if (itemheld1 > 0) then {
if (itemheld2 > 0) then {
if (itemheld3 > 0) then {
msg <you don't have any room.> }
else {
msg <you pick it up.>
set <itemheld3; (item number)> }
else {
msg <you pick it up.>
set <itemheld2; (item number)> }
else {
msg <you pick it up.>
set <itemheld1; (item number)> }


code no.2: picking up stackable items.
if (itemheld1 > 49) then {
if (itemheld1 < 61) then {
msg <you pick it up.>
set <itemheld1; %itemheld1% + 1> }
else if (itemheld2 > 49) then {
if (itemheld2 < 61) then {
msg <you pick it up.>
set <itemheld2; %itemheld2% + 1> }
else if (itemheld3 > 49) then {
if (itemheld3 < 61) then {
msg <you pick it up.>
set <itemheld3; %itemheld3% + 1> }
else (don't pick up.) }
else if (itemheld3 > 49) then {
if (itemheld3 < 61) then {
msg <you pick it up.>
set <itemheld3; %itemheld3% + 1> }
else (don't pick up.) }
else if (itemheld2 > 49) then {
if (itemheld2 < 61) then {
msg <you pick it up.>
set <itemheld2; %itemheld2% + 1> }
else if (itemheld3 > 49) then {
if (itemheld3 < 61) then {
msg <you pick it up.>
set <itemheld3; %itemheld3% + 1> }
else (don't pick up.) }
else if (itemheld3 > 49) then {
if (itemheld3 < 61) then {
msg <you pick it up.>
set <itemheld3; %itemheld3% + 1> }
else (don't pick up.) }

hopefully you can understand that code, :roll: it took me ages to get it right...

MADBRIT: i'd like it if you checked my codes over, first is simple, second is very complicated, would this system work? if not then what!?

MaDbRiT
17 Jun 2005, 15:29
Elexxorine

I'm a bit puzzled as to the purpose of your code as posted, what are you trying to do exactly?

If you simply want to set a limit on the number and/or size of objects carried, this can be done very easily without use of any arrays.

If you can try to explain in regular terms the effect you are trying to produce (especially with regards to your reference to items as 'stackable') I might be better able to help.

Al (MaDbRiT)

francisstokes
17 Jun 2005, 16:00
I think what what hes trying to say is hes got variables that hold items insted of using the built in iventory system.
A "stackable" item is an item that you have more than 1 of in the same slot (though, you could only have up 32000 odd of them, so its not good for currency), eg a potion would display you have 12 potions, all in one variable but something like an iron ore would display: you have 7 iron ore, but in seven seperate slots.

This kind of system is used widely in MMORPG's (mass multiplayer online role playing game) as it makes 'skills' items easier to keep track of.

I found that really hard to explain and it probably reflets when you read it but i tried.

Cryophile
17 Jun 2005, 18:41
Why not just have a property for each stackable object called 'quantity'? Wow, talk about reinventing the wheel...

Also, if you want to display in the inventory how many you have change the alias to something like:
Potion [#(objectname):quantity#]

Elexxorine
20 Jun 2005, 10:03
i'm trying not to use the built in system, as you can only really have one of each object, with out coding each one, so i'm using variables, like FS explains. i'm just having problems with quest getting confused with lots of variables :roll: .

Cryophile
20 Jun 2005, 18:54
You just totally disregarded my point. You can have multiples of each item if you assign a property called quantity. Say you want to drink a potion - you would check to see if quantity was 1 and remove it from your inventory. If the quantity was > 1 then you would subtract one from the property. The built-in method is extremely competent and does not need to be redone. I accomplished this quite well when I was writing RPGs (still working on Shadow Project... I notice CW has done nothing with the demo)
There is absolutely no need for a new inventory system. With this system you can effectively have unlimited amounts of any item you coded only once. You do not need to make an item for each instance and you do not need to clone anything. Although, I did use cloning for random encounters in Shadow Project. It worked perfectly. If you want my asl file for that I can send it to you sometime.

francisstokes
20 Jun 2005, 19:24
Let elexxorine have his fun.If he wants to create a new inventory system specificaly for his game, i say let him do it.I want to see how it turns out.

steve the gaming guy
20 Jun 2005, 20:46
He can have all the fun he wants but I think S1aY3R makes a good suggestion.
I personally would like to learn how to code that properly as I am still learning (and probably will be for a while).

S1aY3R, with your potion example, where do you put that line of code within the game? I get the general idea of what you're thinking but I just don't know where that fits in. Is that in an inventory room maybe?

paul_one
21 Jun 2005, 09:28
When you pick up an item, you need to check that it's 'collectable', see if you already have an object with the same alias - or property referencing the object (eg, an object name or number to define that specific object) and then increase the property called 'quantity' and then set the property 'alias' to 'object[#(objectname):quantity#]'.

Let's try to explain that in simple terms with an example:

You have a potion in inventory and one on the floor. Both HAVE to have different names... SO the one in hand is "potion" and the one on the floor is "potion_clone1" - it's alias'd to "potion".

To identify that they can be 'collected' or 'stacked' you need a property to say so... You may want 4 different puzzle pieces but not to stack them, etc. So they have the property 'collectable' (boolean).

So that they are the same object, they have the property "object" which is set to "healthP". You may have 2 TYPES of books, and don't want them all stacked together - but stacked into two (or more) piles.

When you pick up the object, you check to see if it has the property 'collectable', then check to see what the 'object' property is. Finally 'quantity' is checked on the object you're picking up (incase there are 7 'potion's on the floor all together) and added to the quantity in the 'potion' in the inventory.
The object being picked up is destroyed/moved to a 'void' room.

And Slayer, sorry that I haven't commented on it. I remember having a look at the file - and again about a week ago when I was tidying up all my data around various locations. I'll have to hunt around and find it again.