read named items from Inventory

Problems Koding something? Get help from other users here!
User avatar
Lord-Ddog
Newbie
Newbie
Posts: 4

read named items from Inventory

Post#1 » Mon Jul 25, 2016 1:55 pm

Hi community,

I want to know, is there any way to read out an item from the player inventory?
I try to create a quest where my player must collect 5 apples. The quest giver shall read the player inventory to check the apples in his Inventory.
I have create a inventory which displays all apples I have collect in a stack.
But I don't create the check from the quest giver, all my tries won't work.
Anybody have an example kode for me?
Thanks for reading and hopefully help :-)

User avatar
MindcraftMax
Newbie
Newbie
Posts: 4
Contact:

Re: read named items from Inventory

Post#2 » Mon Jul 25, 2016 7:14 pm

Hello,

if you haven't already, read the Koding Curriculum, which is the tutorial to begin working with Kode.

I suppose you are using the [inventory] tile, this is just an object set, so you can simply go through it with a for each of loop and use a variable [number var: number of apples] that you increment by 1 every time you get an apple. But how do you know an object is an apple? I'm glad you asked.

To test if an object "test object" is an apple, DO NOT test if "test object" is equal to the apple in the gallery: an object coming from the gallery picker is pretty much regarded as an object set rather than an actual object, so you actually want to test if "test object" intersects the apple in the gallery, or you can transform [gallery picker: apple] into a real object set by joining [all objects] after it, and then test if that contains "test object".
You could also have created your "test object" from a template, but in that case, you still cannot test if "test object" is equal to the template. And you cannot use [intersect] directly on the template either, because it's not regarded as an object set: a template is mostly regarded as an object that doesn't really exist in the game. However, you can still get the object set of all objects created from that template with [template] [all objects], so you can do your test on that (using [intersect] or [contains]).
Finally, you can also look at the name of the object, and if it is the name that you gave to the apple or apple template in the first place, then it's probably an apple; just make sure you didn't give the same name to an object which is not an apple!

Okay, that's just one way to do it, but object sets are quite flexible: you don't need to look at each individual element to get the number of apples, instead you can directly calculate (without a for each of loop) the value of an intermediary [object set var: apples in inventory] object set, and look at [object set var: apples in inventory] [count].

User avatar
Lord-Ddog
Newbie
Newbie
Posts: 4

Re: read named items from Inventory

Post#3 » Mon Jul 25, 2016 9:03 pm

I actually do not 100% know how it works, but after I read your text, I have find a method to read out my apples out of my inventory :D
Thanks so much for your help :-)

User avatar
MindcraftMax
Newbie
Newbie
Posts: 4
Contact:

Re: read named items from Inventory

Post#4 » Mon Jul 25, 2016 10:29 pm

No problem :)

If you don't know for sure what is happening, try to go through your kode line by line and think of what should happen, and if there are tiles whose behaviour you are not sure of, read/watch tutorials about them and play around with them.

Return to “Koding Konversations”

Who is online

Users browsing this forum: No registered users and 1 guest

cron