My Inventory Script Is Not Working... :c

aisdjioad

Member
So i'm just trying to make a "pick item" system script, but it's not working at all.

I have some global variables named: global.InvSlot0, global.Invslot1, 2, 3, 4, 5. (these are the slots in my inventory).
And another global variable named: global.currentInvSlot = [global.InvSlot0, global.Invslot1, 2, 3, 4, 5]

So this is the code:

function scrItemGet(_iid) ///_iid is the item id.
{
for (var i = 0; i < 5; i++)
{
var _check = global.currentInvSlot;

if (_check == 0)
{
global.currentInvSlot = _iid;
return true;
}
}
}

But when i try to pick up the item, nothing happens...
I open my inventory and the item is not there.

Theres something wrong with my code?
 

chamaeleon

Member
Since you don't make use of the global variables InvSlot0 through InvSlot5 besides in the array declaration, I'm assuming you're working under the impression that by putting those variable names there in that array declaration, somehow using the array later, like in your function, changes made to those global variables will somehow be reflected by inspecting the array. This is not going to be the case. The array will only have the values of your variables at the point of time it is initialized. Any changes made to the variable values after this point in time will have no effect on the values in the array.
 

aisdjioad

Member
Since you don't make use of the global variables InvSlot0 through InvSlot5 besides in the array declaration, I'm assuming you're working under the impression that by putting those variable names there in that array declaration, somehow using the array later, like in your function, changes made to those global variables will somehow be reflected by inspecting the array. This is not going to be the case. The array will only have the values of your variables at the point of time it is initialized. Any changes made to the variable values after this point in time will have no effect on the values in the array.
So what would be better to do?

I just did a debug now and saw that my globa.Invslot0 value is changing... so the script worked!

But, for somereason, the item's info is not showing in my iventory.

"info" i mean: name, sprite, etc
 
Top