Array Questions

Get help using Construct 2

Post » Mon Dec 19, 2016 11:01 am

So i am on a part of crafting items. I would like to create a system to where whenever you are in the crafting menu you will be allowed to drag materials in the window to see if it yield any craftable items. Such as this Stone and Stone to the little window. and the result would be a sharp stone

Now i know from a variable stand-point that all it require is just if you have 2 or more stone you get a sharp stone but what if i got another 2 thousand more worth of craft-able other items. So I figure perhaps i can use An array system that would checks recipes of craft-able items.

From my current limited knowledge I do not know if there a string to check array by the rows only such as this if stone and Another stone on the same of the array at Y=0 to show what it can produce .

so for instance if i pick a stone and a stick in the window it should not yeild anything since at the Y 0 line stone and stick does not appear on the same line.

And I would like to know if it possible for me to create a system where i can make the game to check recipes per line rather then per coors? How would one tell contruct two to do that.
B
51
S
24
G
6
Posts: 391
Reputation: 7,820

Post » Mon Dec 19, 2016 9:07 pm

Just to let you know, I'm working on an example for you.
By the way, it's in XML, I think that's more suiting for a crafting system than an Array.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Mon Dec 19, 2016 11:30 pm

Here you go:
Download .capx

Important:
This is a very rough and unfinished version, not very backend-friendly.
It is not commented, so it probably is quite confusing.
I don't have the time to comment it yet, so I will add that later.
You will also have to understand XML to understand how the program works.
You won't need it though to add new recipes, since XML is easy to edit.


There is also one quite big issue:
Recipes with more than one ingredient of the same kind (like Sharp Stone, 2xStone) will be crafted with one ingredient only and will cause other recipes with the same ingredient to stop working correctly.
I'll probably address this in the future, if you can't fix it yourself.
It is possible, but quite tedious.

This is my first use of XML in a project, so keep in mind that there might be better solutions than the one I used.
You may want to bump this thread if you think you need more help.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Tue Dec 20, 2016 5:06 am

hmmm After looking at it wouldnt it make sense to add in something like a counting system. such as if one text of stone get placed in the box add one to a counter. and if another UID get entered then add one and have the crafting system use if 2 or more are place make 1 sharpstone.

Cause atm you are right about the bug but that because you dont have anything define how many of each but rather just text of one.
B
51
S
24
G
6
Posts: 391
Reputation: 7,820

Post » Tue Dec 20, 2016 3:18 pm

Yeah the thing is, the whole system uses XML, so I can't just simply use a variable since I would have to combine the variable with the XML which would be quite tedious.
What I can do though, is add a dictionary that counts the amount of every text object and combine that with the rest.

Though I still think that my solution isn't very effective, but it was the only thing I could come up with.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Tue Dec 20, 2016 5:35 pm

Well i did find something useful is that What if we used a an id system for each item creation and then reverse check it in a looping matter cause this one website that explain the XML was very helpful and it check to see if you can use expression.

http://www.freeformatter.com/xpath-tester.html

it showed some really neat things. So im thinking what if we created a whole new dictionary to store just the id of each creation and have it to check the Item count with the current picked to where if we have two stone dictionary a counted for and two item it would know to use them both. Would we use a loop here something like Loop 1-(count(//Item[@ID]) Which in our case would be 6.

So therefore we would have an id of each created item with the ID number to use so that we could techspeaking loop check them or something like that. I know its here somewhere. But im super confuse to where to place each of the loops. and Where to check the count of <i>


CAuse if we can get it to know two stone and there is a recipe for it then create it. What do you think ? and for anyone else who is pro at xml files would help us understand it better and how to event it correctly.
B
51
S
24
G
6
Posts: 391
Reputation: 7,820

Post » Tue Dec 20, 2016 5:54 pm

Actually, I'm quite familiar with XML now, so most of the XML-related stuff shouldn't be much of a problem.

The issue is:
We can't use a dictionary to store the items the are dropped on the input.
Why?
Because dictionaries don't allow multiple keys with the same name.

So what we need is a way to differentiate between multiple instances of the same object or to merge multiple instances into one dictionary entry.
If we got this to work, then there wouldn't be any problem whatsoever.

Actually, I have difficulties understanding the ID system you tried to explain.
What do you mean by ID? Based on what pattern do you want to generate it?
What do you mean by Creation? Do you mean the output of a crafting process? Do you want to backtrack after crafting something?
_______________________________

check the Item count with the current picked to where if we have two stone dictionary a counted for and two item it would know to use them both. Would we use a loop here something like Loop 1-(count(//Item[@ID])

If you explained this to me a bit more detailed, we could surely come to a solution.
(As I said, the XML parsing shouldn't be much of a problem)

_______________________________

I think, I found a solution, just need to test it.
This is what I think of:
When adding the items on the crafting table ("Input") to the dictionary, we could simply check whether a same key already exists.
If it does, we add 1 to its value, if it doesn't, we create a new one.

I'll post a new reply if it works. It should.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Tue Dec 20, 2016 6:40 pm

The id thing is if you look at the xml examples that the website show it shows actor id=2 or 3 or 1. This is an id attribute which is something ive seen in multiple modern day games have.

So by using the Id attribute we could tech use it to our advantage to coordinate which item we want to check and which to loop through rather then using <i>. Does this explain better?
B
51
S
24
G
6
Posts: 391
Reputation: 7,820

Post » Tue Dec 20, 2016 8:26 pm

Let it be clear, i am not against XML (i just understand zip of it yet)
This is just another approach.

1 Array to hold the rules (an easy way) and for the unlocking of newly found items. I suppose you need to trow that one in the local store at 1 point.
1 Array for easy (outside the boundary of an event) calculations.

https://www.dropbox.com/s/bx72b5oqprveb ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,477
Reputation: 20,918

Post » Tue Dec 20, 2016 9:00 pm

Got it to work now.
Download .capx

(The only thing that isn't perfect yet, is the way it handles recipes with the same list of ingredients as another recipe. It will produce the first one in the XML. If you need this to work too, just gimme a shout.)

Concerning @99Instances2Go 's version:
I didn't look at the .capx, but Arrays are (probably?) more complicated to setup, but easier to handle than XML's.
It's probably more sensible to go with the Arrays. @99Instances2Go does quality work, I have experiences that myself already, haha.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 1 guest