How do I solve my problem with array for inventory

Get help using Construct 2

Post » Fri Jun 03, 2016 9:09 pm

Hey guys! I am making an inventory and i am having problems with the array because when I pick up an item and then I pick up an other one item these last item i picked up replaced the other one.

Example:

https://gyazo.com/392a16c3d84d11acc311cc349e4d3156

Code:

https://gyazo.com/e93053272319db299665e79354511599

https://gyazo.com/f3b20a5d1a78c3c98e60620e78c7bfed

Thanks you all! Sorry about my english... maybe if you check the example then you will understand it. :geek:
Last edited by ElChuchis on Fri Jun 03, 2016 11:04 pm, edited 1 time in total.
B
14
S
6
Posts: 63
Reputation: 1,236

Post » Fri Jun 03, 2016 10:35 pm

Manual:
CurX
CurY
CurZ
The current zero-based index for each dimension in a For each element loop.

Me:
Where is the For each element loop ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jun 03, 2016 11:03 pm

99Instances2Go wrote:Manual:
CurX
CurY
CurZ
The current zero-based index for each dimension in a For each element loop.

Me:
Where is the For each element loop ?


Still not working right:

https://gyazo.com/46406d62be1e71c52d8237839b1bafc3

Code:

https://gyazo.com/e281f94cd1e46747fb02e6a3ed5f1cc4

https://gyazo.com/4aa7d541ea73dc5284c00349c8130b16

I am not sure about what did you mean... sorry :S
B
14
S
6
Posts: 63
Reputation: 1,236

Post » Fri Jun 03, 2016 11:20 pm

Not in the inventory does not mean it is not in the array. Did you look at the array in the debugger ?

You dont show how you let the inventory read out the array.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jun 03, 2016 11:41 pm

99Instances2Go wrote:Not in the inventory does not mean it is not in the array. Did you look at the array in the debugger ?

You dont show how you let the inventory read out the array.


That happened:

https://gyazo.com/37f0de3c7eae5d424584827270495e7f

:oops:
B
14
S
6
Posts: 63
Reputation: 1,236

Post » Fri Jun 03, 2016 11:46 pm

I tried it, and it works fine! but i need to pick up the item when you are scavaging the corpse or the bush...

https://gyazo.com/31139f11db84b46e7f895bf437c23931

CoDe:

https://gyazo.com/584ce7de1a88fac6b733179ab575a20b

Item.QueSoy (translate to english: Item.WhatIam):

https://gyazo.com/255c09390ac8ffa053cf6514c7c89254

One of the item have the variable name: berries, and the other one: Bones

I can't understand why the "For each X" fill all the array
B
14
S
6
Posts: 63
Reputation: 1,236

Post » Sat Jun 04, 2016 10:18 am

Contains value
Searches the entire array to check if any of the elements contains the given value. For example, you can use this to test if the string "sword" is stored anywhere in the array.

That is what the manual says about that condition.
You inverted it.
So, this is only true when there is at least 1 times Item.QueSoy in the WHOLE array.

Further

Item.QueSoy is a 'string'.
Variable = "berries" means you gave that variable the content of a STRING.
Variable = 11 means you gave that variable the value 11

So, either you have a number OR a string.

The value of "berries" = zero. The content of "berries" = "berries"

If you want to know if something is EMPTY (that it will not contain a string) you have to compare to a empty string.
Is variable = "" ?
At the moment you compare: Is variable = 0 ?

But, you did not pre-format the array. As a result there are numbers and strings in the array.
So, either you pre-fill the whole array with "" (the EMPTY STRING).

Or, you make the 'for every x' conditon.
Then a sub condition.
Value at curX = ""
OR
Value at curX = 0

Have to make it an OR block.

Since you coded only "Value at curX = 0" it filled the whole array because as string has a value of zero.

(those that expected me to use programming gramar at this moment are laughting there a.. off)
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Sat Jun 04, 2016 8:28 pm

99Instances2Go wrote:Contains value
Searches the entire array to check if any of the elements contains the given value. For example, you can use this to test if the string "sword" is stored anywhere in the array.

That is what the manual says about that condition.
You inverted it.
So, this is only true when there is at least 1 times Item.QueSoy in the WHOLE array.

Further

Item.QueSoy is a 'string'.
Variable = "berries" means you gave that variable the content of a STRING.
Variable = 11 means you gave that variable the value 11

So, either you have a number OR a string.

The value of "berries" = zero. The content of "berries" = "berries"

If you want to know if something is EMPTY (that it will not contain a string) you have to compare to a empty string.
Is variable = "" ?
At the moment you compare: Is variable = 0 ?

But, you did not pre-format the array. As a result there are numbers and strings in the array.
So, either you pre-fill the whole array with "" (the EMPTY STRING).

Or, you make the 'for every x' conditon.
Then a sub condition.
Value at curX = ""
OR
Value at curX = 0

Have to make it an OR block.

Since you coded only "Value at curX = 0" it filled the whole array because as string has a value of zero.

(those that expected me to use programming gramar at this moment are laughting there a.. off)


You solve my problem! Thanks youuu very much!! :D
B
14
S
6
Posts: 63
Reputation: 1,236


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests