Stack system - or something
Displaying 1-10 of 10 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
Frozenskin

So, I've been working on a game for a while and I've chosen verge3.
So, I have to create an inventory system - at first, I thought something like a unique position for each item, when acquired (for example "torch" is in the fourth position in any case). But this was a pretty weird system, and also I had to keep track of the inventory in every moment to avoid an item to overlap another, creating cosmic errors.
Then, I switched (in my ideal concept) to a stack system: when an item is acquired, it is put in the first free index (or, better, the first index that has a "0" value). I'm not particularly interested in shifting by one index every item when an item is removed from the inventory, it would be cool but I'm not really interested.
So. I've created an int array with 78 as size, but seems I haven't enough knowledge to create a stack system that works :|...I haven't figured it yet.
I know this forum seems pretty inactive at the moment...but still...
(Also sorry for every mistakes I'm not native English).

Posted on 2014-03-12 11:46:11

Kildorf

Hi there! Are you still having trouble with this, and are you using VergeC or Lua?

Posted on 2014-05-01 01:20:35

Frozenskin

Yes, VergeC (verge3). Since then, I've only made a few progresses (mostly because I had to study). I found out how to put items in there and pushing each time the last (after working with the array a bit). When I have to remove an item, it glitches horribly, and I've still haven't found out how to fix it (I worked only a bit in the last month - again, I had to study for an exam).
Should I post some code?

Posted on 2014-05-01 14:59:46

Kildorf

Don't worry about being slow to respond, school should come first. :D Good luck on your exams!

Go ahead and post some code and I'll see if I can help you out! What happens when it "glitches horribly"?

Posted on 2014-05-01 15:57:29

Frozenskin

Firstly, thanks a lot for helping me :D
#define ELEMENTO 78 //i have to admit this line is pretty dumb but still
int inventory[ELEMENTO] //the inventory array;
int inventory_positions[ELEMENTO] //positions of the item in the array;
int volte = 0;
int top = 0;
string inv_array = "inventory";
string pos_array = "inventory_position";
void inventory_routine(){ //I feel I can just delete this :|
for (volte = 0; volte<78; volte++){ 
SetIntArray(pos_array, volte, 0);
}
}
void inventory_get(int item_index){
//when an item is acquired, it is placed in the last free (=0) index of the array, and then pushes the last place available
SetIntArray(inv_array, top, item_index); //sets the item in the array
SetIntArray(pos_array, item_index, top); //remembers position of the acquired item in pos_array 
top += 1; //increases last place available. I think it has to be last
}
void inventory_take(int item_index){
//I want the item to be removed from the array and then, the last place, pushed 
int local_position;
int following;
int scorrimento = 0; //"scorrimento" means scrolling, I used that name because "scrolling" already exists somewhere else
int item_index_temp;
if (top > 1) {//I scrapped, edited and then I got this. It needs a loop 
local_position = GetIntArray(pos_array, item_index); 
following = GetIntArray(inv_array, (local_position + 1));
item_index_temp = item_index;
while (scorrimento<(78 - item_index + 1)){
SetIntArray(inv_array, local_position, following); 
SetIntArray(pos_array, following, local_position);
item_index_temp = following;
local_position = GetIntArray(pos_array, item_index_temp); 
following = GetIntArray(inv_array, (local_position + 1));
scorrimento +=1;
SetIntArray(inv_array, top, 0);
top -= 1;
}
}
if (top = 1) { //this works if there is only 1 item left
SetIntArray(inv_array, 0, 0);
SetIntArray(pos_array, item_index, 0);
top = 0;
}
SetIntArray(pos_array, item_index, 0);
}

It glitches...it changes indices of the array without control, adding the whole row of items instead of pushing, and stuff. I tend to mix variables names, they are both in Italian and English, sorry. I am confused.
I am a dumb guy, sadly. Right now, the script removes ALL the items in the array.
There is something I still can't get.
Again, thanks in advance.

Posted on 2014-05-01 17:08:16

Kildorf

No worries at all, FrozenSkin. Keep at it, and I'm sure you'll be a pro in no time. :)

I haven't actually tried running this code yet (sorry!), but I think the issue is here, specifically the two lines I've added the arrows to

scorrimento +=1;
SetIntArray(inv_array, top, 0); // <--
top -= 1; // <--
}
}


Those lines are inside your while() loop, so you're going to set the last item to 0, and also lower your top variable by one on every loop iteration. Give it a try with those two lines moved outside the while() loop...

scorrimento +=1;
}
SetIntArray(inv_array, top, 0);
top -= 1;
}


Can you give that a shot and let me know how it went? If that didn't work I'll get myself set up so I can actually test the code myself.

Posted on 2014-05-02 02:25:00

Frozenskin

To be honest, I haven't tried it yet, but I appreciate very much the help you have provided. When I'll be able to I'll reply or edit, ok?
Thanks again.

Posted on 2014-05-24 13:42:49

Kildorf

Sounds great. No need to rush for my sake. :)

Posted on 2014-05-25 03:10:00

Frozenskin

Oh yeah I'm back on it.
I've tried the suggested change, but several stuff happens instead. Now, it doesn't remove every item...but weird things happens: Items switch with others, and other things.

Posted on 2014-07-30 17:37:45

Frozenskin

Sorry for the double post, but I've found out a way to do it, and, essentially, I had to rewrite the code. For future reference, I suggest to use linked list (in any kind of code and programming language), since arrays seems to be too static to achieve this goal.
So, a friend of mine suggested to use them, and I found this:
http://verge-rpg.com/general/omg-v3-linked-list/
I'm not saying that it is the only way to do it, because I can't (not enough knowledge on the field), but it saved me.
Thanks to everybody! Thanks Feyr!

Posted on 2014-08-07 11:58:38


Displaying 1-10 of 10 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.