playMaker

Author Topic: [SOLVED]Can someone ELI5 the best way to order GameObjects based on a object var  (Read 1382 times)

ElBolovo

  • Playmaker Newbie
  • *
  • Posts: 4
Hi everyone. I'm new with Playmaker (and game making in general) but it allowed me to progress more smoothly than expected, but I got stumped in something for some days now. I found some things that could be related, but the language used was above my pay grade. Without further ado, here is my problem.

In my game, you receive two types of "cards", one is shuffled and dealt every turn (let's call it ingredients), and another type is fixed all match (recipes).

The objective is making every recipe with the cards you are dealt with. Let's say, you are dealt a potato card, and one of your options is making a baked potato, requiring the aforementioned potato card. However, you can instead swap another card, hoping to get a beef, unlocking the option of making a steak and fries plate instead, earning more points.

Now for my problem. I want to display in the game screen all the recipes that you need to do, and sort it by "doneness" based on the cards you have in hand, helping the player make a decision. 
In the example, a baked potato is 100% done, but another recipe (the steak n fries) has 50% of the requirements meet, a third one is at 33%, and a forth is at 0%.

What I'm doing now is transmitting my ingredients in hand to a Global Variable, reading it with my recipes (each one as a game object), calculating the % of "doneness" and storing it in a INT inside the recipe.

What I'm at a lost is:
-How I read and store the same integer variable of multiple GameObjects into the same Array? Also, I know about Hashtables, but I don't know if I need to do anything with it yet.
-After that, how do I sort everything, keeping every recipe GameObject attached to his respective int (i.e, not shuffling it around).
-And lastly, how I spawn every object in the order of the array? I created some spawn points, but I don't know if it's the way to go.

I hope I could make myself clear, English is not my first language and I'm from another professional background, so I could have fudged some terms. If something is unclear, just ask me for clarification and I will respond ASAP. Thanks in advance for helping me after all the rambling.

« Last Edit: October 20, 2021, 12:26:29 AM by ElBolovo »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Hi.
If your not using array maker yet, you should get array maker 1st.
they are more powerfull than default array.
they can be easy accessed by reference.
so you would only need a global(gameobject) to reference the object with the arrays/hashtables

it also has hashtables and the hash tables can have different types (gameobject/int/float bool etc) in 1 hash table (when added @ runtime).
but for this case maybe you don't need to have different types.

You could make hashtables for recipes and set bool hashes (potato / orange / etc)
place only the ingredients it needs.

You would also need a array(list) with the reference names of the recipes Hashtable Reference.

now if you would pick up a potato,

Then loop thru the recipes with (array (list) get next.
then use hashtable contains key to see if the recipe has this ingredient.
If so set the bool to true.

for the ingredient completion you can first get get hash table count to know how many ingredient it has.
then loop thru the hash table with hash table get next. and check the bool true.
if if thru add 1 to a variable (available ingredient) then do available ingredient divide by the Hash table count
for example if the hashtable would have 10 ingredient and player would have 3 of then it would be 10/3 = 0.3 = 30%

ElBolovo

  • Playmaker Newbie
  • *
  • Posts: 4
Sorry for the delay, my work picked just as I posted the question ::)

So, addressing your reply. I use Arraymaker in other parts of my prototype, but I'm struggling with the Hash table part. I saw some video tutorials (including some from you djaydino), but I'm out of my depth now in which way to proceed for now.

I did something similar earlier that you proposed about using bools, adding the trues and dividing by the total earlier, but there are some conditions have more "weight" and are more complex than a simple "if it exists, it's true" than others, so I'm calculating the proper score, turning it into a integer and live updating it to 1-line prefilled hash table contained inside the card game object. Also, I'm naming the Hash Table Proxy with the name of the recipe and all the prefilled keys as "Total". It looked like a step in the right direction based in a myriad of tutorials that I saw, but as I said, I'm flying with bad vision here.

What I'm having trouble now is consolidating all those integers from multiple Hashtables in different Game Objects into a single Array List so I can sort it. From what I understood from your last reply, I should make a Array List Proxy and reference all the other hashtables, but I can't find how to do it. I managed to load all the pertinent Game Objects into the Arraylist, but I don't know how I can access the Hashtable Proxy inside them to get the integer variable that I need, or if I'm doing it wrong and there is a way to upload the Hashtable directly. After that, I feel I have a fighting chance with progressing with my project.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Hi.
You can Have a array list with the Hash Table Reference names (string).
The receipies do they need to be on different game objects?

if so then have a 'Data' Gameobject with a hashtable and set this as a global variable (Game Object)

Then in the hashtable add the gameobjects and use the hashtable Reference as key name.

ElBolovo

  • Playmaker Newbie
  • *
  • Posts: 4
Sorry, I'm still lost here (and slow at the uptake by the look of it). I believe having one recipe per object is the optimal way because they have other actions that need to be done, and different formulas that define the results. A better example of the end results is more akin to the turn order identifier in a RPG like Final Fantasy X now that I think about it (the upper right thing in this video at 3:14).

Correct me if I already did something wrong, but what I did so far was:

1. Made a "Data" GameObject, with a Hash Table Proxy (I put , set it as a Global variable and preloaded it with the objects that will need to be ranked. I put the key name as the recipe name.
2. In this one I'm not so sure, but in the "Data" GameObject i made another Hashtable Proxy with the values I need to be sorted, receiving the values by each "recipe" Game Object
3. If I understood correctly, I need another game object, the "Sorter" with a Array List that will get the value of the hashtable and sort it. I'm stuck here, I can't find a way to get the values of the other object so I sort it.
« Last Edit: September 24, 2021, 01:24:26 PM by ElBolovo »

ElBolovo

  • Playmaker Newbie
  • *
  • Posts: 4
I forgot to give a update on this issue. I asked around in the Discord server, and turns out that I could do what I needed with a custom action that I got in the ecosystem called "Array Multidimensional List Sort". Just set the two arrays up and you are good to go.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Hi.
Thanks for sharing your solution